Update app.py
Browse files
app.py
CHANGED
@@ -27,11 +27,9 @@ def pdf_changes(pdf_doc):
|
|
27 |
|
28 |
def add_text(history, text):
|
29 |
history = history + [(text, None)]
|
30 |
-
print(history)
|
31 |
return history, ""
|
32 |
|
33 |
def bot(history):
|
34 |
-
print(history[-1][0])
|
35 |
response = infer(history[-1][0])
|
36 |
history[-1][1] = response['result']
|
37 |
return history
|
@@ -43,21 +41,37 @@ def infer(question):
|
|
43 |
|
44 |
return result
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
with gr.Blocks() as demo:
|
47 |
-
with gr.Column():
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
-
|
56 |
load_pdf.click(pdf_changes, pdf_doc, langchain_status, queue=False)
|
57 |
-
|
58 |
-
|
59 |
question.submit(add_text, [chatbot, question], [chatbot, question]).then(
|
60 |
bot, chatbot, chatbot
|
61 |
)
|
|
|
62 |
|
63 |
demo.launch()
|
|
|
27 |
|
28 |
def add_text(history, text):
|
29 |
history = history + [(text, None)]
|
|
|
30 |
return history, ""
|
31 |
|
32 |
def bot(history):
|
|
|
33 |
response = infer(history[-1][0])
|
34 |
history[-1][1] = response['result']
|
35 |
return history
|
|
|
41 |
|
42 |
return result
|
43 |
|
44 |
+
css="""
|
45 |
+
#col-container {max-width: 700px; margin-left: auto; margin-right: auto;}
|
46 |
+
"""
|
47 |
+
|
48 |
+
title = """
|
49 |
+
<div style="text-align: center;max-width: 700px;>
|
50 |
+
<h1>Chat with PDF</h1>
|
51 |
+
<p style="text-align: center;">Upload a .PDF from your computer, click the "Load PDF to LangChain" button, <br />
|
52 |
+
when everything is ready, you can start asking questions about the pdf ;)</p>
|
53 |
+
</div>
|
54 |
+
"""
|
55 |
+
|
56 |
+
|
57 |
with gr.Blocks() as demo:
|
58 |
+
with gr.Column(elem_id="col-container"):
|
59 |
+
gr.HTML(title)
|
60 |
+
with gr.Row():
|
61 |
+
with gr.Column():
|
62 |
+
pdf_doc = gr.File(label="Load a pdf", file_types=['.pdf'], type="file")
|
63 |
+
langchain_status = gr.Textbox()
|
64 |
+
load_pdf = gr.Button("Load pdf to langchain")
|
65 |
+
with gr.Column():
|
66 |
+
chatbot = gr.Chatbot([], elem_id="chatbot").style(height=350)
|
67 |
+
with gr.Row():
|
68 |
+
question = gr.Textbox(label="Question")
|
69 |
+
clear = gr.Button("Clear")
|
70 |
|
|
|
71 |
load_pdf.click(pdf_changes, pdf_doc, langchain_status, queue=False)
|
|
|
|
|
72 |
question.submit(add_text, [chatbot, question], [chatbot, question]).then(
|
73 |
bot, chatbot, chatbot
|
74 |
)
|
75 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
76 |
|
77 |
demo.launch()
|