Updated
Browse files
Main2.py
CHANGED
|
@@ -237,23 +237,30 @@ def create_interface():
|
|
| 237 |
refresh_characters_btn.click(fn=lambda: gr.update(value=get_existing_characters()), outputs=[character_list])
|
| 238 |
|
| 239 |
with gr.Tab("Chat with Character"):
|
| 240 |
-
# Top row for
|
| 241 |
with gr.Row():
|
| 242 |
with gr.Column(scale=1):
|
| 243 |
character_dropdown = gr.Dropdown(label="Choose Character", choices=[char[0] for char in get_existing_characters()], elem_id="character_dropdown")
|
| 244 |
-
chat_id_display = gr.Textbox(label="Current Chat ID", interactive=False, elem_id="chat_id_display")
|
| 245 |
-
with gr.Column(scale=2):
|
| 246 |
-
user_input = gr.Textbox(label="Your Message", placeholder="Type your message or use audio/video input", elem_id="user_input", lines=2)
|
| 247 |
-
with gr.Column(scale=1):
|
| 248 |
-
audio_input = gr.Audio(label="Audio Input", type="filepath", elem_id="audio_input")
|
| 249 |
-
video_input = gr.Video(label="Video Input", elem_id="video_input")
|
| 250 |
with gr.Column(scale=1):
|
| 251 |
-
|
| 252 |
|
| 253 |
-
#
|
| 254 |
-
with gr.
|
| 255 |
-
|
| 256 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
|
| 258 |
def handle_chat(character_name, user_input, audio_file, video_file, user_id, chat_messages, current_chat_id):
|
| 259 |
if not user_id:
|
|
@@ -289,6 +296,17 @@ def create_interface():
|
|
| 289 |
chat_messages.append({"role": "assistant", "content": response})
|
| 290 |
return chat_messages, new_chat_id, new_chat_id
|
| 291 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
chat_btn.click(fn=handle_chat, inputs=[character_dropdown, user_input, audio_input, video_input, user_id, chat_messages, current_chat_id], outputs=[chat_response, current_chat_id, chat_id_display])
|
| 293 |
|
| 294 |
with gr.Tab("Chat History"):
|
|
|
|
| 237 |
refresh_characters_btn.click(fn=lambda: gr.update(value=get_existing_characters()), outputs=[character_list])
|
| 238 |
|
| 239 |
with gr.Tab("Chat with Character"):
|
| 240 |
+
# Top row for "Choose Character" and "Current Chat ID"
|
| 241 |
with gr.Row():
|
| 242 |
with gr.Column(scale=1):
|
| 243 |
character_dropdown = gr.Dropdown(label="Choose Character", choices=[char[0] for char in get_existing_characters()], elem_id="character_dropdown")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
with gr.Column(scale=1):
|
| 245 |
+
chat_id_display = gr.Textbox(label="Current Chat ID", interactive=False, elem_id="chat_id_display")
|
| 246 |
|
| 247 |
+
# Main chat area with responses
|
| 248 |
+
with gr.Column():
|
| 249 |
+
chat_response = gr.Chatbot(label="Chat Responses", elem_id="chat_response", height=700, type="messages")
|
| 250 |
+
|
| 251 |
+
# Row for input elements (Your Message, Audio/Video buttons, and Send button at the bottom)
|
| 252 |
+
with gr.Row():
|
| 253 |
+
with gr.Column(scale=8):
|
| 254 |
+
user_input = gr.Textbox(label="Your Message", placeholder="Type your message", elem_id="user_input", lines=1) # Reduced lines for a single-line input
|
| 255 |
+
with gr.Column(scale=2):
|
| 256 |
+
# Audio and Video as small buttons to the right of "Your Message"
|
| 257 |
+
audio_button = gr.Button("🎤 Audio", elem_id="audio_button", size="sm")
|
| 258 |
+
video_button = gr.Button("📹 Video", elem_id="video_button", size="sm")
|
| 259 |
+
|
| 260 |
+
# Send button below the chat response area
|
| 261 |
+
with gr.Row():
|
| 262 |
+
with gr.Column(scale=1):
|
| 263 |
+
chat_btn = gr.Button("Send", variant="primary")
|
| 264 |
|
| 265 |
def handle_chat(character_name, user_input, audio_file, video_file, user_id, chat_messages, current_chat_id):
|
| 266 |
if not user_id:
|
|
|
|
| 296 |
chat_messages.append({"role": "assistant", "content": response})
|
| 297 |
return chat_messages, new_chat_id, new_chat_id
|
| 298 |
|
| 299 |
+
# Handle audio and video button clicks to trigger file uploads
|
| 300 |
+
def upload_audio():
|
| 301 |
+
return gr.update(value=None, visible=True), gr.update(value=None, visible=False)
|
| 302 |
+
|
| 303 |
+
def upload_video():
|
| 304 |
+
return gr.update(value=None, visible=False), gr.update(value=None, visible=True)
|
| 305 |
+
|
| 306 |
+
audio_button.click(fn=upload_audio, outputs=[audio_input, video_input])
|
| 307 |
+
video_button.click(fn=upload_video, outputs=[audio_input, video_input])
|
| 308 |
+
|
| 309 |
+
# Connect the Send button to handle the chat
|
| 310 |
chat_btn.click(fn=handle_chat, inputs=[character_dropdown, user_input, audio_input, video_input, user_id, chat_messages, current_chat_id], outputs=[chat_response, current_chat_id, chat_id_display])
|
| 311 |
|
| 312 |
with gr.Tab("Chat History"):
|