Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -49,10 +49,11 @@ def process_image(image, outline_size, outline_color):
|
|
| 49 |
output_buffer = io.BytesIO()
|
| 50 |
outlined_img.save(output_buffer, format="PNG", dpi=(300, 300)) # Set DPI here
|
| 51 |
output_buffer.seek(0)
|
| 52 |
-
#img_data = base64.b64encode(output_buffer.read()).decode("utf-8")
|
| 53 |
-
#data_url = f"data:image/png;base64,{img_data}"
|
| 54 |
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
except Exception as e:
|
| 58 |
print(f"Error processing image: {e}") # Log the error
|
|
@@ -77,22 +78,44 @@ with gr.Blocks(title="Sticker Maker") as interface:
|
|
| 77 |
create_btn = gr.Button("Create Sticker", variant="primary")
|
| 78 |
|
| 79 |
with gr.Column():
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
def update_image(image, outline_size, outline_color):
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
create_btn.click(
|
| 93 |
fn=update_image,
|
| 94 |
inputs=[image_upload, outline_size, outline_color],
|
| 95 |
-
outputs=
|
| 96 |
)
|
| 97 |
|
| 98 |
if __name__ == "__main__":
|
|
|
|
| 49 |
output_buffer = io.BytesIO()
|
| 50 |
outlined_img.save(output_buffer, format="PNG", dpi=(300, 300)) # Set DPI here
|
| 51 |
output_buffer.seek(0)
|
|
|
|
|
|
|
| 52 |
|
| 53 |
+
img_data = base64.b64encode(output_buffer.read()).decode("utf-8")
|
| 54 |
+
data_url = f"data:image/png;base64,{img_data}"
|
| 55 |
+
|
| 56 |
+
return data_url # Return data_url for display
|
| 57 |
|
| 58 |
except Exception as e:
|
| 59 |
print(f"Error processing image: {e}") # Log the error
|
|
|
|
| 78 |
create_btn = gr.Button("Create Sticker", variant="primary")
|
| 79 |
|
| 80 |
with gr.Column():
|
| 81 |
+
image_output_html = gr.HTML(
|
| 82 |
+
"""
|
| 83 |
+
<div style="position: relative;">
|
| 84 |
+
<img id="sticker-preview" src="" style="max-width: 100%; max-height: 400px;">
|
| 85 |
+
<a id="download-link" style="position: absolute; top: 10px; right: 10px; background-color: rgba(255, 255, 255, 0.7); padding: 5px; border-radius: 5px; display:none;" download="sticker.png">Download</a>
|
| 86 |
+
</div>
|
| 87 |
+
"""
|
| 88 |
+
)
|
| 89 |
|
| 90 |
def update_image(image, outline_size, outline_color):
|
| 91 |
+
try:
|
| 92 |
+
data_url = process_image(image, outline_size, outline_color)
|
| 93 |
+
if data_url:
|
| 94 |
+
return f"""
|
| 95 |
+
<div style="position: relative;">
|
| 96 |
+
<img id="sticker-preview" src="{data_url}" style="max-width: 100%; max-height: 400px;">
|
| 97 |
+
<a id="download-link" href="{data_url}" download="sticker.png" style="position: absolute; top: 10px; right: 10px; background-color: rgba(255, 255, 255, 0.7); padding: 5px; border-radius: 5px;">Download</a>
|
| 98 |
+
</div>
|
| 99 |
+
"""
|
| 100 |
+
else:
|
| 101 |
+
return """
|
| 102 |
+
<div style="position: relative;">
|
| 103 |
+
<img id="sticker-preview" src="" style="max-width: 100%; max-height: 400px;">
|
| 104 |
+
<a id="download-link" style="position: absolute; top: 10px; right: 10px; background-color: rgba(255, 255, 255, 0.7); padding: 5px; border-radius: 5px; display:none;" download="sticker.png">Download</a>
|
| 105 |
+
</div>
|
| 106 |
+
"""
|
| 107 |
+
except Exception as e:
|
| 108 |
+
print(f"Error in update_image: {e}") # Log the error
|
| 109 |
+
return f"""
|
| 110 |
+
<div style="position: relative;">
|
| 111 |
+
Error: {e}
|
| 112 |
+
</div>
|
| 113 |
+
"""
|
| 114 |
|
| 115 |
create_btn.click(
|
| 116 |
fn=update_image,
|
| 117 |
inputs=[image_upload, outline_size, outline_color],
|
| 118 |
+
outputs=image_output_html,
|
| 119 |
)
|
| 120 |
|
| 121 |
if __name__ == "__main__":
|