Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,6 @@ from diffusers import StableDiffusionInstructPix2PixPipeline, EulerAncestralDisc
|
|
| 4 |
from PIL import Image, ImageOps
|
| 5 |
|
| 6 |
# 1. Model Setup
|
| 7 |
-
# 加載 Instruct-Pix2Pix 模型
|
| 8 |
model_id = "timbrooks/instruct-pix2pix"
|
| 9 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 10 |
|
|
@@ -20,13 +19,11 @@ pipe.to(device)
|
|
| 20 |
pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
|
| 21 |
|
| 22 |
# 2. Core Function
|
| 23 |
-
# 定義圖像編輯函數
|
| 24 |
def edit_image(input_image, instruction, steps, guidance_scale, image_guidance_scale):
|
| 25 |
if input_image is None:
|
| 26 |
return None
|
| 27 |
|
| 28 |
# Resize image for speed optimization on free tier
|
| 29 |
-
# 為了在免費服務器上運行流暢,將圖片限制在 512px
|
| 30 |
width, height = input_image.size
|
| 31 |
max_dim = 512
|
| 32 |
if width > max_dim or height > max_dim:
|
|
@@ -46,8 +43,16 @@ def edit_image(input_image, instruction, steps, guidance_scale, image_guidance_s
|
|
| 46 |
return images[0]
|
| 47 |
|
| 48 |
# 3. Create Gradio Interface
|
| 49 |
-
# 創建網頁界面 (英文版)
|
| 50 |
with gr.Blocks(theme='gradio/soft') as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
gr.Markdown("# 🎨 CycleSphere")
|
| 52 |
gr.Markdown("Upload an image and enter an instruction to edit it (e.g., 'Turn the sky red' or 'Make it look like a painting').")
|
| 53 |
|
|
|
|
| 4 |
from PIL import Image, ImageOps
|
| 5 |
|
| 6 |
# 1. Model Setup
|
|
|
|
| 7 |
model_id = "timbrooks/instruct-pix2pix"
|
| 8 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 9 |
|
|
|
|
| 19 |
pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
|
| 20 |
|
| 21 |
# 2. Core Function
|
|
|
|
| 22 |
def edit_image(input_image, instruction, steps, guidance_scale, image_guidance_scale):
|
| 23 |
if input_image is None:
|
| 24 |
return None
|
| 25 |
|
| 26 |
# Resize image for speed optimization on free tier
|
|
|
|
| 27 |
width, height = input_image.size
|
| 28 |
max_dim = 512
|
| 29 |
if width > max_dim or height > max_dim:
|
|
|
|
| 43 |
return images[0]
|
| 44 |
|
| 45 |
# 3. Create Gradio Interface
|
|
|
|
| 46 |
with gr.Blocks(theme='gradio/soft') as demo:
|
| 47 |
+
|
| 48 |
+
gr.HTML("""
|
| 49 |
+
<div style="padding-bottom: 10px;">
|
| 50 |
+
<a href="https://cyc1e5phere.netlify.app" target="_self" style="text-decoration: none; color: #2e7d32; font-weight: bold; font-size: 1.1em; display: flex; align-items: center; transition: opacity 0.3s;">
|
| 51 |
+
<span style="margin-right: 8px; font-size: 1.5em;">←</span> Back to Home
|
| 52 |
+
</a>
|
| 53 |
+
</div>
|
| 54 |
+
""")
|
| 55 |
+
|
| 56 |
gr.Markdown("# 🎨 CycleSphere")
|
| 57 |
gr.Markdown("Upload an image and enter an instruction to edit it (e.g., 'Turn the sky red' or 'Make it look like a painting').")
|
| 58 |
|