Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,25 +1,30 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
-
from day3.rag_system import RAGPipeline
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
demo = gr.Interface(
|
| 17 |
-
fn=
|
| 18 |
-
inputs=[
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
| 23 |
)
|
| 24 |
|
| 25 |
if __name__ == "__main__":
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
import os
|
| 3 |
import gradio as gr
|
|
|
|
| 4 |
|
| 5 |
+
# day3 qovluğunu sys.path-ə əlavə et
|
| 6 |
+
sys.path.append(os.path.join(os.path.dirname(__file__), "day3"))
|
| 7 |
|
| 8 |
+
from rag_system import RAGPipeline
|
| 9 |
+
|
| 10 |
+
rag = RAGPipeline()
|
| 11 |
+
|
| 12 |
+
def ask_pdf(pdf_file, question):
|
| 13 |
+
if pdf_file:
|
| 14 |
+
info = rag.index_document(pdf_file.name)
|
| 15 |
+
else:
|
| 16 |
+
info = {"chunks_indexed": 0, "best_strategy": None}
|
| 17 |
+
out = rag.query(question)
|
| 18 |
+
return f"**Answer:** {out['answer']}\n\n_Used chunks: {out['used_chunks']}_"
|
| 19 |
|
| 20 |
demo = gr.Interface(
|
| 21 |
+
fn=ask_pdf,
|
| 22 |
+
inputs=[
|
| 23 |
+
gr.File(label="Upload PDF", file_types=[".pdf"]),
|
| 24 |
+
gr.Textbox(label="Question")
|
| 25 |
+
],
|
| 26 |
+
outputs="markdown",
|
| 27 |
+
title="PDF RAG System"
|
| 28 |
)
|
| 29 |
|
| 30 |
if __name__ == "__main__":
|