Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -47,22 +47,22 @@ import streamlit as st
|
|
47 |
# return chain
|
48 |
|
49 |
# # Function to generate a response based on the chat history and query
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
|
67 |
# # Function to render a specific page of a PDF file as an image
|
68 |
# def render_file(file):
|
@@ -147,6 +147,7 @@ import streamlit as st
|
|
147 |
|
148 |
# demo.launch(server_port=7861)
|
149 |
|
|
|
150 |
def add_text(history, text):
|
151 |
if not text:
|
152 |
raise gr.Error('Enter text')
|
|
|
47 |
# return chain
|
48 |
|
49 |
# # Function to generate a response based on the chat history and query
|
50 |
+
def generate_response(history, query, btn):
|
51 |
+
global COUNT, N, chat_history, chain
|
52 |
+
if not btn:
|
53 |
+
raise gr.Error(message='Upload a PDF')
|
54 |
|
55 |
+
if COUNT == 0:
|
56 |
+
chain = process_file(btn)
|
57 |
+
COUNT += 1
|
58 |
|
59 |
+
result = chain({"question": query, 'chat_history': chat_history}, return_only_outputs=True)
|
60 |
+
chat_history += [(query, result["answer"])]
|
61 |
+
N = list(result['source_documents'][0])[1][1]['page']
|
62 |
|
63 |
+
for char in result['answer']:
|
64 |
+
history[-1][-1] += char # Update the last response
|
65 |
+
yield history, ''
|
66 |
|
67 |
# # Function to render a specific page of a PDF file as an image
|
68 |
# def render_file(file):
|
|
|
147 |
|
148 |
# demo.launch(server_port=7861)
|
149 |
|
150 |
+
|
151 |
def add_text(history, text):
|
152 |
if not text:
|
153 |
raise gr.Error('Enter text')
|