luminoussg commited on
Commit
7cbd468
Β·
verified Β·
1 Parent(s): d89084e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -1
app.py CHANGED
@@ -5,6 +5,7 @@ from datetime import datetime
5
  from typing import List, Dict, Any, Generator
6
  from session_manager import SessionManager
7
  from huggingface_hub import InferenceClient
 
8
 
9
  # Initialize session manager and get HF API key
10
  session_manager = SessionManager()
@@ -130,7 +131,8 @@ with gr.Blocks() as demo:
130
  new_session = gr.Button("πŸ”„ New Session")
131
 
132
  chatbot = gr.Chatbot(height=600)
133
- msg = gr.Textbox(label="Message")
 
134
  save_history = gr.Checkbox(label="Save Conversation History", value=True)
135
 
136
  def on_new_session():
@@ -146,6 +148,11 @@ with gr.Blocks() as demo:
146
  "content": message
147
  })
148
  session_manager.save_session(session_id, session)
 
 
 
 
 
149
  return "", history + [[message, None]]
150
 
151
  def bot(history, session_id):
@@ -155,9 +162,14 @@ with gr.Blocks() as demo:
155
  history[-1][1] = response
156
  yield history
157
 
 
 
 
 
158
  msg.submit(user, [msg, chatbot, session_id, save_history], [msg, chatbot]).then(
159
  bot, [chatbot, session_id], [chatbot]
160
  )
 
161
  new_session.click(on_new_session, None, [session_id, chatbot])
162
 
163
  if __name__ == "__main__":
 
5
  from typing import List, Dict, Any, Generator
6
  from session_manager import SessionManager
7
  from huggingface_hub import InferenceClient
8
+ from textbox_with_upload import TextboxWithUpload
9
 
10
  # Initialize session manager and get HF API key
11
  session_manager = SessionManager()
 
131
  new_session = gr.Button("πŸ”„ New Session")
132
 
133
  chatbot = gr.Chatbot(height=600)
134
+ msg = TextboxWithUpload(label="Message")
135
+ msg.add_upload_button()
136
  save_history = gr.Checkbox(label="Save Conversation History", value=True)
137
 
138
  def on_new_session():
 
148
  "content": message
149
  })
150
  session_manager.save_session(session_id, session)
151
+
152
+ # Handle file upload
153
+ if message.startswith("Uploaded file:"):
154
+ message = f"I've uploaded a file: {message.split(':', 1)[1].strip()}"
155
+
156
  return "", history + [[message, None]]
157
 
158
  def bot(history, session_id):
 
162
  history[-1][1] = response
163
  yield history
164
 
165
+ def process_upload(file):
166
+ return f"Uploaded file: {file.name}"
167
+
168
+ # Set up event handlers for message submission, file upload, and new session creation
169
  msg.submit(user, [msg, chatbot, session_id, save_history], [msg, chatbot]).then(
170
  bot, [chatbot, session_id], [chatbot]
171
  )
172
+ msg.upload_button.upload(process_upload, msg.upload_button, msg) # Handle file uploads
173
  new_session.click(on_new_session, None, [session_id, chatbot])
174
 
175
  if __name__ == "__main__":