Spaces:
Runtime error
Runtime error
Final update 🤞
Browse files
app.py
CHANGED
|
@@ -49,6 +49,15 @@ def update_images(image_component, directory="/home/user/app/"):
|
|
| 49 |
|
| 50 |
def create_chat_widget():
|
| 51 |
with gr.Blocks() as chatblock:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
with gr.Row():
|
| 53 |
chatbot = gr.Chatbot(
|
| 54 |
[],
|
|
@@ -67,6 +76,7 @@ def create_chat_widget():
|
|
| 67 |
txt.submit(update_bot, inputs=[txt, chatbot], outputs=[chatbot, txt])
|
| 68 |
send_button.click(update_bot, inputs=[txt, chatbot], outputs=[chatbot, txt])
|
| 69 |
|
|
|
|
| 70 |
with gr.Row():
|
| 71 |
image_display = gr.Image()
|
| 72 |
update_image_button = gr.Button("Update Image")
|
|
@@ -74,14 +84,15 @@ def create_chat_widget():
|
|
| 74 |
|
| 75 |
return chatblock
|
| 76 |
|
|
|
|
| 77 |
def update_bot(text, chatbot):
|
| 78 |
-
if text: # Append user input to the chat
|
| 79 |
-
chatbot.append(("User", text))
|
| 80 |
response_json = interpreter.chat(text, stream=True, display=False)
|
| 81 |
formatted_response, images = json_to_markdown(response_json)
|
| 82 |
-
# Append text response if it exists
|
| 83 |
if formatted_response.strip():
|
| 84 |
-
chatbot.append(("Assistant", formatted_response))
|
| 85 |
# Append images if any
|
| 86 |
for img_path in images:
|
| 87 |
if os.path.exists(img_path) and img_path.endswith('.png'):
|
|
|
|
| 49 |
|
| 50 |
def create_chat_widget():
|
| 51 |
with gr.Blocks() as chatblock:
|
| 52 |
+
# Adding a row for the New Chat button at the top
|
| 53 |
+
with gr.Row():
|
| 54 |
+
new_chat_button = gr.Button("New Chat")
|
| 55 |
+
new_chat_button.click(
|
| 56 |
+
lambda: ([], ""),
|
| 57 |
+
inputs=[],
|
| 58 |
+
outputs=[chatbot] )
|
| 59 |
+
|
| 60 |
+
# Main chat interface
|
| 61 |
with gr.Row():
|
| 62 |
chatbot = gr.Chatbot(
|
| 63 |
[],
|
|
|
|
| 76 |
txt.submit(update_bot, inputs=[txt, chatbot], outputs=[chatbot, txt])
|
| 77 |
send_button.click(update_bot, inputs=[txt, chatbot], outputs=[chatbot, txt])
|
| 78 |
|
| 79 |
+
# Image display row
|
| 80 |
with gr.Row():
|
| 81 |
image_display = gr.Image()
|
| 82 |
update_image_button = gr.Button("Update Image")
|
|
|
|
| 84 |
|
| 85 |
return chatblock
|
| 86 |
|
| 87 |
+
|
| 88 |
def update_bot(text, chatbot):
|
| 89 |
+
if text: # Append user input to the chat with "User:" prefix
|
| 90 |
+
chatbot.append(("User", f"User: {text}"))
|
| 91 |
response_json = interpreter.chat(text, stream=True, display=False)
|
| 92 |
formatted_response, images = json_to_markdown(response_json)
|
| 93 |
+
# Append text response with "Assistant:" prefix if it exists
|
| 94 |
if formatted_response.strip():
|
| 95 |
+
chatbot.append(("Assistant", f"Assistant: {formatted_response}"))
|
| 96 |
# Append images if any
|
| 97 |
for img_path in images:
|
| 98 |
if os.path.exists(img_path) and img_path.endswith('.png'):
|