SAUL19 commited on
Commit
65ad1db
·
1 Parent(s): 08e13ae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -4
app.py CHANGED
@@ -1,7 +1,24 @@
1
  import gradio as gr
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import torch
3
+ from diffusers import StableDiffusionPipeline
4
 
5
+ model_id = "CompVis/stable-diffusion-v1-4"
6
+ device = "cuda" if torch.cuda.is_available() else "cpu"
7
 
8
+ pipe = StableDiffusionPipeline.from_pretrained(
9
+ model_id, torch_dtype=torch.float32)
10
+
11
+ pipe = pipe.to(device)
12
+
13
+ def generatorImage(name):
14
+ prompt = name
15
+ image = pipe(prompt).images[0]
16
+ image_name = '-'.join(prompt.split()) + ".png"
17
+ image.save("./images/" + image_name)
18
+
19
+ return image_name
20
+
21
+
22
+
23
+ iface = gr.Interface(fn=generatorImage, inputs="text", outputs="text")
24
+ iface.launch()