Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -32,14 +32,18 @@ def upload_pdf(pdf_file_path):
|
|
32 |
def respond(message, chat_history):
|
33 |
global qa_chain
|
34 |
if qa_chain is None:
|
35 |
-
return message, chat_history + [
|
|
|
36 |
try:
|
37 |
result = qa_chain({"query": message})
|
38 |
answer = result["result"]
|
39 |
-
chat_history.append(
|
|
|
40 |
return "", chat_history
|
41 |
except Exception as e:
|
42 |
-
|
|
|
|
|
43 |
|
44 |
def create_interface():
|
45 |
with gr.Blocks(css=css, theme="soft") as demo:
|
@@ -51,7 +55,7 @@ def create_interface():
|
|
51 |
pdf_input = gr.File(label="Upload PDF", type="filepath", file_types=[".pdf"])
|
52 |
status = gr.Markdown()
|
53 |
|
54 |
-
chatbot = gr.Chatbot(elem_id="chatbot", visible=False)
|
55 |
|
56 |
examples = [
|
57 |
"What are the admission requirements?",
|
|
|
32 |
def respond(message, chat_history):
|
33 |
global qa_chain
|
34 |
if qa_chain is None:
|
35 |
+
return message, chat_history + [{"role": "assistant", "content": "⚠️ Please upload a PDF first."}]
|
36 |
+
|
37 |
try:
|
38 |
result = qa_chain({"query": message})
|
39 |
answer = result["result"]
|
40 |
+
chat_history.append({"role": "user", "content": message})
|
41 |
+
chat_history.append({"role": "assistant", "content": answer})
|
42 |
return "", chat_history
|
43 |
except Exception as e:
|
44 |
+
chat_history.append({"role": "user", "content": message})
|
45 |
+
chat_history.append({"role": "assistant", "content": f"❌ Error: {e}"})
|
46 |
+
return "", chat_history
|
47 |
|
48 |
def create_interface():
|
49 |
with gr.Blocks(css=css, theme="soft") as demo:
|
|
|
55 |
pdf_input = gr.File(label="Upload PDF", type="filepath", file_types=[".pdf"])
|
56 |
status = gr.Markdown()
|
57 |
|
58 |
+
chatbot = gr.Chatbot(elem_id="chatbot", visible=False, type="messages") # ✅ fixed type here
|
59 |
|
60 |
examples = [
|
61 |
"What are the admission requirements?",
|