Spaces:
Runtime error
Runtime error
ffreemt
commited on
Commit
·
7743097
1
Parent(s):
86dc97a
Update gr.Accordion(Info, open=False)
Browse files
app.py
CHANGED
|
@@ -8,6 +8,7 @@ https://python.langchain.com/en/latest/getting_started/tutorials.html
|
|
| 8 |
import os
|
| 9 |
import time
|
| 10 |
from pathlib import Path
|
|
|
|
| 11 |
from types import SimpleNamespace
|
| 12 |
|
| 13 |
import gradio as gr
|
|
@@ -316,8 +317,16 @@ def main():
|
|
| 316 |
# greet_btn = gr.Button("Submit")
|
| 317 |
# output = gr.Textbox(label="Output Box")
|
| 318 |
# greet_btn.click(fn=greet, inputs=name, outputs=output, api_name="greet")
|
| 319 |
-
|
| 320 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 321 |
# Upload files and generate embeddings database
|
| 322 |
file_output = gr.File()
|
| 323 |
upload_button = gr.UploadButton(
|
|
@@ -327,31 +336,32 @@ def main():
|
|
| 327 |
)
|
| 328 |
upload_button.upload(upload_files, upload_button, file_output)
|
| 329 |
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 334 |
|
| 335 |
-
def respond(message, chat_history):
|
| 336 |
-
# bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
|
| 337 |
-
if ns.qa is None: # no files processed yet
|
| 338 |
-
bot_message = "Provide some file(s) for processsing first."
|
| 339 |
chat_history.append((message, bot_message))
|
| 340 |
-
return "", chat_history
|
| 341 |
-
try:
|
| 342 |
-
res = ns.qa(message)
|
| 343 |
-
answer, docs = res["result"], res["source_documents"]
|
| 344 |
-
bot_message = f"{answer} ({docs})"
|
| 345 |
-
except Exception as exc:
|
| 346 |
-
logger.error(exc)
|
| 347 |
-
bot_message = f"bummer! {exc}"
|
| 348 |
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
return "", chat_history
|
| 352 |
|
| 353 |
-
|
| 354 |
-
|
| 355 |
|
| 356 |
try:
|
| 357 |
from google import colab
|
|
|
|
| 8 |
import os
|
| 9 |
import time
|
| 10 |
from pathlib import Path
|
| 11 |
+
from textwrap import dedent
|
| 12 |
from types import SimpleNamespace
|
| 13 |
|
| 14 |
import gradio as gr
|
|
|
|
| 317 |
# greet_btn = gr.Button("Submit")
|
| 318 |
# output = gr.Textbox(label="Output Box")
|
| 319 |
# greet_btn.click(fn=greet, inputs=name, outputs=output, api_name="greet")
|
| 320 |
+
with gr.Accordion("Info", open=False):
|
| 321 |
+
_ = """
|
| 322 |
+
Talk to your docs (.pdf, .docx, .epub, .txt .md). It
|
| 323 |
+
takes quite a while to ingest docs (10-30 min. depending
|
| 324 |
+
on net, RAM, CPU etc.).
|
| 325 |
+
"""
|
| 326 |
+
gr.Markdown(dedent(_))
|
| 327 |
+
|
| 328 |
+
# with gr.Accordion("Upload files", open=True):
|
| 329 |
+
with gr.Tab("Upload files"):
|
| 330 |
# Upload files and generate embeddings database
|
| 331 |
file_output = gr.File()
|
| 332 |
upload_button = gr.UploadButton(
|
|
|
|
| 336 |
)
|
| 337 |
upload_button.upload(upload_files, upload_button, file_output)
|
| 338 |
|
| 339 |
+
with gr.Tab("Query docs"):
|
| 340 |
+
# interactive chat
|
| 341 |
+
chatbot = gr.Chatbot()
|
| 342 |
+
msg = gr.Textbox(label="Query")
|
| 343 |
+
clear = gr.Button("Clear")
|
| 344 |
+
|
| 345 |
+
def respond(message, chat_history):
|
| 346 |
+
# bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
|
| 347 |
+
if ns.qa is None: # no files processed yet
|
| 348 |
+
bot_message = "Provide some file(s) for processsing first."
|
| 349 |
+
chat_history.append((message, bot_message))
|
| 350 |
+
return "", chat_history
|
| 351 |
+
try:
|
| 352 |
+
res = ns.qa(message)
|
| 353 |
+
answer, docs = res["result"], res["source_documents"]
|
| 354 |
+
bot_message = f"{answer} ({docs})"
|
| 355 |
+
except Exception as exc:
|
| 356 |
+
logger.error(exc)
|
| 357 |
+
bot_message = f"bummer! {exc}"
|
| 358 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 359 |
chat_history.append((message, bot_message))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 360 |
|
| 361 |
+
return "", chat_history
|
|
|
|
|
|
|
| 362 |
|
| 363 |
+
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
| 364 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
| 365 |
|
| 366 |
try:
|
| 367 |
from google import colab
|