allfree commited on
Commit
e6a4994
·
verified ·
1 Parent(s): 073814c

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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="Masukkan Prompt Anda"),
21
+ outputs=gr.Image(label="Hasil Gambar"),
22
+ title="AI Text-to-Image Generator",
23
+ description="Masukkan deskripsi teks untuk menghasilkan gambar menggunakan Stable Diffusion."
24
+ )
25
+
26
+ if __name__ == "__main__":
27
+ demo.launch()