Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from PIL import Image, ImageEnhance
|
3 |
+
import requests
|
4 |
+
from io import BytesIO
|
5 |
+
|
6 |
+
# Core image edit function (simulate behavior — replace with your model!)
|
7 |
+
def run_edit(image, prompt, negative_prompt, guidance_scale=7, steps=20):
|
8 |
+
print("Prompt:", prompt)
|
9 |
+
print("Negative Prompt:", negative_prompt)
|
10 |
+
print("Guidance Scale:", guidance_scale)
|
11 |
+
print("Steps:", steps)
|
12 |
+
|
13 |
+
# Dummy transformation: increase contrast and add a pink overlay
|
14 |
+
image = image.convert("RGB")
|
15 |
+
enhancer = ImageEnhance.Contrast(image)
|
16 |
+
image = enhancer.enhance(1.3)
|
17 |
+
|
18 |
+
pink_overlay = Image.new("RGB", image.size, (255, 182, 193)) # Light pink
|
19 |
+
edited = Image.blend(image, pink_overlay, alpha=0.2)
|
20 |
+
|
21 |
+
return edited
|
22 |
+
|
23 |
+
# Gradio Interface matching Hugging Face API structure
|
24 |
+
interface = gr.Interface(
|
25 |
+
fn=run_edit,
|
26 |
+
inputs=[
|
27 |
+
gr.Image(label="Image you would like to edit", type="pil"),
|
28 |
+
gr.Textbox(label="Prompt", placeholder="Describe what to change"),
|
29 |
+
gr.Textbox(label="Negative Prompt", placeholder="What to avoid"),
|
30 |
+
gr.Number(label="Guidance Scale", value=7.0),
|
31 |
+
gr.Slider(label="Steps", value=20, minimum=1, maximum=100)
|
32 |
+
],
|
33 |
+
outputs=gr.Image(label="Your result image"),
|
34 |
+
title="Image Editing with Prompt",
|
35 |
+
description="Edit an image using prompts. Adjust the scale and steps as needed.",
|
36 |
+
)
|
37 |
+
|
38 |
+
# Assign API name so Hugging Face Client can call it via `/run_edit`
|
39 |
+
interface.api_name = "/run_edit"
|
40 |
+
|
41 |
+
# Launch app (required for HF Spaces)
|
42 |
+
interface.launch()
|