Spaces:
Sleeping
Sleeping
File size: 1,316 Bytes
4254fda |
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 |
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() |