Update app.py
Browse files
app.py
CHANGED
@@ -125,7 +125,7 @@ app = MyApp()
|
|
125 |
def set_api_key(api_key):
|
126 |
app.set_api_key(api_key)
|
127 |
# Pre-process the saved PDF file after setting the API key
|
128 |
-
saved_file_path = "
|
129 |
with open(saved_file_path, 'rb') as saved_file:
|
130 |
app.process_file(saved_file)
|
131 |
app.build_chain(saved_file)
|
@@ -141,66 +141,7 @@ with gr.Blocks() as demo:
|
|
141 |
fn=set_api_key,
|
142 |
inputs=[api_key_input],
|
143 |
outputs=[api_key_status]
|
144 |
-
)
|
145 |
-
|
146 |
-
with gr.Tab("Inst RAG"):
|
147 |
-
with gr.Column():
|
148 |
-
with gr.Tab("Upload PDF"):
|
149 |
-
btn = gr.UploadButton("📁 Upload a PDF", file_types=[".pdf"])
|
150 |
-
show_img = gr.Image(label="Uploaded PDF")
|
151 |
-
|
152 |
-
btn.upload(
|
153 |
-
fn=purge_chat_and_render_first,
|
154 |
-
inputs=[btn],
|
155 |
-
outputs=[show_img],
|
156 |
-
)
|
157 |
-
|
158 |
-
with gr.Tab("Process PDF"):
|
159 |
-
process_btn = gr.Button("Process PDF")
|
160 |
-
show_img_processed = gr.Image(label="Processed PDF")
|
161 |
-
process_status = gr.Textbox(label="Processing Status", interactive=False)
|
162 |
-
|
163 |
-
process_btn.click(
|
164 |
-
fn=lambda file: (app.process_file(file), "Processing complete!"),
|
165 |
-
inputs=[btn],
|
166 |
-
outputs=[show_img_processed, process_status],
|
167 |
-
)
|
168 |
-
|
169 |
-
with gr.Tab("Build Vector Database"):
|
170 |
-
build_vector_btn = gr.Button("Build Vector Database")
|
171 |
-
status_text = gr.Textbox(label="Status", value="", interactive=False)
|
172 |
-
|
173 |
-
build_vector_btn.click(
|
174 |
-
fn=app.build_chain,
|
175 |
-
inputs=[btn],
|
176 |
-
outputs=[status_text],
|
177 |
-
)
|
178 |
-
|
179 |
-
with gr.Tab("Chat"):
|
180 |
-
chatbot = gr.Chatbot(elem_id="chatbot")
|
181 |
-
txt = gr.Textbox(
|
182 |
-
show_label=False,
|
183 |
-
placeholder="Enter text and press submit",
|
184 |
-
scale=2
|
185 |
-
)
|
186 |
-
submit_btn = gr.Button("Submit", scale=1)
|
187 |
-
refresh_btn = gr.Button("Refresh Chat", scale=1)
|
188 |
-
source_texts_output = gr.Textbox(label="Source Texts", interactive=False)
|
189 |
-
|
190 |
-
submit_btn.click(
|
191 |
-
fn=add_text,
|
192 |
-
inputs=[chatbot, txt],
|
193 |
-
outputs=[chatbot],
|
194 |
-
queue=False,
|
195 |
-
).success(
|
196 |
-
fn=get_response, inputs=[chatbot, txt], outputs=[chatbot, source_texts_output]
|
197 |
-
)
|
198 |
-
|
199 |
-
refresh_btn.click(
|
200 |
-
fn=refresh_chat,
|
201 |
-
inputs=[],
|
202 |
-
outputs=[chatbot],
|
203 |
-
)
|
204 |
|
205 |
with gr.Tab("Current RAG"):
|
206 |
with gr.Column():
|
|
|
125 |
def set_api_key(api_key):
|
126 |
app.set_api_key(api_key)
|
127 |
# Pre-process the saved PDF file after setting the API key
|
128 |
+
saved_file_path = "THEDIA1.pdf"
|
129 |
with open(saved_file_path, 'rb') as saved_file:
|
130 |
app.process_file(saved_file)
|
131 |
app.build_chain(saved_file)
|
|
|
141 |
fn=set_api_key,
|
142 |
inputs=[api_key_input],
|
143 |
outputs=[api_key_status]
|
144 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
|
146 |
with gr.Tab("Current RAG"):
|
147 |
with gr.Column():
|