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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -27
app.py CHANGED
@@ -1,27 +1,16 @@
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()
 
1
+ import os
2
+ from huggingface_hub import InferenceClient
3
+
4
+ client = InferenceClient(
5
+ provider="together",
6
+ api_key=os.environ["HF_TOKEN"],
7
+ )
8
+
9
+ # output is a PIL.Image object
10
+ image = client.text_to_image(
11
+ "Astronaut riding a horse",
12
+ model="black-forest-labs/FLUX.1-dev",
13
+ )
14
+
15
+ if __name__ == "__main__":
16
+ demo.launch()