rohitr01 commited on
Commit
20acde3
·
verified ·
1 Parent(s): 063c24f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -23
app.py CHANGED
@@ -1,26 +1,9 @@
1
- import gradio as gr
2
- from diffusers import StableDiffusionPipeline
3
  import torch
 
4
 
5
- # Load the pre-trained model from Hugging Face (CompVis is the original model repository)
6
- pipe = StableDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2", torch_dtype=torch.float16)
7
-
8
- # Ensure that the model runs on CPU
9
- pipe = pipe.to("cpu") # Use CPU instead of CUDA (GPU)
10
-
11
- def generate_image(prompt):
12
- # Generate image based on the user's prompt
13
- image = pipe(prompt).images[0]
14
-
15
- return image
16
-
17
- # Create a Gradio interface
18
- iface = gr.Interface(
19
- fn=generate_image
20
- , # Function to call when the user submits a prompt
21
- inputs="text", # Input is a text field for the user to type their prompt
22
- outputs="image", # Output is an image, generated by the model
23
- live=True # Make the interface responsive in real-time
24
- )
25
 
26
- iface.launch()
 
 
 
 
 
1
  import torch
2
+ from diffusers import StableDiffusionPipeline
3
 
4
+ pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16)
5
+ pipe = pipe.to("cuda")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
+ prompt = "a photo of an astronaut riding a horse on mars"
8
+ image = pipe(prompt).images[0]
9
+ image