Update app.py
Browse files
app.py
CHANGED
@@ -41,10 +41,13 @@ def local_query(query, context):
|
|
41 |
|
42 |
return tokenizer.batch_decode(outputs, skip_special_tokens=True)
|
43 |
|
44 |
-
def run_query(query):
|
|
|
45 |
context = get_context(query)
|
46 |
result = local_query(query, context)
|
47 |
-
|
|
|
|
|
48 |
|
49 |
|
50 |
def load_document(pdf_filename):
|
@@ -74,8 +77,7 @@ def load_document(pdf_filename):
|
|
74 |
return 'Success'
|
75 |
|
76 |
|
77 |
-
|
78 |
-
import os
|
79 |
|
80 |
def upload_pdf(file):
|
81 |
try:
|
@@ -99,9 +101,11 @@ def upload_pdf(file):
|
|
99 |
|
100 |
|
101 |
with gr.Blocks() as demo:
|
102 |
-
|
|
|
103 |
output = gr.Textbox(label="Output Box")
|
104 |
chatbot = gr.Chatbot(value=[], elem_id="chatbot")
|
|
|
105 |
with gr.Row():
|
106 |
with gr.Column(scale=0.70):
|
107 |
txt = gr.Textbox(
|
@@ -111,8 +115,10 @@ with gr.Blocks() as demo:
|
|
111 |
|
112 |
|
113 |
# Event handler for uploading a PDF
|
114 |
-
|
115 |
btn.upload(fn=upload_pdf, inputs=[btn], outputs=[output])
|
|
|
|
|
|
|
116 |
|
117 |
|
118 |
|
|
|
41 |
|
42 |
return tokenizer.batch_decode(outputs, skip_special_tokens=True)
|
43 |
|
44 |
+
def run_query(history, query):
|
45 |
+
|
46 |
context = get_context(query)
|
47 |
result = local_query(query, context)
|
48 |
+
|
49 |
+
history = history.append(query)
|
50 |
+
return history, result
|
51 |
|
52 |
|
53 |
def load_document(pdf_filename):
|
|
|
77 |
return 'Success'
|
78 |
|
79 |
|
80 |
+
|
|
|
81 |
|
82 |
def upload_pdf(file):
|
83 |
try:
|
|
|
101 |
|
102 |
|
103 |
with gr.Blocks() as demo:
|
104 |
+
|
105 |
+
btn = gr.UploadButton("Upload a PDF", file_types=[".pdf"])
|
106 |
output = gr.Textbox(label="Output Box")
|
107 |
chatbot = gr.Chatbot(value=[], elem_id="chatbot")
|
108 |
+
|
109 |
with gr.Row():
|
110 |
with gr.Column(scale=0.70):
|
111 |
txt = gr.Textbox(
|
|
|
115 |
|
116 |
|
117 |
# Event handler for uploading a PDF
|
|
|
118 |
btn.upload(fn=upload_pdf, inputs=[btn], outputs=[output])
|
119 |
+
txt.submit(run_query, [chatbot, txt], [chatbot, txt], queue=False)
|
120 |
+
#.then(
|
121 |
+
# generate_response, inputs =[chatbot,],outputs = chatbot,)
|
122 |
|
123 |
|
124 |
|