Bagda commited on
Commit
9e13de8
·
verified ·
1 Parent(s): 5ca0d23

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -16
app.py CHANGED
@@ -3,32 +3,33 @@ from diffusers import StableDiffusionImg2ImgPipeline
3
  import torch
4
  from PIL import Image
5
 
6
- # Load pretrained stable-diffusion model
7
  pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
8
- "runwayml/stable-diffusion-v1-5",
9
- torch_dtype=torch.float16,
10
- revision="fp16",
11
  use_auth_token=True
12
- ).to("cuda" if torch.cuda.is_available() else "cpu")
 
 
 
 
13
 
 
14
  def generate_thumbnail(prompt, input_image):
15
- # Resize image to 512x512
16
  image = input_image.resize((512, 512)).convert("RGB")
17
-
18
- # Generate image
19
- output = pipe(prompt=prompt, image=image, strength=0.75, guidance_scale=7.5)
20
- return output.images[0]
21
 
22
  # Gradio UI
23
- demo = gr.Interface(
24
  fn=generate_thumbnail,
25
  inputs=[
26
- gr.Textbox(label="Enter your prompt (e.g., NOOB vs PRO Minecraft style)"),
27
- gr.Image(type="pil", label="Upload Background Image"),
28
  ],
29
  outputs=gr.Image(label="Generated Thumbnail"),
30
- title="AI Thumbnail Generator",
31
- description="Upload an image and enter your text to create a Minecraft-style YouTube thumbnail"
32
  )
33
 
34
- demo.launch()
 
3
  import torch
4
  from PIL import Image
5
 
6
+ # Load the pretrained model
7
  pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
8
+ "runwayml/stable-diffusion-v1-5",
9
+ torch_dtype=torch.float16, # Or float32 if on CPU
 
10
  use_auth_token=True
11
+ )
12
+
13
+ # Set to GPU or CPU
14
+ device = "cuda" if torch.cuda.is_available() else "cpu"
15
+ pipe = pipe.to(device)
16
 
17
+ # Thumbnail generation function
18
  def generate_thumbnail(prompt, input_image):
 
19
  image = input_image.resize((512, 512)).convert("RGB")
20
+ result = pipe(prompt=prompt, image=image, strength=0.75, guidance_scale=7.5)
21
+ return result.images[0]
 
 
22
 
23
  # Gradio UI
24
+ interface = gr.Interface(
25
  fn=generate_thumbnail,
26
  inputs=[
27
+ gr.Textbox(label="Thumbnail Prompt (e.g., 'NOOB vs PRO in Minecraft')"),
28
+ gr.Image(type="pil", label="Upload Background Image")
29
  ],
30
  outputs=gr.Image(label="Generated Thumbnail"),
31
+ title="🖼️ AI Thumbnail Generator",
32
+ description="Upload a background image and enter a thumbnail prompt to generate your own YouTube-style thumbnail using Stable Diffusion!"
33
  )
34
 
35
+ interface.launch()