Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffusers import StableDiffusionPipeline
|
| 2 |
+
import torch
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
# 加载 SDXL 模型
|
| 6 |
+
pipe = StableDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16)
|
| 7 |
+
pipe.to("cuda") # 使用 GPU 加速
|
| 8 |
+
|
| 9 |
+
def generate_image(prompt):
|
| 10 |
+
image = pipe(prompt).images[0]
|
| 11 |
+
return image
|
| 12 |
+
|
| 13 |
+
# 创建 Gradio 界面
|
| 14 |
+
iface = gr.Interface(fn=generate_image, inputs="text", outputs="image", title="SDXL Image Generator")
|
| 15 |
+
iface.launch()
|