Update app.py
Browse files
app.py
CHANGED
|
@@ -221,11 +221,12 @@ def chat_respond(message, history, chat_history_data, img_input, model_ui, groun
|
|
| 221 |
# 2. Préparation du contenu utilisateur
|
| 222 |
send_contents = [message]
|
| 223 |
if img_input:
|
| 224 |
-
|
|
|
|
| 225 |
|
| 226 |
user_display_text = message
|
| 227 |
if img_input:
|
| 228 |
-
user_display_text += "\n\n🖼️ *(
|
| 229 |
user_message_obj = {"role": "user", "content": user_display_text}
|
| 230 |
|
| 231 |
try:
|
|
@@ -265,9 +266,10 @@ def chat_respond(message, history, chat_history_data, img_input, model_ui, groun
|
|
| 265 |
# 5. Mise à jour de l'historique Gemini
|
| 266 |
u_parts = [types.Part.from_text(text=message)]
|
| 267 |
if img_input:
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
|
|
|
| 271 |
user_content_obj = types.Content(role="user", parts=u_parts)
|
| 272 |
|
| 273 |
model_content_obj = response.candidates[0].content
|
|
@@ -377,7 +379,8 @@ with gr.Blocks(title="Nano Vision Studio") as demo:
|
|
| 377 |
chat_history = gr.Chatbot(label="Session History", height=600)
|
| 378 |
with gr.Row():
|
| 379 |
chat_input = gr.Textbox(label="Your Message", scale=4)
|
| 380 |
-
chat_img = gr.Image(label="Input Image", type="filepath", height=100)
|
|
|
|
| 381 |
with gr.Row():
|
| 382 |
chat_btn = gr.Button("Send", variant="primary")
|
| 383 |
clear_btn = gr.Button("🗑️ New Session")
|
|
|
|
| 221 |
# 2. Préparation du contenu utilisateur
|
| 222 |
send_contents = [message]
|
| 223 |
if img_input:
|
| 224 |
+
for img_path in img_input:
|
| 225 |
+
send_contents.append(Image.open(img_path))
|
| 226 |
|
| 227 |
user_display_text = message
|
| 228 |
if img_input:
|
| 229 |
+
user_display_text += f"\n\n🖼️ *({len(img_input)} Images attached)*"
|
| 230 |
user_message_obj = {"role": "user", "content": user_display_text}
|
| 231 |
|
| 232 |
try:
|
|
|
|
| 266 |
# 5. Mise à jour de l'historique Gemini
|
| 267 |
u_parts = [types.Part.from_text(text=message)]
|
| 268 |
if img_input:
|
| 269 |
+
for img_path in img_input:
|
| 270 |
+
with open(img_path, "rb") as f:
|
| 271 |
+
img_bytes = f.read()
|
| 272 |
+
u_parts.append(types.Part.from_bytes(data=img_bytes, mime_type="image/jpeg"))
|
| 273 |
user_content_obj = types.Content(role="user", parts=u_parts)
|
| 274 |
|
| 275 |
model_content_obj = response.candidates[0].content
|
|
|
|
| 379 |
chat_history = gr.Chatbot(label="Session History", height=600)
|
| 380 |
with gr.Row():
|
| 381 |
chat_input = gr.Textbox(label="Your Message", scale=4)
|
| 382 |
+
# chat_img = gr.Image(label="Input Image", type="filepath", height=100)
|
| 383 |
+
chat_img = gr.File(label="Attach Images (Max 14)", file_count="multiple", type="filepath", height=100)
|
| 384 |
with gr.Row():
|
| 385 |
chat_btn = gr.Button("Send", variant="primary")
|
| 386 |
clear_btn = gr.Button("🗑️ New Session")
|