Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -447,7 +447,11 @@ def chat_logic(
|
|
| 447 |
ocr_text = ""
|
| 448 |
if image_input is not None:
|
| 449 |
try:
|
| 450 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 451 |
img = Image.open(image_input.name)
|
| 452 |
elif isinstance(image_input, (bytes, bytearray)):
|
| 453 |
img = Image.open(io.BytesIO(image_input))
|
|
@@ -455,7 +459,10 @@ def chat_logic(
|
|
| 455 |
img = image_input
|
| 456 |
except Exception:
|
| 457 |
try:
|
| 458 |
-
|
|
|
|
|
|
|
|
|
|
| 459 |
except Exception:
|
| 460 |
img = None
|
| 461 |
if img is not None:
|
|
@@ -546,7 +553,9 @@ with gr.Blocks(title=APP_NAME, theme="soft") as demo:
|
|
| 546 |
)
|
| 547 |
|
| 548 |
with gr.Row():
|
| 549 |
-
|
|
|
|
|
|
|
| 550 |
audio_inp = gr.Audio(label="🎙️ কণ্ঠস্বৰ প্ৰশ্ন (Stub — not used now)", type="numpy")
|
| 551 |
|
| 552 |
with gr.Row():
|
|
|
|
| 447 |
ocr_text = ""
|
| 448 |
if image_input is not None:
|
| 449 |
try:
|
| 450 |
+
# Handle gradio image types: filepath (string), PIL Image, bytes/file-like
|
| 451 |
+
if isinstance(image_input, str):
|
| 452 |
+
img = Image.open(image_input)
|
| 453 |
+
elif hasattr(image_input, "name") and isinstance(image_input.name, str):
|
| 454 |
+
# uploaded file-like with .name
|
| 455 |
img = Image.open(image_input.name)
|
| 456 |
elif isinstance(image_input, (bytes, bytearray)):
|
| 457 |
img = Image.open(io.BytesIO(image_input))
|
|
|
|
| 459 |
img = image_input
|
| 460 |
except Exception:
|
| 461 |
try:
|
| 462 |
+
if hasattr(image_input, "read"):
|
| 463 |
+
img = Image.open(io.BytesIO(image_input.read()))
|
| 464 |
+
else:
|
| 465 |
+
img = None
|
| 466 |
except Exception:
|
| 467 |
img = None
|
| 468 |
if img is not None:
|
|
|
|
| 553 |
)
|
| 554 |
|
| 555 |
with gr.Row():
|
| 556 |
+
# Use a gr.Image type compatible with this Gradio version: 'filepath' or 'pil' or 'numpy'
|
| 557 |
+
# 'filepath' returns a string path in Spaces; code above handles it.
|
| 558 |
+
image_inp = gr.Image(label="📷 প্ৰশ্নৰ ছবি (Optional)", type="filepath")
|
| 559 |
audio_inp = gr.Audio(label="🎙️ কণ্ঠস্বৰ প্ৰশ্ন (Stub — not used now)", type="numpy")
|
| 560 |
|
| 561 |
with gr.Row():
|