Spaces:
Sleeping
Sleeping
Hamid Omarov
commited on
Commit
·
b3617c5
1
Parent(s):
e7e9247
Space: add langchain-community for PyPDFLoader
Browse files- app.py +22 -17
- requirements.txt +0 -6
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__":
|
requirements.txt
DELETED
@@ -1,6 +0,0 @@
|
|
1 |
-
gradio
|
2 |
-
chromadb
|
3 |
-
sentence-transformers
|
4 |
-
langchain-groq
|
5 |
-
pypdf
|
6 |
-
python-dotenv
|
|
|
|
|
|
|
|
|
|
|
|
|
|