agnixcode commited on
Commit
7abecd5
Β·
verified Β·
1 Parent(s): e8f133c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -7
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.append((user_input, answer))
90
- return history, history
 
 
 
91
 
92
- with gr.Blocks() as app:
 
93
  gr.Markdown("# πŸ“Š Dynamic Finance RAG Chatbot")
94
 
95
  with gr.Row():
96
- link_input = gr.Textbox(label="πŸ“Ž Paste Google Drive PDF Link")
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(label="Ask your question")
 
 
 
 
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()