Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,7 +18,7 @@ def chat_with_image(message, image, history):
|
|
| 18 |
messages = [{"role": "system", "content": "You are a helpful assistant that can analyze images and text."}]
|
| 19 |
|
| 20 |
for human, assistant in history:
|
| 21 |
-
if isinstance(human,
|
| 22 |
# This is an image message
|
| 23 |
encoded_image = encode_image(Image.open(human[1]))
|
| 24 |
messages.append({
|
|
@@ -76,14 +76,17 @@ with gr.Blocks() as demo:
|
|
| 76 |
clear = gr.Button("Clear")
|
| 77 |
|
| 78 |
def user(user_message, image, history):
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
def bot(history):
|
| 82 |
-
user_message,
|
| 83 |
-
bot_message = chat_with_image(user_message,
|
| 84 |
-
history[-1]
|
| 85 |
for character in bot_message:
|
| 86 |
-
history[-1]
|
| 87 |
yield history
|
| 88 |
|
| 89 |
msg.submit(user, [msg, image, chatbot], [msg, image, chatbot], queue=False).then(
|
|
|
|
| 18 |
messages = [{"role": "system", "content": "You are a helpful assistant that can analyze images and text."}]
|
| 19 |
|
| 20 |
for human, assistant in history:
|
| 21 |
+
if isinstance(human, list) and len(human) == 2 and human[1] is not None:
|
| 22 |
# This is an image message
|
| 23 |
encoded_image = encode_image(Image.open(human[1]))
|
| 24 |
messages.append({
|
|
|
|
| 76 |
clear = gr.Button("Clear")
|
| 77 |
|
| 78 |
def user(user_message, image, history):
|
| 79 |
+
if image is not None:
|
| 80 |
+
return "", None, history + [[user_message, image], None]
|
| 81 |
+
else:
|
| 82 |
+
return "", None, history + [[user_message, None], None]
|
| 83 |
|
| 84 |
def bot(history):
|
| 85 |
+
user_message, user_image = history[-1][0]
|
| 86 |
+
bot_message = chat_with_image(user_message, user_image, history[:-1])
|
| 87 |
+
history[-1][1] = ""
|
| 88 |
for character in bot_message:
|
| 89 |
+
history[-1][1] += character
|
| 90 |
yield history
|
| 91 |
|
| 92 |
msg.submit(user, [msg, image, chatbot], [msg, image, chatbot], queue=False).then(
|