Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -36,7 +36,6 @@
|
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
-
|
| 40 |
import os
|
| 41 |
import gradio as gr
|
| 42 |
from google import genai
|
|
@@ -55,9 +54,13 @@ def generate_or_edit_image(prompt, uploaded_img):
|
|
| 55 |
|
| 56 |
# If user uploads an image, include it in the request
|
| 57 |
if uploaded_img is not None:
|
| 58 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
buffered = BytesIO()
|
| 60 |
-
uploaded_img.save(buffered, format="PNG")
|
| 61 |
image_bytes = buffered.getvalue()
|
| 62 |
|
| 63 |
contents.append({
|
|
@@ -85,8 +88,7 @@ demo = gr.Interface(
|
|
| 85 |
gr.Textbox(label="Enter your prompt"),
|
| 86 |
gr.Image(
|
| 87 |
label="Upload an image (optional)",
|
| 88 |
-
type="pil",
|
| 89 |
-
file_types=[".jpg", ".jpeg", ".png"] # allow JPG, JPEG, PNG
|
| 90 |
)
|
| 91 |
],
|
| 92 |
outputs=gr.Image(label="Generated/Edited Image"),
|
|
@@ -96,4 +98,3 @@ demo = gr.Interface(
|
|
| 96 |
|
| 97 |
if __name__ == "__main__":
|
| 98 |
demo.launch()
|
| 99 |
-
|
|
|
|
| 36 |
|
| 37 |
|
| 38 |
|
|
|
|
| 39 |
import os
|
| 40 |
import gradio as gr
|
| 41 |
from google import genai
|
|
|
|
| 54 |
|
| 55 |
# If user uploads an image, include it in the request
|
| 56 |
if uploaded_img is not None:
|
| 57 |
+
# Validate image format
|
| 58 |
+
if uploaded_img.format not in ["JPEG", "JPG", "PNG"]:
|
| 59 |
+
return "❌ Please upload a JPG, JPEG, or PNG image."
|
| 60 |
+
|
| 61 |
+
# Convert uploaded image to PNG bytes (safe for Gemini)
|
| 62 |
buffered = BytesIO()
|
| 63 |
+
uploaded_img.save(buffered, format="PNG")
|
| 64 |
image_bytes = buffered.getvalue()
|
| 65 |
|
| 66 |
contents.append({
|
|
|
|
| 88 |
gr.Textbox(label="Enter your prompt"),
|
| 89 |
gr.Image(
|
| 90 |
label="Upload an image (optional)",
|
| 91 |
+
type="pil" # just keep type=pil, no file_types in your version
|
|
|
|
| 92 |
)
|
| 93 |
],
|
| 94 |
outputs=gr.Image(label="Generated/Edited Image"),
|
|
|
|
| 98 |
|
| 99 |
if __name__ == "__main__":
|
| 100 |
demo.launch()
|
|
|