Spaces:
Running
on
Zero
Running
on
Zero
adding rag
Browse files
app.py
CHANGED
@@ -6,6 +6,9 @@ import uuid
|
|
6 |
|
7 |
|
8 |
from middleware import Middleware
|
|
|
|
|
|
|
9 |
|
10 |
def generate_uuid(state):
|
11 |
# Check if UUID already exists in session state
|
@@ -44,7 +47,7 @@ class PDFSearchApp:
|
|
44 |
return f"Error processing PDF: {str(e)}"
|
45 |
|
46 |
|
47 |
-
def search_documents(self, state, query, num_results=
|
48 |
print(f"Searching for query: {query}")
|
49 |
id = generate_uuid(state)
|
50 |
|
@@ -69,7 +72,9 @@ class PDFSearchApp:
|
|
69 |
|
70 |
print(f"Retrieved image path: {img_path}")
|
71 |
|
72 |
-
|
|
|
|
|
73 |
|
74 |
except Exception as e:
|
75 |
return f"Error during search: {str(e)}", "--"
|
@@ -100,16 +105,16 @@ def create_ui():
|
|
100 |
with gr.Tab("Query"):
|
101 |
with gr.Column():
|
102 |
query_input = gr.Textbox(label="Enter query")
|
103 |
-
num_results = gr.Slider(
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
)
|
110 |
search_btn = gr.Button("Query")
|
111 |
-
llm_answer = gr.Textbox(label="
|
112 |
-
images = gr.Image(label="
|
113 |
|
114 |
# Event handlers
|
115 |
file_input.change(
|
@@ -120,7 +125,7 @@ def create_ui():
|
|
120 |
|
121 |
search_btn.click(
|
122 |
fn=app.search_documents,
|
123 |
-
inputs=[state, query_input
|
124 |
outputs=[images, llm_answer]
|
125 |
)
|
126 |
|
|
|
6 |
|
7 |
|
8 |
from middleware import Middleware
|
9 |
+
from rag import Rag
|
10 |
+
|
11 |
+
rag = Rag()
|
12 |
|
13 |
def generate_uuid(state):
|
14 |
# Check if UUID already exists in session state
|
|
|
47 |
return f"Error processing PDF: {str(e)}"
|
48 |
|
49 |
|
50 |
+
def search_documents(self, state, query, num_results=1):
|
51 |
print(f"Searching for query: {query}")
|
52 |
id = generate_uuid(state)
|
53 |
|
|
|
72 |
|
73 |
print(f"Retrieved image path: {img_path}")
|
74 |
|
75 |
+
rag_response = rag.get_answer_from_gemini(query, [img_path])
|
76 |
+
|
77 |
+
return img_path, rag_response
|
78 |
|
79 |
except Exception as e:
|
80 |
return f"Error during search: {str(e)}", "--"
|
|
|
105 |
with gr.Tab("Query"):
|
106 |
with gr.Column():
|
107 |
query_input = gr.Textbox(label="Enter query")
|
108 |
+
# num_results = gr.Slider(
|
109 |
+
# minimum=1,
|
110 |
+
# maximum=10,
|
111 |
+
# value=5,
|
112 |
+
# step=1,
|
113 |
+
# label="Number of results"
|
114 |
+
# )
|
115 |
search_btn = gr.Button("Query")
|
116 |
+
llm_answer = gr.Textbox(label="RAG Response", interactive=False)
|
117 |
+
images = gr.Image(label="Page matching query")
|
118 |
|
119 |
# Event handlers
|
120 |
file_input.change(
|
|
|
125 |
|
126 |
search_btn.click(
|
127 |
fn=app.search_documents,
|
128 |
+
inputs=[state, query_input],
|
129 |
outputs=[images, llm_answer]
|
130 |
)
|
131 |
|