Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,26 @@
|
|
| 1 |
-
import
|
| 2 |
-
from
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
| 13 |
)
|
| 14 |
|
| 15 |
if __name__ == "__main__":
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from diffusers import AutoPipelineForText2Image
|
| 3 |
+
import torch
|
| 4 |
|
| 5 |
+
# Memuat model text-to-image
|
| 6 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 7 |
+
pipeline = AutoPipelineForText2Image.from_pretrained(
|
| 8 |
+
"stable-diffusion-v1-5/stable-diffusion-v1-5",
|
| 9 |
+
torch_dtype=torch.float16 if device == "cuda" else torch.float32
|
| 10 |
+
).to(device)
|
| 11 |
+
|
| 12 |
+
def generate_image(prompt):
|
| 13 |
+
# Menghasilkan gambar dari teks
|
| 14 |
+
image = pipeline(prompt).images[0]
|
| 15 |
+
return image
|
| 16 |
|
| 17 |
+
# Membuat Antarmuka Gradio
|
| 18 |
+
demo = gr.Interface(
|
| 19 |
+
fn=generate_image,
|
| 20 |
+
inputs=gr.Textbox(label="Input your prompt"),
|
| 21 |
+
outputs=gr.Image(label="Image Result"),
|
| 22 |
+
title="AI Text-to-Image Generator",
|
| 23 |
+
description="Input Text via Stable Diffusion."
|
| 24 |
)
|
| 25 |
|
| 26 |
if __name__ == "__main__":
|