hf-rag-multi / app.py
siyu618's picture
Upload app.py
e188610 verified
raw
history blame
961 Bytes
import pickle
import gradio as gr
from config.rag_config import RAGConfig
from src.rag_pipeline import RAGPipeline
config = RAGConfig()
# εŠ θ½½ε‘ι‡εΊ“
with open(config.vector_db_path, "rb") as f:
data = pickle.load(f)
docs, doc_embeddings = data["texts"], data["embeddings"]
pipeline = RAGPipeline(config, docs, doc_embeddings)
def answer_question(query, threshold):
pipeline.config.similarity_threshold = threshold
answer, retrieved = pipeline.ask(query)
context = "\n\n".join([f"Score: {s:.4f}\n{t}" for t, s in retrieved])
return answer, context
demo = gr.Interface(
fn=answer_question,
inputs=[
gr.Textbox(label="Enter your question"),
gr.Slider(0.0, 1.0, value=0.4, step=0.05, label="Similarity Threshold")
],
outputs=[
gr.Textbox(label="Answer"),
gr.Textbox(label="Retrieved Contexts")
],
title="πŸ“˜ Multi-PDF RAG System"
)
if __name__ == "__main__":
demo.launch()