Bagda commited on
Commit
84c269c
·
verified ·
1 Parent(s): 092aa85

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -19
app.py CHANGED
@@ -1,32 +1,34 @@
1
  import gradio as gr
2
- import torch
3
  from diffusers import StableDiffusionImg2ImgPipeline
 
4
  from PIL import Image
5
- import numpy as np
6
 
7
- # Load pre-trained model (no fine-tuning required)
8
  pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
9
- "runwayml/stable-diffusion-v1-5",
10
- torch_dtype=torch.float16
11
- ).to("cuda")
 
 
12
 
13
  def generate_thumbnail(prompt, input_image):
14
- if input_image is None or prompt.strip() == "":
15
- return None
16
-
17
- # Convert image to 512x512
18
- input_image = input_image.resize((512, 512))
19
 
20
- result = pipe(prompt=prompt, image=input_image, strength=0.75, guidance_scale=7.5).images[0]
21
- return result
 
22
 
23
- gr.Interface(
 
24
  fn=generate_thumbnail,
25
  inputs=[
26
- gr.Textbox(label="Prompt (e.g. 'NOOB vs PRO Minecraft epic battle')"),
27
- gr.Image(label="Background Image", type="pil")
28
  ],
29
  outputs=gr.Image(label="Generated Thumbnail"),
30
- title="🖼️ AI Thumbnail Generator (Stable Diffusion)",
31
- description="Upload a background + write your prompt to generate a Minecraft-style thumbnail using Stable Diffusion v1.5"
32
- ).launch()
 
 
 
1
  import gradio as gr
 
2
  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()