Prgckwb commited on
Commit
b024062
1 Parent(s): f901652

:tada: init

Browse files
Files changed (2) hide show
  1. app.py +42 -4
  2. requirements.txt +8 -0
app.py CHANGED
@@ -1,7 +1,45 @@
1
  import gradio as gr
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import spaces
3
+ import torch
4
+ from diffusers import DiffusionPipeline
5
 
 
 
6
 
7
+ @spaces.GPU()
8
+ @torch.inference_mode()
9
+ def inference(
10
+ model_id: str,
11
+ prompt: str,
12
+ negative_prompt: str = "",
13
+ progress=gr.Progress(track_tqdm=True),
14
+ ):
15
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
16
+
17
+ pipe = DiffusionPipeline.from_pretrained(
18
+ model_id,
19
+ torch_dtype=torch.float16,
20
+ ).to(device)
21
+
22
+ image = pipe(
23
+ prompt,
24
+ negative_prompt=negative_prompt,
25
+ ).images[0]
26
+
27
+ return image
28
+
29
+
30
+ if __name__ == "__main__":
31
+ demo = gr.Interface(
32
+ fn=inference,
33
+ inputs=[
34
+ gr.Text(
35
+ label="Model ID",
36
+ value="stabilityai/stable-diffusion-3-medium-diffusers",
37
+ ),
38
+ gr.Text(label="Prompt", value=""),
39
+ gr.Text(label="Negative Prompt", value=""),
40
+ ],
41
+ outputs=[
42
+ gr.Image(label="Image", type="pil"),
43
+ ],
44
+ )
45
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ gradio
2
+ torch
3
+ torchvision
4
+ safetensors
5
+ diffusers
6
+ transformers
7
+ ftfy
8
+ accelerate