Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -38,9 +38,8 @@ def get_api_response(api_key, user_message, user_image):
|
|
38 |
})
|
39 |
|
40 |
if user_image:
|
41 |
-
# Open the uploaded image
|
42 |
-
|
43 |
-
base64_img = encode_image(img)
|
44 |
messages.append({
|
45 |
"type": "image_url",
|
46 |
"image_url": {"url": f"data:image/png;base64,{base64_img}"}
|
@@ -80,7 +79,10 @@ def chatbot_response(api_key, user_message, user_image, history):
|
|
80 |
"""
|
81 |
# Append the user's message to the history
|
82 |
if user_message or user_image:
|
83 |
-
|
|
|
|
|
|
|
84 |
|
85 |
# Get the API response
|
86 |
api_result = get_api_response(api_key, user_message, user_image)
|
@@ -113,7 +115,7 @@ with gr.Blocks() as demo:
|
|
113 |
interactive=True
|
114 |
)
|
115 |
|
116 |
-
chatbot = gr.Chatbot(label="💬 Chatbot") # `.style()` method
|
117 |
|
118 |
with gr.Row():
|
119 |
with gr.Column(scale=4):
|
@@ -125,7 +127,7 @@ with gr.Blocks() as demo:
|
|
125 |
with gr.Column(scale=1):
|
126 |
user_image = gr.Image(
|
127 |
label="Upload Image",
|
128 |
-
type="
|
129 |
# Removed the 'tool' parameter
|
130 |
interactive=True
|
131 |
)
|
|
|
38 |
})
|
39 |
|
40 |
if user_image:
|
41 |
+
# Open the uploaded image (already a PIL Image)
|
42 |
+
base64_img = encode_image(user_image)
|
|
|
43 |
messages.append({
|
44 |
"type": "image_url",
|
45 |
"image_url": {"url": f"data:image/png;base64,{base64_img}"}
|
|
|
79 |
"""
|
80 |
# Append the user's message to the history
|
81 |
if user_message or user_image:
|
82 |
+
if user_image:
|
83 |
+
history.append(("User", user_message, user_image))
|
84 |
+
else:
|
85 |
+
history.append(("User", user_message, None))
|
86 |
|
87 |
# Get the API response
|
88 |
api_result = get_api_response(api_key, user_message, user_image)
|
|
|
115 |
interactive=True
|
116 |
)
|
117 |
|
118 |
+
chatbot = gr.Chatbot(label="💬 Chatbot") # Removed `.style()` method
|
119 |
|
120 |
with gr.Row():
|
121 |
with gr.Column(scale=4):
|
|
|
127 |
with gr.Column(scale=1):
|
128 |
user_image = gr.Image(
|
129 |
label="Upload Image",
|
130 |
+
type="pil", # Changed from 'file' to 'pil'
|
131 |
# Removed the 'tool' parameter
|
132 |
interactive=True
|
133 |
)
|