Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,28 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from diffusers import StableDiffusionImg2ImgPipeline
|
| 3 |
import torch
|
| 4 |
from PIL import Image
|
| 5 |
|
| 6 |
-
# 載入 ArchitectureRealMix 模型
|
| 7 |
model_id = "stablediffusionapi/architecturerealmix"
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
def generate_architecture(prompt, input_image, strength, guidance_scale):
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
# 建立 Gradio 使用者介面
|
| 19 |
iface = gr.Interface(
|
| 20 |
fn=generate_architecture,
|
| 21 |
inputs=[
|
|
@@ -26,7 +33,7 @@ iface = gr.Interface(
|
|
| 26 |
],
|
| 27 |
outputs=gr.Image(type="pil", label="生成的建築模擬圖"),
|
| 28 |
title="ArchitectureRealMix 建築模擬圖生成器",
|
| 29 |
-
description="
|
| 30 |
)
|
| 31 |
|
| 32 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from diffusers import StableDiffusionPipeline, StableDiffusionImg2ImgPipeline
|
| 3 |
import torch
|
| 4 |
from PIL import Image
|
| 5 |
|
|
|
|
| 6 |
model_id = "stablediffusionapi/architecturerealmix"
|
| 7 |
+
|
| 8 |
+
# 載入 text-to-image 和 image-to-image 兩個管線
|
| 9 |
+
pipe_txt2img = StableDiffusionPipeline.from_pretrained(model_id)
|
| 10 |
+
pipe_img2img = StableDiffusionImg2ImgPipeline.from_pretrained(model_id)
|
| 11 |
+
|
| 12 |
+
# 移動到 CPU(根據執行環境可改成 "cuda")
|
| 13 |
+
pipe_txt2img = pipe_txt2img.to("cpu")
|
| 14 |
+
pipe_img2img = pipe_img2img.to("cpu")
|
| 15 |
|
| 16 |
def generate_architecture(prompt, input_image, strength, guidance_scale):
|
| 17 |
+
if input_image is None:
|
| 18 |
+
# 無上傳圖片,純文字生成
|
| 19 |
+
image = pipe_txt2img(prompt=prompt, guidance_scale=guidance_scale).images[0]
|
| 20 |
+
else:
|
| 21 |
+
# 有圖片,上傳圖片到圖片生成
|
| 22 |
+
init_image = input_image.resize((512, 512)).convert("RGB")
|
| 23 |
+
image = pipe_img2img(prompt=prompt, init_image=init_image, strength=strength, guidance_scale=guidance_scale).images[0]
|
| 24 |
+
return image
|
| 25 |
|
|
|
|
| 26 |
iface = gr.Interface(
|
| 27 |
fn=generate_architecture,
|
| 28 |
inputs=[
|
|
|
|
| 33 |
],
|
| 34 |
outputs=gr.Image(type="pil", label="生成的建築模擬圖"),
|
| 35 |
title="ArchitectureRealMix 建築模擬圖生成器",
|
| 36 |
+
description="支援以文字描述生成建築模擬圖,亦可上傳圖片結合文字做圖片到圖片生成。"
|
| 37 |
)
|
| 38 |
|
| 39 |
iface.launch()
|