Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,16 +2,16 @@ import gradio as gr
|
|
| 2 |
import torch
|
| 3 |
from diffusers import StableDiffusionPipeline, LCMScheduler
|
| 4 |
import time
|
|
|
|
| 5 |
|
| 6 |
# ============================================
|
| 7 |
-
# LCM मॉडल लोडिंग
|
| 8 |
# ============================================
|
| 9 |
|
| 10 |
model_id = "SimianLuo/LCM_Dreamshaper_v7"
|
| 11 |
|
| 12 |
print("🔄 LCM मॉडल लोड हो रहा है...")
|
| 13 |
|
| 14 |
-
# स्टैंडर्ड पाइपलाइन का उपयोग करें (कस्टम पाइपलाइन नहीं)
|
| 15 |
pipe = StableDiffusionPipeline.from_pretrained(
|
| 16 |
model_id,
|
| 17 |
torch_dtype=torch.float32,
|
|
@@ -19,10 +19,8 @@ pipe = StableDiffusionPipeline.from_pretrained(
|
|
| 19 |
requires_safety_checker=False
|
| 20 |
)
|
| 21 |
|
| 22 |
-
# LCM Scheduler सेट करें
|
| 23 |
pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
|
| 24 |
|
| 25 |
-
# CPU ऑप्टिमाइज़ेशन
|
| 26 |
try:
|
| 27 |
pipe.enable_attention_slicing()
|
| 28 |
pipe.enable_vae_slicing()
|
|
@@ -32,120 +30,387 @@ except Exception as e:
|
|
| 32 |
|
| 33 |
print("✅ मॉडल तैयार है!")
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
# ============================================
|
| 36 |
# इमेज जनरेशन फंक्शन
|
| 37 |
# ============================================
|
| 38 |
|
| 39 |
-
def generate_image(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
"""
|
| 41 |
-
|
| 42 |
"""
|
| 43 |
# खाली प्रॉम्प्ट चेक करें
|
| 44 |
if not prompt or prompt.strip() == "":
|
| 45 |
-
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
if seed < 0 or seed is None:
|
| 49 |
generator = torch.Generator().manual_seed(int(time.time()))
|
| 50 |
-
actual_seed =
|
| 51 |
else:
|
| 52 |
generator = torch.Generator().manual_seed(int(seed))
|
| 53 |
actual_seed = int(seed)
|
| 54 |
|
| 55 |
-
#
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
|
|
|
| 59 |
print(f"🎨 जनरेट हो रहा है...")
|
| 60 |
-
print(f"
|
| 61 |
-
print(f" स्टेप्स: {steps}, गाइडेंस: {guidance_scale}
|
|
|
|
| 62 |
|
| 63 |
try:
|
| 64 |
-
|
|
|
|
| 65 |
result = pipe(
|
| 66 |
prompt=prompt,
|
| 67 |
negative_prompt=negative_prompt,
|
| 68 |
-
num_inference_steps=
|
| 69 |
-
guidance_scale=
|
| 70 |
generator=generator,
|
| 71 |
-
width=
|
| 72 |
-
height=
|
| 73 |
-
# LCM के लिए ये ज़रूरी सेटिंग्स हैं
|
| 74 |
output_type="pil",
|
| 75 |
num_images_per_prompt=1
|
| 76 |
)
|
| 77 |
|
| 78 |
-
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
except Exception as e:
|
|
|
|
| 82 |
print(f"❌ एरर: {e}")
|
| 83 |
-
|
| 84 |
-
traceback.print_exc()
|
| 85 |
-
return None
|
| 86 |
|
| 87 |
# ============================================
|
| 88 |
# Gradio UI
|
| 89 |
# ============================================
|
| 90 |
|
| 91 |
-
with gr.Blocks(
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
gr.Markdown("""
|
| 94 |
-
#
|
| 95 |
|
| 96 |
-
**
|
| 97 |
""")
|
| 98 |
|
| 99 |
with gr.Row():
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
label="📝 प्रॉम्प्ट",
|
| 103 |
-
value="RAW photo, hyperrealistic, beautiful sunset over mountains, golden hour, 8k, cinematic",
|
| 104 |
-
lines=2
|
| 105 |
-
)
|
| 106 |
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
with gr.Row():
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
|
|
|
| 117 |
)
|
| 118 |
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
|
|
|
|
|
|
| 122 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
value=-1,
|
| 127 |
-
info="-1 = रैंडम"
|
| 128 |
)
|
| 129 |
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
fn=generate_image,
|
| 137 |
-
inputs=[
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
)
|
| 140 |
|
|
|
|
|
|
|
|
|
|
| 141 |
gr.Examples(
|
| 142 |
examples=[
|
| 143 |
-
["RAW photo,
|
| 144 |
-
["
|
| 145 |
-
["
|
|
|
|
| 146 |
],
|
| 147 |
-
inputs=[prompt, negative_prompt,
|
|
|
|
| 148 |
)
|
| 149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
if __name__ == "__main__":
|
| 151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import torch
|
| 3 |
from diffusers import StableDiffusionPipeline, LCMScheduler
|
| 4 |
import time
|
| 5 |
+
from PIL import Image
|
| 6 |
|
| 7 |
# ============================================
|
| 8 |
+
# LCM मॉडल लोडिंग
|
| 9 |
# ============================================
|
| 10 |
|
| 11 |
model_id = "SimianLuo/LCM_Dreamshaper_v7"
|
| 12 |
|
| 13 |
print("🔄 LCM मॉडल लोड हो रहा है...")
|
| 14 |
|
|
|
|
| 15 |
pipe = StableDiffusionPipeline.from_pretrained(
|
| 16 |
model_id,
|
| 17 |
torch_dtype=torch.float32,
|
|
|
|
| 19 |
requires_safety_checker=False
|
| 20 |
)
|
| 21 |
|
|
|
|
| 22 |
pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
|
| 23 |
|
|
|
|
| 24 |
try:
|
| 25 |
pipe.enable_attention_slicing()
|
| 26 |
pipe.enable_vae_slicing()
|
|
|
|
| 30 |
|
| 31 |
print("✅ मॉडल तैयार है!")
|
| 32 |
|
| 33 |
+
# ============================================
|
| 34 |
+
# प्लेटफॉर्म प्रीसेट्स
|
| 35 |
+
# ============================================
|
| 36 |
+
|
| 37 |
+
PLATFORM_PRESETS = {
|
| 38 |
+
"📱 Instagram Post (Square)": {"width": 1080, "height": 1080},
|
| 39 |
+
"📱 Instagram Story": {"width": 1080, "height": 1920},
|
| 40 |
+
"📱 Instagram Portrait": {"width": 1080, "height": 1350},
|
| 41 |
+
"📱 Instagram Landscape": {"width": 1080, "height": 566},
|
| 42 |
+
"📘 Facebook Post": {"width": 1200, "height": 630},
|
| 43 |
+
"📘 Facebook Cover": {"width": 851, "height": 315},
|
| 44 |
+
"🐦 Twitter/X Post": {"width": 1600, "height": 900},
|
| 45 |
+
"🐦 Twitter/X Header": {"width": 1500, "height": 500},
|
| 46 |
+
"📺 YouTube Thumbnail": {"width": 1280, "height": 720},
|
| 47 |
+
"📺 YouTube Channel Banner": {"width": 2560, "height": 1440},
|
| 48 |
+
"💼 LinkedIn Post": {"width": 1200, "height": 627},
|
| 49 |
+
"💼 LinkedIn Banner": {"width": 1584, "height": 396},
|
| 50 |
+
"📌 Pinterest Pin": {"width": 1000, "height": 1500},
|
| 51 |
+
"🎵 TikTok Video": {"width": 1080, "height": 1920},
|
| 52 |
+
"💬 WhatsApp Status": {"width": 1080, "height": 1920},
|
| 53 |
+
"🖥️ Desktop Wallpaper (HD)": {"width": 1920, "height": 1080},
|
| 54 |
+
"🖥️ Desktop Wallpaper (4K)": {"width": 3840, "height": 2160},
|
| 55 |
+
"📱 Mobile Wallpaper": {"width": 1080, "height": 1920},
|
| 56 |
+
"🎨 Square (1:1)": {"width": 1024, "height": 1024},
|
| 57 |
+
"🎨 Portrait (2:3)": {"width": 1024, "height": 1536},
|
| 58 |
+
"🎨 Landscape (3:2)": {"width": 1536, "height": 1024},
|
| 59 |
+
"🎨 Wide (16:9)": {"width": 1280, "height": 720},
|
| 60 |
+
"✏️ Custom Size": {"width": 512, "height": 512},
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
QUALITY_PRESETS = {
|
| 64 |
+
"⚡ Ultra Fast (Draft)": {"steps": 2, "guidance": 0.8},
|
| 65 |
+
"🚀 Fast (Good)": {"steps": 4, "guidance": 1.0},
|
| 66 |
+
"🎯 Balanced (Better)": {"steps": 6, "guidance": 1.2},
|
| 67 |
+
"💎 High Quality (Best)": {"steps": 8, "guidance": 1.5},
|
| 68 |
+
"🔬 Custom": {"steps": 4, "guidance": 1.0},
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
# ============================================
|
| 72 |
+
# प्लेटफॉर्म बदलने पर ऑटो-अपडेट फंक्शन
|
| 73 |
+
# ============================================
|
| 74 |
+
|
| 75 |
+
def update_size_from_preset(platform_choice):
|
| 76 |
+
"""प्लेटफॉर्म चुनने पर width और height अपडेट करें"""
|
| 77 |
+
if platform_choice in PLATFORM_PRESETS:
|
| 78 |
+
preset = PLATFORM_PRESETS[platform_choice]
|
| 79 |
+
return preset["width"], preset["height"]
|
| 80 |
+
return 512, 512
|
| 81 |
+
|
| 82 |
+
def update_quality_from_preset(quality_choice):
|
| 83 |
+
"""क्वालिटी प्रीसेट चुनने पर steps और guidance अपडेट करें"""
|
| 84 |
+
if quality_choice in QUALITY_PRESETS and quality_choice != "🔬 Custom":
|
| 85 |
+
preset = QUALITY_PRESETS[quality_choice]
|
| 86 |
+
return preset["steps"], preset["guidance"]
|
| 87 |
+
return 4, 1.0
|
| 88 |
+
|
| 89 |
# ============================================
|
| 90 |
# इमेज जनरेशन फंक्शन
|
| 91 |
# ============================================
|
| 92 |
|
| 93 |
+
def generate_image(
|
| 94 |
+
prompt, negative_prompt,
|
| 95 |
+
platform_choice, quality_choice,
|
| 96 |
+
custom_width, custom_height,
|
| 97 |
+
custom_steps, custom_guidance,
|
| 98 |
+
seed, enhance_prompt
|
| 99 |
+
):
|
| 100 |
"""
|
| 101 |
+
एडवांस्ड इमेज जनरेशन फंक्शन
|
| 102 |
"""
|
| 103 |
# खाली प्रॉम्प्ट चेक करें
|
| 104 |
if not prompt or prompt.strip() == "":
|
| 105 |
+
return None, "❌ कृपया प्रॉम्पट डालें"
|
| 106 |
+
|
| 107 |
+
# साइज़ सेट करें
|
| 108 |
+
if platform_choice == "✏️ Custom Size":
|
| 109 |
+
width = int(custom_width)
|
| 110 |
+
height = int(custom_height)
|
| 111 |
+
else:
|
| 112 |
+
preset = PLATFORM_PRESETS.get(platform_choice, {"width": 512, "height": 512})
|
| 113 |
+
width = preset["width"]
|
| 114 |
+
height = preset["height"]
|
| 115 |
+
|
| 116 |
+
# साइज़ लिमिट चेक (CPU मेमोरी के लिए)
|
| 117 |
+
if width * height > 1024 * 1024: # 1MP से बड़ी इमेज
|
| 118 |
+
scale = (1024 * 1024) / (width * height)
|
| 119 |
+
width = int(width * (scale ** 0.5))
|
| 120 |
+
height = int(height * (scale ** 0.5))
|
| 121 |
+
width = (width // 64) * 64
|
| 122 |
+
height = (height // 64) * 64
|
| 123 |
+
size_warning = f"⚠️ बड़ी इमेज को {width}x{height} पर रिसाइज़ किया गया (मेमोरी लिमिट)"
|
| 124 |
+
else:
|
| 125 |
+
# 64 के मल्टीपल में कन्वर्ट करें
|
| 126 |
+
width = (width // 64) * 64
|
| 127 |
+
height = (height // 64) * 64
|
| 128 |
+
size_warning = ""
|
| 129 |
|
| 130 |
+
# क्वालिटी सेट करें
|
| 131 |
+
if quality_choice == "🔬 Custom":
|
| 132 |
+
steps = int(custom_steps)
|
| 133 |
+
guidance_scale = float(custom_guidance)
|
| 134 |
+
else:
|
| 135 |
+
preset = QUALITY_PRESETS.get(quality_choice, {"steps": 4, "guidance": 1.0})
|
| 136 |
+
steps = preset["steps"]
|
| 137 |
+
guidance_scale = preset["guidance"]
|
| 138 |
+
|
| 139 |
+
# प्रॉम्प्ट एन्हांसमेंट
|
| 140 |
+
if enhance_prompt:
|
| 141 |
+
if not prompt.lower().startswith("raw photo"):
|
| 142 |
+
prompt = "RAW photo, hyperrealistic, " + prompt
|
| 143 |
+
if "8k" not in prompt.lower():
|
| 144 |
+
prompt = prompt + ", 8k, highly detailed, cinematic lighting"
|
| 145 |
+
|
| 146 |
+
# नेगेटिव प्रॉम्प्ट
|
| 147 |
+
if not negative_prompt:
|
| 148 |
+
negative_prompt = "cartoon, anime, illustration, painting, drawing, 3d render, blurry, low quality, distorted, ugly, bad anatomy"
|
| 149 |
+
|
| 150 |
+
# सीड
|
| 151 |
if seed < 0 or seed is None:
|
| 152 |
generator = torch.Generator().manual_seed(int(time.time()))
|
| 153 |
+
actual_seed = int(time.time()) % 9999999
|
| 154 |
else:
|
| 155 |
generator = torch.Generator().manual_seed(int(seed))
|
| 156 |
actual_seed = int(seed)
|
| 157 |
|
| 158 |
+
# स्टेटस मैसेज
|
| 159 |
+
status = f"""
|
| 160 |
+
🎨 **जनरेट हो रहा है...**
|
| 161 |
+
- प्रॉम्प्ट: {prompt[:80]}...
|
| 162 |
+
- साइज़: {width} x {height}
|
| 163 |
+
- स्टेप्स: {steps} | गाइडेंस: {guidance_scale}
|
| 164 |
+
- सीड: {actual_seed}
|
| 165 |
+
"""
|
| 166 |
|
| 167 |
+
print(f"\n{'='*50}")
|
| 168 |
print(f"🎨 जनरेट हो रहा है...")
|
| 169 |
+
print(f" साइज़: {width}x{height}")
|
| 170 |
+
print(f" स्टेप्स: {steps}, गाइडेंस: {guidance_scale}")
|
| 171 |
+
print(f" सीड: {actual_seed}")
|
| 172 |
|
| 173 |
try:
|
| 174 |
+
start_time = time.time()
|
| 175 |
+
|
| 176 |
result = pipe(
|
| 177 |
prompt=prompt,
|
| 178 |
negative_prompt=negative_prompt,
|
| 179 |
+
num_inference_steps=steps,
|
| 180 |
+
guidance_scale=guidance_scale,
|
| 181 |
generator=generator,
|
| 182 |
+
width=width,
|
| 183 |
+
height=height,
|
|
|
|
| 184 |
output_type="pil",
|
| 185 |
num_images_per_prompt=1
|
| 186 |
)
|
| 187 |
|
| 188 |
+
end_time = time.time()
|
| 189 |
+
gen_time = round(end_time - start_time, 1)
|
| 190 |
+
|
| 191 |
+
success_msg = f"""
|
| 192 |
+
✅ **इमेज जनरेट हो गई!**
|
| 193 |
+
- समय: {gen_time} सेकंड
|
| 194 |
+
- साइज़: {width} x {height}
|
| 195 |
+
- सीड: {actual_seed}
|
| 196 |
+
{size_warning}
|
| 197 |
+
"""
|
| 198 |
+
|
| 199 |
+
print(f"✅ इमेज {gen_time} सेकंड में जनरेट हुई!")
|
| 200 |
+
|
| 201 |
+
return result.images[0], success_msg
|
| 202 |
|
| 203 |
except Exception as e:
|
| 204 |
+
error_msg = f"❌ एरर: {str(e)[:200]}..."
|
| 205 |
print(f"❌ एरर: {e}")
|
| 206 |
+
return None, error_msg
|
|
|
|
|
|
|
| 207 |
|
| 208 |
# ============================================
|
| 209 |
# Gradio UI
|
| 210 |
# ============================================
|
| 211 |
|
| 212 |
+
with gr.Blocks(
|
| 213 |
+
title="AI Image Generator - Custom Sizes & Quality",
|
| 214 |
+
theme=gr.themes.Soft()
|
| 215 |
+
) as demo:
|
| 216 |
|
| 217 |
gr.Markdown("""
|
| 218 |
+
# 🎨 AI इमेज जनरेटर - कस्टम साइज़ और क्वालिटी
|
| 219 |
|
| 220 |
+
**किसी भी सोशल मीडिया प्लेटफॉर्म के लिए परफेक्ट साइज़ की इमेज बनाएं!**
|
| 221 |
""")
|
| 222 |
|
| 223 |
with gr.Row():
|
| 224 |
+
# ===== बायां कॉलम - इनपुट =====
|
| 225 |
+
with gr.Column(scale=2):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
|
| 227 |
+
# प्रॉम्प्ट सेक्शन
|
| 228 |
+
with gr.Group():
|
| 229 |
+
gr.Markdown("### 📝 प्रॉम्प्ट")
|
| 230 |
+
prompt = gr.Textbox(
|
| 231 |
+
label="आप क्या बनाना चाहते हैं?",
|
| 232 |
+
placeholder="जैसे: beautiful sunset over mountains, golden hour...",
|
| 233 |
+
value="beautiful sunset over mountains, golden hour, ocean view",
|
| 234 |
+
lines=3,
|
| 235 |
+
show_label=False
|
| 236 |
+
)
|
| 237 |
+
|
| 238 |
+
enhance_prompt = gr.Checkbox(
|
| 239 |
+
label="✨ प्रॉम्प्ट ऑटो-एन्हांस करें (RAW photo, 8k, cinematic जोड़ें)",
|
| 240 |
+
value=True
|
| 241 |
+
)
|
| 242 |
+
|
| 243 |
+
negative_prompt = gr.Textbox(
|
| 244 |
+
label="🚫 नेगेटिव प्रॉम्प्ट (क्या नहीं चाहिए)",
|
| 245 |
+
value="cartoon, anime, illustration, painting, drawing, blurry, low quality, ugly, bad anatomy",
|
| 246 |
+
lines=2
|
| 247 |
+
)
|
| 248 |
+
|
| 249 |
+
# प्लेटफॉर्म और साइज़ सेक्शन
|
| 250 |
+
with gr.Group():
|
| 251 |
+
gr.Markdown("### 📐 प्लेटफॉर्म और साइज़")
|
| 252 |
+
|
| 253 |
+
platform_choice = gr.Dropdown(
|
| 254 |
+
choices=list(PLATFORM_PRESETS.keys()),
|
| 255 |
+
value="🎨 Square (1:1)",
|
| 256 |
+
label="📱 प्लेटफॉर्म चुनें",
|
| 257 |
+
info="सोशल मीडिया प्लेटफॉर्म के हिसाब से ऑटो-साइज़"
|
| 258 |
+
)
|
| 259 |
+
|
| 260 |
+
with gr.Row():
|
| 261 |
+
custom_width = gr.Number(
|
| 262 |
+
label="चौड़ाई (px)",
|
| 263 |
+
value=512,
|
| 264 |
+
minimum=256,
|
| 265 |
+
maximum=2048,
|
| 266 |
+
step=64,
|
| 267 |
+
interactive=True
|
| 268 |
+
)
|
| 269 |
+
custom_height = gr.Number(
|
| 270 |
+
label="ऊंचाई (px)",
|
| 271 |
+
value=512,
|
| 272 |
+
minimum=256,
|
| 273 |
+
maximum=2048,
|
| 274 |
+
step=64,
|
| 275 |
+
interactive=True
|
| 276 |
+
)
|
| 277 |
|
| 278 |
+
# क्वालिटी सेक्शन
|
| 279 |
+
with gr.Group():
|
| 280 |
+
gr.Markdown("### ⚙️ क्वालिटी सेटिंग्स")
|
| 281 |
+
|
| 282 |
+
quality_choice = gr.Dropdown(
|
| 283 |
+
choices=list(QUALITY_PRESETS.keys()),
|
| 284 |
+
value="🚀 Fast (Good)",
|
| 285 |
+
label="🎯 क्वालिटी प्रीसेट",
|
| 286 |
+
info="तेज़ = कम समय, बेहतर = ज़्यादा डिटेल"
|
| 287 |
+
)
|
| 288 |
+
|
| 289 |
+
with gr.Row():
|
| 290 |
+
custom_steps = gr.Slider(
|
| 291 |
+
label="🔢 स्टेप्स",
|
| 292 |
+
minimum=1,
|
| 293 |
+
maximum=12,
|
| 294 |
+
value=4,
|
| 295 |
+
step=1,
|
| 296 |
+
interactive=True
|
| 297 |
+
)
|
| 298 |
+
custom_guidance = gr.Slider(
|
| 299 |
+
label="🎯 गाइडेंस स्केल",
|
| 300 |
+
minimum=0.5,
|
| 301 |
+
maximum=2.0,
|
| 302 |
+
value=1.0,
|
| 303 |
+
step=0.1,
|
| 304 |
+
interactive=True
|
| 305 |
+
)
|
| 306 |
+
|
| 307 |
+
# सीड और जनरेट बटन
|
| 308 |
with gr.Row():
|
| 309 |
+
seed = gr.Number(
|
| 310 |
+
label="🎲 सीड (-1 = रैंडम)",
|
| 311 |
+
value=-1,
|
| 312 |
+
precision=0
|
| 313 |
)
|
| 314 |
|
| 315 |
+
generate_btn = gr.Button(
|
| 316 |
+
"✨ इमेज जनरेट करें",
|
| 317 |
+
variant="primary",
|
| 318 |
+
size="lg",
|
| 319 |
+
scale=2
|
| 320 |
)
|
| 321 |
+
|
| 322 |
+
# ===== दायां कॉलम - आउटपुट =====
|
| 323 |
+
with gr.Column(scale=1):
|
| 324 |
+
output_image = gr.Image(
|
| 325 |
+
label="जनरेटेड इमेज",
|
| 326 |
+
height=400,
|
| 327 |
+
show_label=True
|
| 328 |
+
)
|
| 329 |
|
| 330 |
+
status_text = gr.Markdown(
|
| 331 |
+
"👆 ऊपर सेटिंग्स चुनें और जनरेट करें"
|
|
|
|
|
|
|
| 332 |
)
|
| 333 |
|
| 334 |
+
with gr.Accordion("📊 परफॉरमेंस गाइड", open=False):
|
| 335 |
+
gr.Markdown("""
|
| 336 |
+
| क्वालिटी | स्टेप्स | CPU समय | कब इस्तेमाल करें |
|
| 337 |
+
|:---|:---:|:---:|:---|
|
| 338 |
+
| Ultra Fast | 2 | 5-8s | आइडिया टेस्टिंग |
|
| 339 |
+
| Fast | 4 | 10-15s | सोशल मीडिया पोस्ट |
|
| 340 |
+
| Balanced | 6 | 15-25s | ब्लॉग/वेबसाइट |
|
| 341 |
+
| High Quality | 8 | 25-40s | प्रिंट/पोस्टर |
|
| 342 |
+
""")
|
| 343 |
+
|
| 344 |
+
with gr.Accordion("💡 टिप्स", open=False):
|
| 345 |
+
gr.Markdown("""
|
| 346 |
+
- **प्रॉम्प्ट टिप**: "RAW photo", "hyperrealistic", "8k" जोड़ें
|
| 347 |
+
- **नेगेटिव टिप**: "cartoon, anime, blurry" हमेशा रखें
|
| 348 |
+
- **साइज़ टिप**: 1024px से बड़ी इमेज में ज़्यादा समय लगेगा
|
| 349 |
+
- **सीड टिप**: एक ही सीड से एक जैसी इमेज बनेगी
|
| 350 |
+
""")
|
| 351 |
+
|
| 352 |
+
# ===== इवेंट हैंडलर्स =====
|
| 353 |
+
|
| 354 |
+
def on_platform_change(choice):
|
| 355 |
+
"""प्लेटफॉर्म बदलने पर साइज़ अपडेट करें"""
|
| 356 |
+
w, h = update_size_from_preset(choice)
|
| 357 |
+
return w, h, choice == "✏️ Custom Size"
|
| 358 |
+
|
| 359 |
+
platform_choice.change(
|
| 360 |
+
fn=on_platform_change,
|
| 361 |
+
inputs=[platform_choice],
|
| 362 |
+
outputs=[custom_width, custom_height, gr.Checkbox(visible=False)]
|
| 363 |
+
).then(
|
| 364 |
+
fn=lambda x: x == "✏️ Custom Size",
|
| 365 |
+
inputs=[platform_choice],
|
| 366 |
+
outputs=[custom_width]
|
| 367 |
+
)
|
| 368 |
+
|
| 369 |
+
def on_quality_change(choice):
|
| 370 |
+
"""क्वालिटी बदलने पर steps और guidance अपडेट करें"""
|
| 371 |
+
s, g = update_quality_from_preset(choice)
|
| 372 |
+
is_custom = (choice == "🔬 Custom")
|
| 373 |
+
return s, g, is_custom, is_custom
|
| 374 |
|
| 375 |
+
quality_choice.change(
|
| 376 |
+
fn=on_quality_change,
|
| 377 |
+
inputs=[quality_choice],
|
| 378 |
+
outputs=[custom_steps, custom_guidance, custom_steps, custom_guidance]
|
| 379 |
+
)
|
| 380 |
+
|
| 381 |
+
# जनरेट बटन
|
| 382 |
+
generate_btn.click(
|
| 383 |
fn=generate_image,
|
| 384 |
+
inputs=[
|
| 385 |
+
prompt, negative_prompt,
|
| 386 |
+
platform_choice, quality_choice,
|
| 387 |
+
custom_width, custom_height,
|
| 388 |
+
custom_steps, custom_guidance,
|
| 389 |
+
seed, enhance_prompt
|
| 390 |
+
],
|
| 391 |
+
outputs=[output_image, status_text]
|
| 392 |
)
|
| 393 |
|
| 394 |
+
# ===== उदाहरण =====
|
| 395 |
+
gr.Markdown("### 📋 तुरंत ट्राई करें")
|
| 396 |
+
|
| 397 |
gr.Examples(
|
| 398 |
examples=[
|
| 399 |
+
["RAW photo, red Ferrari on coastal highway, sunset", "cartoon, anime, blurry", "📱 Instagram Post (Square)", "🚀 Fast (Good)", 1080, 1080, 4, 1.0, 42, True],
|
| 400 |
+
["cute golden retriever puppy in flower garden", "cartoon, drawing, ugly", "📌 Pinterest Pin", "🎯 Balanced (Better)", 1000, 1500, 6, 1.2, 123, True],
|
| 401 |
+
["astronaut floating in space, earth background", "cartoon, 3d render", "📺 YouTube Thumbnail", "🚀 Fast (Good)", 1280, 720, 4, 1.0, 456, True],
|
| 402 |
+
["Indian bride in red lehenga, golden jewelry", "cartoon, illustration, deformed", "📱 Instagram Story", "💎 High Quality (Best)", 1080, 1920, 8, 1.5, 789, True],
|
| 403 |
],
|
| 404 |
+
inputs=[prompt, negative_prompt, platform_choice, quality_choice, custom_width, custom_height, custom_steps, custom_guidance, seed, enhance_prompt],
|
| 405 |
+
label=""
|
| 406 |
)
|
| 407 |
|
| 408 |
+
# ============================================
|
| 409 |
+
# ऐप लॉन्च
|
| 410 |
+
# ============================================
|
| 411 |
+
|
| 412 |
if __name__ == "__main__":
|
| 413 |
+
print("=" * 50)
|
| 414 |
+
print("🚀 AI इमेज जनरेटर - कस्टम साइज़ और क्वालिटी")
|
| 415 |
+
print("=" * 50)
|
| 416 |
+
demo.queue(max_size=5).launch(show_error=True)
|