QuickNotesAI commited on
Commit
d0decf6
·
verified ·
1 Parent(s): f40c272

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -8
app.py CHANGED
@@ -2,24 +2,34 @@ import gradio as gr
2
  from diffusers import StableDiffusionPipeline
3
  import torch
4
 
5
- # Model Load (Free Space safe version)
6
  model_id = "runwayml/stable-diffusion-v1-5"
7
  pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float32)
8
- pipe = pipe.to("cpu") # Free Space में GPU नहीं होने पर CPU use
9
 
10
- def generate_image(prompt):
11
- image = pipe(prompt).images[0]
 
 
 
 
 
 
12
  return image
13
 
14
  # Gradio Interface
15
  iface = gr.Interface(
16
  fn=generate_image,
17
- inputs=gr.Textbox(lines=2, placeholder="Type your image description here...", label="Prompt"),
 
 
 
18
  outputs=gr.Image(label="Generated Image"),
19
- title="AI Image Generator",
20
  description="""
21
- Type any text and get beautiful AI-generated images instantly!
22
- Free low-res images available. Perfect for posters, social media, and creative art.
 
23
  """,
24
  allow_flagging="never"
25
  )
 
2
  from diffusers import StableDiffusionPipeline
3
  import torch
4
 
5
+ # Model Load (Free Space friendly)
6
  model_id = "runwayml/stable-diffusion-v1-5"
7
  pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float32)
8
+ pipe = pipe.to("cpu") # Free Space CPU safe
9
 
10
+ # Function for fast low-res preview + high-res paid option
11
+ def generate_image(prompt, high_res=False):
12
+ if high_res:
13
+ # Paid high-res: slower
14
+ image = pipe(prompt, height=512, width=512).images[0]
15
+ else:
16
+ # Free low-res: faster
17
+ image = pipe(prompt, height=256, width=256).images[0]
18
  return image
19
 
20
  # Gradio Interface
21
  iface = gr.Interface(
22
  fn=generate_image,
23
+ inputs=[
24
+ gr.Textbox(lines=2, placeholder="Type your image description here...", label="Prompt"),
25
+ gr.Checkbox(label="High-Resolution (Paid Feature)")
26
+ ],
27
  outputs=gr.Image(label="Generated Image"),
28
+ title="AI Image Generator (Fast Preview)",
29
  description="""
30
+ Type any text to get beautiful AI-generated images instantly!
31
+ Free low-res images for fast preview.
32
+ Check High-Resolution for paid download.
33
  """,
34
  allow_flagging="never"
35
  )