import gradio as gr import pandas as pd from src.utils import get_rag_chain rag = get_rag_chain() # Write a function to process the RAG results def query_fc(query): # query = "Is Africa the youngest continent in the world?" result = rag.invoke(query) docs = [doc.metadata for doc in result['source_documents']] df = pd.DataFrame(docs) df.url = df.apply(lambda x: "{}".format(x.url, x.title), axis=1) df['publisher'] = df.apply(lambda x: "{}". format(x.publisher_site, x.publisher_name), axis=1) df.drop(columns=['language_code', 'title', 'claim_date', 'review_date', 'publisher_site', 'publisher_name'], inplace=True) df.rename(columns={'url': 'FC article', 'claim': 'Claim', 'publisher': 'FC Publisher', 'claimant': 'Claimant', 'textual_rating': 'FC Rating'}, inplace=True) # Reorder the columns in the DataFrame column_order = ['Claim', 'FC Rating', 'FC article', 'FC Publisher', 'Claimant'] df = df.reindex(columns=column_order) return (result['result'], "