iammrrobot420's picture
Update app.py from anycoder
e48016b verified
import gradio as gr
import numpy as np
import cv2
from PIL import Image
import tempfile
def apply_modification(image, modification_type):
"""
Apply a simple modification to demonstrate the concept
This is a placeholder - you would replace with your actual processing
"""
img = np.array(image)
if modification_type == "small":
# Placeholder for small modification
img = cv2.circle(img, (img.shape[1]//2, img.shape[0]//2), 30, (255, 0, 0), -1)
elif modification_type == "large":
# Placeholder for large modification
img = cv2.circle(img, (img.shape[1]//2, img.shape[0]//2), 60, (0, 0, 255), -1)
return Image.fromarray(img)
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as demo:
gr.Markdown("""
# Personal Image Modifier
*Built with [anycoder](https://huggingface.co/spaces/akhaliq/anycoder)*
""")
with gr.Row():
with gr.Column():
input_image = gr.Image(label="Upload Your Image", type="pil")
modification = gr.Radio(
choices=["Small", "Large"],
label="Modification Type",
value="Small"
)
submit_btn = gr.Button("Apply Modification", variant="primary")
with gr.Column():
output_image = gr.Image(label="Modified Image")
download_btn = gr.DownloadButton("Download Result")
# Example images
gr.Examples(
examples=[["examples/male1.jpg", "Small"], ["examples/male2.jpg", "Large"]],
inputs=[input_image, modification],
outputs=output_image,
fn=apply_modification,
cache_examples=True
)
def process_and_download(image, mod_type):
modified = apply_modification(image, mod_type.lower())
temp_path = f"{tempfile.mkdtemp()}/modified.png"
modified.save(temp_path)
return modified, temp_path
submit_btn.click(
fn=process_and_download,
inputs=[input_image, modification],
outputs=[output_image, download_btn]
)
demo.launch(
title="Personal Image Modifier",
footer_links=[{"label": "Built with anycoder", "url": "https://huggingface.co/spaces/akhaliq/anycoder"}]
)