Spaces:
Running
Running
File size: 1,863 Bytes
80a3a2e aa77ab3 80a3a2e aa77ab3 dda3626 80a3a2e c1c360d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
import gradio as gr
from RagWithConfidenceScore import RagWithScore #
# Initialize the RAG system
rag_system = RagWithScore()
# Load or create the vector store
rag_system.load_and_process_documents()
# Define the function to handle user queries
def answer_financial_query(query):
# Use the RAG system to answer the question
result = rag_system.answer_question(query)
# Format the output
answer = result["answer"]
confidence_score = result["confidence_score"]
confidence_level = result["confidence_level"]
sources = "\n\n".join([doc.page_content for doc in result["source_documents"]])
return answer, f"{confidence_score:.2f}", confidence_level, sources
# Return the results
# return {
# "Answer": answer,
# "Confidence Score": f"{confidence_score:.2f}",
# "Confidence Level": confidence_level,
# "Source Documents": sources
# }
# Create a Gradio interface
interface = gr.Interface(
fn=answer_financial_query, # Function to call
inputs=gr.Textbox(lines=2, placeholder="Enter your financial query here..."), # Input component
outputs=[ # Output components
gr.Textbox(label="Answer", lines=8),
gr.Textbox(label="Confidence Score"),
gr.Textbox(label="Confidence Level")
# gr.Textbox(label="Source Documents", lines=10)
],
title="Financial RAG System",
description="Ask questions about financial data and get answers powered by Retrieval-Augmented Generation (RAG).",
examples=[
["What is the current revenue growth rate?"],
["Explain the concept of EBITDA."],
["What are the key financial risks mentioned in the report?"],
["How has the debt-to-equity ratio changed over the last two years?"]
],
cache_examples=False
)
# Launch the interface
interface.launch(share=True) |