Student3331 commited on
Commit
b300a4b
·
verified ·
1 Parent(s): d76a062

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -19
app.py CHANGED
@@ -1,27 +1,22 @@
1
- import torch
2
- from diffusers import StableDiffusionPipeline
3
  import gradio as gr
 
 
4
 
5
- # Load model with CPU optimization
6
- pipe = StableDiffusionPipeline.from_pretrained(
7
- "CompVis/stable-diffusion-v1-4", # Stable Diffusion v1.4 model
8
- torch_dtype=torch.float16 # Use float16 for efficiency on CPU
9
- )
10
- pipe.to("cpu") # Ensure it's running on CPU
11
 
12
- # Define the function to generate an image from a prompt
13
  def generate_image(prompt):
14
- # Generate image using the pipeline
15
  image = pipe(prompt).images[0]
16
  return image
17
 
18
- # Create the Gradio interface
19
- demo = gr.Interface(
20
- fn=generate_image,
21
- inputs=gr.Textbox(label="Enter a prompt"),
22
- outputs=gr.Image(),
23
- title="Text-to-Image Generator (CPU Optimized)"
24
- )
25
 
26
- # Launch the app
27
- demo.launch()
 
 
 
1
  import gradio as gr
2
+ from diffusers import StableDiffusionPipeline
3
+ import torch
4
 
5
+ # Load the model
6
+ model_id = "CompVis/stable-diffusion-v1-4-original" # Change this to any model you want
7
+ pipe = StableDiffusionPipeline.from_pretrained(model_id)
8
+ pipe = pipe.to("cpu") # Ensures the model runs on CPU if no GPU is available
 
 
9
 
10
+ # Function to generate an image from text
11
  def generate_image(prompt):
12
+ # Generate image from prompt
13
  image = pipe(prompt).images[0]
14
  return image
15
 
16
+ # Gradio interface
17
+ iface = gr.Interface(fn=generate_image,
18
+ inputs=gr.Textbox(label="Enter a prompt"),
19
+ outputs=gr.Image(label="Generated Image"))
 
 
 
20
 
21
+ # Launch the interface
22
+ iface.launch()