UX4567 commited on
Commit
81536f6
·
verified ·
1 Parent(s): 1b2e644

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -18
app.py CHANGED
@@ -3,39 +3,58 @@ import torch
3
  from diffusers import StableDiffusionPipeline, UNet2DConditionModel
4
  import gradio as gr
5
 
6
-
7
  model_id = "UX4567/Stable-Diffusion-v1-3.0"
8
  device = "cuda" if torch.cuda.is_available() else "cpu"
9
 
10
  print("Model load ho raha hai...")
11
- # 1. Load your fine-tuned UNet in float16
12
  trained_unet = UNet2DConditionModel.from_pretrained(
13
- model_id,
14
  torch_dtype=torch.float16
15
  )
16
 
17
- # 2. Initialize pipeline with runwayml base and your custom UNet
18
  pipe = StableDiffusionPipeline.from_pretrained(
19
  "runwayml/stable-diffusion-v1-5",
20
  unet=trained_unet,
21
- torch_dtype=torch.float16
 
22
  ).to(device)
23
 
24
- # 3. Generation function with GPU decorator
25
  @spaces.GPU
26
  def generate_image(prompt):
27
- image = pipe(prompt, num_inference_steps=35, guidance_scale=7.5).images[0]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  return image
29
 
30
- # 4. Gradio UI setup
31
- demo = gr.Interface(
32
- fn=generate_image,
33
- inputs=gr.Textbox(label="Enter your prompt", value="a futuristic cyberpunk city at night"),
34
- outputs=gr.Image(label="Generated Image"),
35
- title="Calico Image Generator",
36
- description="Apne fine-tuned Stable Diffusion model se creative images generate karein!"
37
- )
 
 
 
 
 
 
 
 
 
38
 
39
- if __name__ == "__main__":
40
- demo.launch()
41
-
 
3
  from diffusers import StableDiffusionPipeline, UNet2DConditionModel
4
  import gradio as gr
5
 
 
6
  model_id = "UX4567/Stable-Diffusion-v1-3.0"
7
  device = "cuda" if torch.cuda.is_available() else "cpu"
8
 
9
  print("Model load ho raha hai...")
10
+
11
  trained_unet = UNet2DConditionModel.from_pretrained(
12
+ model_id,
13
  torch_dtype=torch.float16
14
  )
15
 
 
16
  pipe = StableDiffusionPipeline.from_pretrained(
17
  "runwayml/stable-diffusion-v1-5",
18
  unet=trained_unet,
19
+ torch_dtype=torch.float16,
20
+ safety_checker=None # thoda fast hoga
21
  ).to(device)
22
 
 
23
  @spaces.GPU
24
  def generate_image(prompt):
25
+ if not prompt.strip():
26
+ return None
27
+
28
+ # Quality booster
29
+ enhanced_prompt = f"{prompt}, ultra sharp, highly detailed, cinematic lighting, 8k"
30
+ negative_prompt = "blurry, low quality, low-res, distorted, ugly, bad anatomy, watermark, text, deformed"
31
+
32
+ image = pipe(
33
+ prompt=enhanced_prompt,
34
+ negative_prompt=negative_prompt,
35
+ num_inference_steps=35,
36
+ guidance_scale=8.5, # 7.5 se 8.5 - thoda zyada sharp
37
+ width=512,
38
+ height=768 # tere cyberpunk wale ke liye vertical better lagega
39
+ ).images[0]
40
  return image
41
 
42
+ # Better UI - tere screenshot jaisa
43
+ with gr.Blocks() as demo:
44
+ gr.Markdown("# Calico Image Generator\nApne fine-tuned Stable Diffusion model se creative images generate karein!")
45
+
46
+ with gr.Group():
47
+ prompt_box = gr.Textbox(label="Enter your prompt", value="a futuristic cyberpunk city at night", lines=2)
48
+
49
+ with gr.Row():
50
+ clear_btn = gr.Button("Clear")
51
+ submit_btn = gr.Button("Submit", variant="primary")
52
+
53
+ output_img = gr.Image(label="Generated Image")
54
+
55
+ gr.Markdown("Share via Link se share kar sakta hai tu!")
56
+
57
+ submit_btn.click(fn=generate_image, inputs=prompt_box, outputs=output_img)
58
+ clear_btn.click(lambda: ("", None), inputs=None, outputs=[prompt_box, output_img])
59
 
60
+ demo.launch()