Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,17 +24,32 @@ def generate_image(prompt, model):
|
|
| 24 |
response = requests.get(url, stream=True)
|
| 25 |
response.raise_for_status()
|
| 26 |
|
| 27 |
-
#
|
| 28 |
img = Image.open(BytesIO(response.content)).convert("RGBA")
|
| 29 |
|
| 30 |
-
#
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
except Exception as e:
|
| 36 |
raise gr.Error(f"Unexpected error: {str(e)}")
|
| 37 |
|
|
|
|
| 38 |
# ✅ Gradio UI with custom CSS
|
| 39 |
with gr.Blocks(css="custom_hide_footer.css") as demo:
|
| 40 |
gr.Markdown("## 🎨 CodeHubb AI Image Generator")
|
|
|
|
| 24 |
response = requests.get(url, stream=True)
|
| 25 |
response.raise_for_status()
|
| 26 |
|
| 27 |
+
# ✅ Load generated image
|
| 28 |
img = Image.open(BytesIO(response.content)).convert("RGBA")
|
| 29 |
|
| 30 |
+
# ✅ Resize watermark to fixed width (e.g., 200px)
|
| 31 |
+
wm_width = 200
|
| 32 |
+
wm_ratio = wm_width / watermark.width
|
| 33 |
+
wm_size = (wm_width, int(watermark.height * wm_ratio))
|
| 34 |
+
resized_watermark = watermark.resize(wm_size)
|
| 35 |
|
| 36 |
+
# ✅ Paste watermark at top-left
|
| 37 |
+
img.paste(resized_watermark, (10, 10), resized_watermark)
|
| 38 |
+
|
| 39 |
+
# ✅ Convert to RGB and then to JPEG
|
| 40 |
+
final_img = img.convert("RGB")
|
| 41 |
+
|
| 42 |
+
# ✅ Save in-memory as JPEG (Gradio will return it)
|
| 43 |
+
buffer = BytesIO()
|
| 44 |
+
final_img.save(buffer, format="JPEG")
|
| 45 |
+
buffer.seek(0)
|
| 46 |
+
|
| 47 |
+
return Image.open(buffer)
|
| 48 |
|
| 49 |
except Exception as e:
|
| 50 |
raise gr.Error(f"Unexpected error: {str(e)}")
|
| 51 |
|
| 52 |
+
|
| 53 |
# ✅ Gradio UI with custom CSS
|
| 54 |
with gr.Blocks(css="custom_hide_footer.css") as demo:
|
| 55 |
gr.Markdown("## 🎨 CodeHubb AI Image Generator")
|