Spaces:
Sleeping
Sleeping
apahilaj
commited on
Commit
·
b4b5a4d
1
Parent(s):
29f30e1
app.py chat
Browse files
app.py
CHANGED
|
@@ -156,19 +156,19 @@ def load_db(file, k):
|
|
| 156 |
|
| 157 |
chat_history = [] # initialize chat history
|
| 158 |
|
| 159 |
-
def
|
| 160 |
global chat_history
|
| 161 |
-
|
| 162 |
-
a = load_db(
|
| 163 |
-
r = a.invoke({"question":
|
| 164 |
match = re.search(r'Helpful Answer:(.*)', r['answer'])
|
| 165 |
if match:
|
| 166 |
helpful_answer = match.group(1).strip()
|
| 167 |
# Extend chat history with the current question and answer
|
| 168 |
-
chat_history.extend([
|
| 169 |
-
return
|
| 170 |
else:
|
| 171 |
-
return "No helpful answer found."
|
| 172 |
|
| 173 |
-
iface = gr.ChatInterface(fn=
|
| 174 |
iface.launch(share=True)
|
|
|
|
| 156 |
|
| 157 |
chat_history = [] # initialize chat history
|
| 158 |
|
| 159 |
+
def greet(messages):
|
| 160 |
global chat_history
|
| 161 |
+
user_message = messages[-1]['content']
|
| 162 |
+
a = load_db("temp.pdf", 3) # assuming you've uploaded the file and saved it as "temp.pdf"
|
| 163 |
+
r = a.invoke({"question": user_message, "chat_history": chat_history})
|
| 164 |
match = re.search(r'Helpful Answer:(.*)', r['answer'])
|
| 165 |
if match:
|
| 166 |
helpful_answer = match.group(1).strip()
|
| 167 |
# Extend chat history with the current question and answer
|
| 168 |
+
chat_history.extend([{"role": "user", "content": user_message}, {"role": "assistant", "content": helpful_answer}])
|
| 169 |
+
return [{"role": "assistant", "content": helpful_answer}]
|
| 170 |
else:
|
| 171 |
+
return [{"role": "assistant", "content": "No helpful answer found."}]
|
| 172 |
|
| 173 |
+
iface = gr.ChatInterface(fn=greet, inputs=gr.Textbox(), outputs=gr.ChatResponse(continuous_update=True))
|
| 174 |
iface.launch(share=True)
|