chat22GV2 / app.py
ramysaidagieb's picture
Upload 5 files
4254fda verified
raw
history blame
1.32 kB
import gradio as gr
from rag_pipeline import RAGPipeline
import time
rag = RAGPipeline()
def submit_question(user_question):
start_time = time.time()
response, passages = rag.answer_question(user_question)
end_time = time.time()
log = f"[⏱️] زمن الإجابة: {end_time - start_time:.2f} ثانية\n"
for i, passage in enumerate(passages):
log += f"[📘] المرجع {i+1}: {passage}\n"
return response, log
with gr.Blocks() as demo:
with gr.Row():
with gr.Column():
file_uploader = gr.File(file_types=[".pdf", ".docx", ".txt"], label="📂 رفع المستندات", file_count="multiple")
upload_btn = gr.Button("⬆️ رفع ومعالجة")
upload_log = gr.Textbox(label="🔍 سجل المعالجة", lines=10)
with gr.Column():
question = gr.Textbox(label="❓ اطرح سؤالك هنا")
submit_btn = gr.Button("🔎 إرسال السؤال")
answer = gr.Textbox(label="📜 الإجابة", lines=5)
sources = gr.Textbox(label="🧭 المراجع", lines=10)
upload_btn.click(fn=rag.load_and_index, inputs=[file_uploader], outputs=[upload_log])
submit_btn.click(fn=submit_question, inputs=[question], outputs=[answer, sources])
demo.launch()