adminuser742150 commited on
Commit
248c796
·
verified ·
1 Parent(s): 1447e65

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -12
app.py CHANGED
@@ -3,23 +3,28 @@ import gradio as gr
3
  from diffusers import StableDiffusionPipeline
4
  import torch
5
 
6
- # Load model once
7
- model_id = "runwayml/stable-diffusion-v1-5"
8
- pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float32)
9
- pipe = pipe.to("cpu") # force CPU to run free on Spaces
 
 
 
 
10
 
11
- # Simple function for text-to-image
12
- def generate_image(prompt: str):
13
- image = pipe(prompt, num_inference_steps=20, guidance_scale=7.5).images[0]
14
  return image
15
 
16
- # API-only mode, no full UI
17
  demo = gr.Interface(
18
  fn=generate_image,
19
  inputs=gr.Textbox(label="Enter your prompt"),
20
- outputs=gr.Image(type="pil"),
21
- live=False,
 
22
  )
23
 
24
- # Make it lightweight & responsive (minimal layout)
25
- demo.launch(server_name="0.0.0.0", server_port=7860, show_api=True)
 
 
3
  from diffusers import StableDiffusionPipeline
4
  import torch
5
 
6
+ # Load Stable Diffusion pipeline (open source)
7
+ pipe = StableDiffusionPipeline.from_pretrained(
8
+ "runwayml/stable-diffusion-v1-5",
9
+ torch_dtype=torch.float32
10
+ )
11
+
12
+ # Force CPU (free Spaces usually don’t allow GPU)
13
+ pipe.to("cpu")
14
 
15
+ def generate_image(prompt):
16
+ image = pipe(prompt, guidance_scale=7.5).images[0]
 
17
  return image
18
 
19
+ # Gradio UI for testing
20
  demo = gr.Interface(
21
  fn=generate_image,
22
  inputs=gr.Textbox(label="Enter your prompt"),
23
+ outputs=gr.Image(label="Generated Image"),
24
+ title="Stable Diffusion Text-to-Image",
25
+ description="Enter a prompt and generate an image using Stable Diffusion."
26
  )
27
 
28
+ if __name__ == "__main__":
29
+ demo.launch()
30
+