Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -84,26 +84,37 @@ Question:
|
|
| 84 |
|
| 85 |
return response.choices[0].message.content
|
| 86 |
|
|
|
|
|
|
|
| 87 |
def chat(user_input, history):
|
| 88 |
answer = generate_answer(user_input)
|
| 89 |
-
history
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
-
|
|
|
|
| 93 |
gr.Markdown("# π Dynamic Finance RAG Chatbot")
|
| 94 |
|
| 95 |
with gr.Row():
|
| 96 |
-
link_input = gr.Textbox(label="π
|
| 97 |
-
load_btn = gr.Button("Load PDF")
|
| 98 |
|
| 99 |
status = gr.Textbox(label="Status", interactive=False)
|
| 100 |
|
| 101 |
-
chatbot = gr.Chatbot()
|
| 102 |
-
msg = gr.Textbox(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
# Events
|
| 105 |
load_btn.click(load_pdf_from_link, inputs=link_input, outputs=status)
|
| 106 |
msg.submit(chat, inputs=[msg, chatbot], outputs=[chatbot, chatbot])
|
|
|
|
| 107 |
|
| 108 |
if __name__ == "__main__":
|
| 109 |
app.launch()
|
|
|
|
| 84 |
|
| 85 |
return response.choices[0].message.content
|
| 86 |
|
| 87 |
+
# ... (keep all previous code until chat function)
|
| 88 |
+
|
| 89 |
def chat(user_input, history):
|
| 90 |
answer = generate_answer(user_input)
|
| 91 |
+
new_history = history + [
|
| 92 |
+
{"role": "user", "content": user_input},
|
| 93 |
+
{"role": "assistant", "content": answer}
|
| 94 |
+
]
|
| 95 |
+
return new_history, new_history
|
| 96 |
|
| 97 |
+
# UI (replace entirely):
|
| 98 |
+
with gr.Blocks(title="Finance RAG") as app:
|
| 99 |
gr.Markdown("# π Dynamic Finance RAG Chatbot")
|
| 100 |
|
| 101 |
with gr.Row():
|
| 102 |
+
link_input = gr.Textbox(label="π Google Drive PDF Link", placeholder="https://drive.google.com/file/d/...")
|
| 103 |
+
load_btn = gr.Button("π₯ Load PDF", variant="primary")
|
| 104 |
|
| 105 |
status = gr.Textbox(label="Status", interactive=False)
|
| 106 |
|
| 107 |
+
chatbot = gr.Chatbot(height=500)
|
| 108 |
+
msg = gr.Textbox(
|
| 109 |
+
label="π¬ Ask about the PDF",
|
| 110 |
+
placeholder="What are the key financial metrics?",
|
| 111 |
+
container=True
|
| 112 |
+
)
|
| 113 |
|
| 114 |
# Events
|
| 115 |
load_btn.click(load_pdf_from_link, inputs=link_input, outputs=status)
|
| 116 |
msg.submit(chat, inputs=[msg, chatbot], outputs=[chatbot, chatbot])
|
| 117 |
+
msg.submit(lambda: "", outputs=msg)
|
| 118 |
|
| 119 |
if __name__ == "__main__":
|
| 120 |
app.launch()
|