Fix Media caption too long
Browse files- akn/Gemini/gemini.py +39 -2
akn/Gemini/gemini.py
CHANGED
@@ -336,6 +336,8 @@ async def chatbot_talk(client: Client, message: Message):
|
|
336 |
return await ai_reply.edit_text(f"Error: {e}")
|
337 |
|
338 |
if message.text:
|
|
|
|
|
339 |
await client.send_chat_action(message.chat.id, enums.ChatAction.TYPING)
|
340 |
await asyncio.sleep(1.5)
|
341 |
query = message.text.strip()
|
@@ -369,9 +371,11 @@ async def chatbot_talk(client: Client, message: Message):
|
|
369 |
await new_js.edit_text("Uploading image completed...")
|
370 |
x = GeminiLatest(api_keys=GOOGLE_API_KEY)
|
371 |
response_reads = x.get_response_image("What this?", file_path)
|
|
|
|
|
372 |
await message.reply_photo(
|
373 |
file_path,
|
374 |
-
caption=response_reads,
|
375 |
progress=progress,
|
376 |
progress_args=(
|
377 |
new_js,
|
@@ -397,9 +401,42 @@ async def chatbot_talk(client: Client, message: Message):
|
|
397 |
await new_js.edit_text("Uploading image completed...")
|
398 |
x = GeminiLatest(api_keys=GOOGLE_API_KEY)
|
399 |
response_reads = x.get_response_image("What this?", file_path)
|
|
|
|
|
400 |
await message.reply_photo(
|
401 |
file_path,
|
402 |
-
caption=response_reads,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
403 |
progress=progress,
|
404 |
progress_args=(
|
405 |
new_js,
|
|
|
336 |
return await ai_reply.edit_text(f"Error: {e}")
|
337 |
|
338 |
if message.text:
|
339 |
+
query_base = None
|
340 |
+
start_time = time.time()
|
341 |
await client.send_chat_action(message.chat.id, enums.ChatAction.TYPING)
|
342 |
await asyncio.sleep(1.5)
|
343 |
query = message.text.strip()
|
|
|
371 |
await new_js.edit_text("Uploading image completed...")
|
372 |
x = GeminiLatest(api_keys=GOOGLE_API_KEY)
|
373 |
response_reads = x.get_response_image("What this?", file_path)
|
374 |
+
end_time = time.time()
|
375 |
+
execution_time = end_time - start_time
|
376 |
await message.reply_photo(
|
377 |
file_path,
|
378 |
+
caption=response_reads + f"\nExecution time `{execution_time:.2f}` seconds",
|
379 |
progress=progress,
|
380 |
progress_args=(
|
381 |
new_js,
|
|
|
401 |
await new_js.edit_text("Uploading image completed...")
|
402 |
x = GeminiLatest(api_keys=GOOGLE_API_KEY)
|
403 |
response_reads = x.get_response_image("What this?", file_path)
|
404 |
+
end_time = time.time()
|
405 |
+
execution_time = end_time - start_time
|
406 |
await message.reply_photo(
|
407 |
file_path,
|
408 |
+
caption=response_reads + f"\nExecution time `{execution_time:.2f}` seconds",
|
409 |
+
progress=progress,
|
410 |
+
progress_args=(
|
411 |
+
new_js,
|
412 |
+
time.time(),
|
413 |
+
"Uploading image completed..."
|
414 |
+
)
|
415 |
+
)
|
416 |
+
backup_chat.append({"role": "model", "parts": [{"text": response_reads}]})
|
417 |
+
await db._update_chatbot_chat_in_db(message.from_user.id, backup_chat)
|
418 |
+
await new_js.delete()
|
419 |
+
return
|
420 |
+
|
421 |
+
except MediaCaptionTooLong as e:
|
422 |
+
backup_chat.append({"role": "user", "parts": [{"text": query_base}]})
|
423 |
+
await new_js.edit_text("Please wait, caption too try still processing...")
|
424 |
+
response_js = await js.image.create(
|
425 |
+
"black-forest-labs/flux-1-schnell",
|
426 |
+
image_read=True,
|
427 |
+
params_data={"query": query_base},
|
428 |
+
)
|
429 |
+
file_path = "randydev.jpg"
|
430 |
+
with open(file_path, "wb") as f:
|
431 |
+
f.write(response_js)
|
432 |
+
await new_js.edit_text("Uploading image completed...")
|
433 |
+
x = GeminiLatest(api_keys=GOOGLE_API_KEY)
|
434 |
+
response_reads = x.get_response_image("What this?", file_path)
|
435 |
+
end_time = time.time()
|
436 |
+
execution_time = end_time - start_time
|
437 |
+
await message.reply_photo(
|
438 |
+
file_path,
|
439 |
+
caption=f"Execution time `{execution_time:.2f}` seconds",
|
440 |
progress=progress,
|
441 |
progress_args=(
|
442 |
new_js,
|