Update app.py
Browse files
app.py
CHANGED
|
@@ -6,9 +6,10 @@ import urllib.parse
|
|
| 6 |
from io import BytesIO
|
| 7 |
from PIL import Image
|
| 8 |
from gradio_client import Client
|
|
|
|
| 9 |
|
| 10 |
# ==========================================
|
| 11 |
-
# 1. API Keys
|
| 12 |
# ==========================================
|
| 13 |
KEYS = {
|
| 14 |
"segmind": "SG_8d03bc9ab924555c",
|
|
@@ -16,62 +17,60 @@ KEYS = {
|
|
| 16 |
"google": "AIzaSyBdEqDB6SFI2uQ-5FBr-cCeRj-dkiv8pFY",
|
| 17 |
"stablehorde": "56kkbwcSPfHIr2YsDkpNDQ",
|
| 18 |
"modelslab": "42zL3I6pH7Mv94jhNf4RGyuKGGT3GoEhfXZv47WwmQsfyhgC8XNttfOpvMKL",
|
| 19 |
-
|
| 20 |
-
# ⚠️ তোমার Hugging Face Token এখানে দিতে ভুলবে না (স্লো বা HF API গুলোর জন্য এটি মাস্ট)
|
| 21 |
-
"huggingface": "hf_xxxxxxxxxxxxxxxxxxxxxxxxx"
|
| 22 |
}
|
| 23 |
|
| 24 |
HEADERS_DEFAULT = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"}
|
| 25 |
|
| 26 |
def get_image_from_url(url):
|
| 27 |
-
res = requests.get(url, headers=HEADERS_DEFAULT)
|
| 28 |
if res.status_code == 200: return Image.open(BytesIO(res.content))
|
| 29 |
-
raise Exception(
|
| 30 |
|
| 31 |
# ==========================================
|
| 32 |
# 2. Core API Functions (10 Main Servers)
|
| 33 |
# ==========================================
|
| 34 |
def generate_hercai(p, w, h, ar):
|
| 35 |
url = f"https://hercai.onrender.com/v3/text2image?prompt={urllib.parse.quote(p)}"
|
| 36 |
-
res = requests.get(url, headers=HEADERS_DEFAULT)
|
| 37 |
if res.status_code == 200: return get_image_from_url(res.json().get("url"))
|
| 38 |
-
raise Exception("
|
| 39 |
|
| 40 |
def generate_pollinations(p, w, h, ar):
|
| 41 |
url = f"https://image.pollinations.ai/prompt/{urllib.parse.quote(p)}?width={w}&height={h}&nologo=true"
|
| 42 |
-
res = requests.get(url, headers=HEADERS_DEFAULT)
|
| 43 |
if res.status_code == 200: return Image.open(BytesIO(res.content))
|
| 44 |
-
raise Exception("
|
| 45 |
|
| 46 |
def generate_google_imagen(p, w, h, ar):
|
| 47 |
-
res = requests.post(f"https://generativelanguage.googleapis.com/v1beta/models/imagen-3.0-generate-001:predict?key={KEYS['google']}", json={"instances": [{"prompt": p}]})
|
| 48 |
if res.status_code == 200: return Image.open(BytesIO(base64.b64decode(res.json()['predictions'][0]['bytesBase64Encoded'])))
|
| 49 |
-
raise Exception("
|
| 50 |
|
| 51 |
def generate_segmind(p, w, h, ar):
|
| 52 |
-
res = requests.post("https://api.segmind.com/v1/sdxl1.0-txt2img", headers={"x-api-key": KEYS['segmind']}, json={"prompt": p, "samples": 1, "width": w, "height": h})
|
| 53 |
if res.status_code == 200: return Image.open(BytesIO(res.content))
|
| 54 |
-
raise Exception("
|
| 55 |
|
| 56 |
def generate_getimg(p, w, h, ar):
|
| 57 |
-
res = requests.post("https://api.getimg.ai/v1/essential/text-to-image", headers={"Authorization": f"Bearer {KEYS['getimg']}"}, json={"prompt": p, "width": w, "height": h})
|
| 58 |
if res.status_code == 200: return Image.open(BytesIO(base64.b64decode(res.json()["image"])))
|
| 59 |
-
raise Exception("
|
| 60 |
|
| 61 |
def generate_modelslab(p, w, h, ar):
|
| 62 |
-
res = requests.post("https://modelslab.com/api/v6/images/text2img", json={"key": KEYS['modelslab'], "prompt": p, "width": str(w), "height": str(h)})
|
| 63 |
if res.status_code == 200 and "output" in res.json(): return get_image_from_url(res.json()["output"][0])
|
| 64 |
-
raise Exception("
|
| 65 |
|
| 66 |
def generate_stable_horde(p, w, h, ar):
|
| 67 |
-
res = requests.post("https://stablehorde.net/api/v2/generate/async", headers={"apikey": KEYS['stablehorde']}, json={"prompt": p, "params": {"n": 1, "width": 512, "height": 512}})
|
| 68 |
if res.status_code == 202:
|
| 69 |
job_id = res.json()['id']
|
| 70 |
-
for _ in range(
|
| 71 |
time.sleep(2)
|
| 72 |
-
check = requests.get(f"https://stablehorde.net/api/v2/generate/status/{job_id}")
|
| 73 |
if check.status_code == 200 and check.json().get("done", False): return get_image_from_url(check.json()['generations'][0]['img'])
|
| 74 |
-
raise Exception("
|
| 75 |
|
| 76 |
def generate_hf_flux(p, w, h, ar):
|
| 77 |
client = Client("black-forest-labs/FLUX.1-schnell")
|
|
@@ -92,17 +91,16 @@ def generate_hf_api(prompt, model_id, w, h):
|
|
| 92 |
url = f"https://api-inference.huggingface.co/models/{model_id}"
|
| 93 |
headers = {"Authorization": f"Bearer {KEYS['huggingface']}"} if KEYS.get('huggingface') and KEYS['huggingface'] != "hf_xxxxxxxxxxxxxxxxxxxxxxxxx" else {}
|
| 94 |
payload = {"inputs": prompt, "parameters": {"width": w, "height": h}}
|
| 95 |
-
res = requests.post(url, headers=headers, json=payload)
|
| 96 |
if res.status_code != 200:
|
| 97 |
-
res = requests.post(url, headers=headers, json={"inputs": prompt})
|
| 98 |
if res.status_code == 200: return Image.open(BytesIO(res.content))
|
| 99 |
-
raise Exception("
|
| 100 |
|
| 101 |
# ==========================================
|
| 102 |
-
# 3. MEGA API DICTIONARY (Exactly
|
| 103 |
# ==========================================
|
| 104 |
ALL_APIS = {
|
| 105 |
-
# ১০টি কোর এবং আনলিমিটেড সার্ভার (এগুলো সবচেয়ে ফাস্ট কাজ করবে)
|
| 106 |
"Pollinations AI (Unlimited)": generate_pollinations,
|
| 107 |
"Hercai AI (Unlimited)": generate_hercai,
|
| 108 |
"Google Imagen (Daily)": generate_google_imagen,
|
|
@@ -115,111 +113,87 @@ ALL_APIS = {
|
|
| 115 |
"HF Space: SD3.5": generate_hf_sd3,
|
| 116 |
}
|
| 117 |
|
| 118 |
-
# ৯০টি বেস্ট Hugging Face মডেল
|
| 119 |
-
hf_models_list =
|
| 120 |
-
"
|
| 121 |
-
"
|
| 122 |
-
"
|
| 123 |
-
"
|
| 124 |
-
"
|
| 125 |
-
"
|
| 126 |
-
"
|
| 127 |
-
"
|
| 128 |
-
"
|
| 129 |
-
"
|
| 130 |
-
"
|
| 131 |
-
"
|
| 132 |
-
"
|
| 133 |
-
"
|
| 134 |
-
"
|
| 135 |
-
"
|
| 136 |
-
"
|
| 137 |
-
"
|
| 138 |
-
"
|
| 139 |
-
"
|
| 140 |
-
"
|
| 141 |
-
"
|
| 142 |
-
"
|
| 143 |
-
"
|
| 144 |
-
"
|
| 145 |
-
"
|
| 146 |
-
"
|
| 147 |
-
"
|
| 148 |
-
"
|
| 149 |
-
"
|
| 150 |
-
|
| 151 |
-
"
|
| 152 |
-
"
|
| 153 |
-
"
|
| 154 |
-
"
|
| 155 |
-
"
|
| 156 |
-
"
|
| 157 |
-
"
|
| 158 |
-
"
|
| 159 |
-
"
|
| 160 |
-
"
|
| 161 |
-
"
|
| 162 |
-
"
|
| 163 |
-
"
|
| 164 |
-
"
|
| 165 |
-
"
|
| 166 |
-
"
|
| 167 |
-
"
|
| 168 |
-
"
|
| 169 |
-
"
|
| 170 |
-
"
|
| 171 |
-
"
|
| 172 |
-
"
|
| 173 |
-
"
|
| 174 |
-
"
|
| 175 |
-
"
|
| 176 |
-
"
|
| 177 |
-
"
|
| 178 |
-
"
|
| 179 |
-
"
|
| 180 |
-
"
|
| 181 |
-
|
| 182 |
-
"HF: Chilled Re-Generic": "stablediffusionapi/chilled-re-generic",
|
| 183 |
-
"HF: Children's 3D": "stablediffusionapi/childrens-stories-3d",
|
| 184 |
-
"HF: Complex Lineart": "stablediffusionapi/complex-lineart",
|
| 185 |
-
"HF: Dark Victorian": "stablediffusionapi/dark-victorian-style",
|
| 186 |
-
"HF: Dreamshaper V6": "stablediffusionapi/dreamshaper-v6",
|
| 187 |
-
"HF: DucHaiten AI Art": "stablediffusionapi/duchaiten-aiart",
|
| 188 |
-
"HF: DVArch": "stablediffusionapi/dvarch",
|
| 189 |
-
"HF: Fantasy World": "stablediffusionapi/fantasy-world",
|
| 190 |
-
"HF: Grapefruit Anime": "stablediffusionapi/grapefruit",
|
| 191 |
-
"HF: Guweiz Style": "stablediffusionapi/guweiz-style",
|
| 192 |
-
"HF: Hassaku Anime": "stablediffusionapi/hassaku-hentai-model",
|
| 193 |
-
"HF: MajicMix Realistic": "stablediffusionapi/majicmix-realistic",
|
| 194 |
-
"HF: MeinaMix V9": "stablediffusionapi/meinamix-v9",
|
| 195 |
-
"HF: Meina Unreal": "stablediffusionapi/meina-unreal",
|
| 196 |
-
"HF: Meina Pastel": "stablediffusionapi/meina-pastel",
|
| 197 |
-
"HF: MoXin Chinese Art": "stablediffusionapi/moxin",
|
| 198 |
-
"HF: Pastel Mix Stylized": "stablediffusionapi/pastel-mix-stylized-anime",
|
| 199 |
-
"HF: Perfect World": "stablediffusionapi/perfect-world",
|
| 200 |
-
"HF: Portrait Plus": "stablediffusionapi/portrait-plus",
|
| 201 |
-
"HF: Realistic Vision V2": "stablediffusionapi/realistic-vision-v20",
|
| 202 |
-
"HF: Realistic Vision V4": "stablediffusionapi/realistic-vision-v40",
|
| 203 |
-
"HF: Beautiful People": "stablediffusionapi/shonin-beautiful-people",
|
| 204 |
-
"HF: Synthwave Punk": "stablediffusionapi/synthwave-punk-v2",
|
| 205 |
-
"HF: The Ally's Mix III": "stablediffusionapi/the-allys-mix-iii",
|
| 206 |
-
"HF: ToonYou": "stablediffusionapi/toonyou",
|
| 207 |
-
"HF: Vintedois Diffusion": "stablediffusionapi/vintedois-diffusion",
|
| 208 |
-
"HF: Waifu Diffusion V1.4": "stablediffusionapi/waifu-diffusion-v14",
|
| 209 |
-
"HF: Small SD": "OFA-Sys/small-stable-diffusion-v0"
|
| 210 |
-
}
|
| 211 |
|
| 212 |
-
# ফাংশন জেনারেটর (কোড ছোট রাখার জন্য)
|
| 213 |
def make_hf_func(model_id):
|
| 214 |
return lambda p, w, h, ar: generate_hf_api(p, model_id, w, h)
|
| 215 |
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
ALL_APIS[name] = make_hf_func(model_id)
|
| 219 |
|
| 220 |
# ==========================================
|
| 221 |
-
# 4.
|
| 222 |
# ==========================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
def generate_image_logic(prompt, style, size, selected_api):
|
| 224 |
if not prompt.strip():
|
| 225 |
yield None, "⚠️ **দয়া করে একটি প্রম্পট লিখুন!**"
|
|
@@ -237,29 +211,45 @@ def generate_image_logic(prompt, style, size, selected_api):
|
|
| 237 |
}
|
| 238 |
enhanced_prompt = f"{prompt.strip()}{style_modifiers.get(style, '')}, aspect ratio {ar}"
|
| 239 |
|
| 240 |
-
# অটোমেটিক মোড: ১০
|
| 241 |
if selected_api == "অটোমেটিক (Auto Fallback)":
|
| 242 |
-
|
|
|
|
| 243 |
|
| 244 |
-
for
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 255 |
|
| 256 |
-
# ম্যানুয়াল মোড
|
| 257 |
else:
|
| 258 |
yield None, f"⏳ শুধুমাত্র **{selected_api}**-এ কল করা হচ্ছে..."
|
| 259 |
api_func = ALL_APIS[selected_api]
|
| 260 |
try:
|
| 261 |
image = api_func(enhanced_prompt, w, h, ar)
|
| 262 |
-
if image: yield image, f"✅ **সফল!** আপনি ম্যানুয়ালি {selected_api} ব্যবহার করেছেন।"
|
| 263 |
else: yield None, f"❌ **দুঃখিত!** {selected_api} বর্তমানে ডাউন।"
|
| 264 |
except Exception as e:
|
| 265 |
yield None, f"❌ **দুঃখিত!** ব্যর্থ হয়েছে। অন্য একটি সার্ভার ট্রাই করুন।"
|
|
@@ -270,7 +260,7 @@ def generate_image_logic(prompt, style, size, selected_api):
|
|
| 270 |
api_choices = ["অটোমেটিক (Auto Fallback)"] + list(ALL_APIS.keys())
|
| 271 |
|
| 272 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 273 |
-
gr.Markdown("<h1 style='text-align: center;'>🎨
|
| 274 |
|
| 275 |
with gr.Row():
|
| 276 |
with gr.Column(scale=1):
|
|
@@ -286,7 +276,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 286 |
label="ছবির সাইজ (Size)", value="স্কয়ার (1:1) - Instagram"
|
| 287 |
)
|
| 288 |
|
| 289 |
-
# ড্রপডাউন মেনুতে এখন ১০০টি অপশন থাকবে
|
| 290 |
api_selector = gr.Dropdown(
|
| 291 |
choices=api_choices, label="সার্ভার সিলেক্ট করুন (ডিফল্ট: অটোমেটিক)", value="অটোমেটিক (Auto Fallback)", interactive=True
|
| 292 |
)
|
|
@@ -295,7 +284,8 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 295 |
log_box = gr.Markdown("স্ট্যাটাস: অপেক্ষমান...")
|
| 296 |
|
| 297 |
with gr.Column(scale=1):
|
| 298 |
-
|
|
|
|
| 299 |
|
| 300 |
generate_btn.click(
|
| 301 |
fn=generate_image_logic,
|
|
@@ -303,5 +293,8 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 303 |
outputs=[image_output, log_box]
|
| 304 |
)
|
| 305 |
|
|
|
|
|
|
|
|
|
|
| 306 |
if __name__ == "__main__":
|
| 307 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 6 |
from io import BytesIO
|
| 7 |
from PIL import Image
|
| 8 |
from gradio_client import Client
|
| 9 |
+
import concurrent.futures # একসাথে ১০টা কল করার জন্য
|
| 10 |
|
| 11 |
# ==========================================
|
| 12 |
+
# 1. API Keys
|
| 13 |
# ==========================================
|
| 14 |
KEYS = {
|
| 15 |
"segmind": "SG_8d03bc9ab924555c",
|
|
|
|
| 17 |
"google": "AIzaSyBdEqDB6SFI2uQ-5FBr-cCeRj-dkiv8pFY",
|
| 18 |
"stablehorde": "56kkbwcSPfHIr2YsDkpNDQ",
|
| 19 |
"modelslab": "42zL3I6pH7Mv94jhNf4RGyuKGGT3GoEhfXZv47WwmQsfyhgC8XNttfOpvMKL",
|
| 20 |
+
"huggingface": "hf_xxxxxxxxxxxxxxxxxxxxxxxxx" # ⚠️ তোমার HF Token এখানে দিও
|
|
|
|
|
|
|
| 21 |
}
|
| 22 |
|
| 23 |
HEADERS_DEFAULT = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"}
|
| 24 |
|
| 25 |
def get_image_from_url(url):
|
| 26 |
+
res = requests.get(url, headers=HEADERS_DEFAULT, timeout=15)
|
| 27 |
if res.status_code == 200: return Image.open(BytesIO(res.content))
|
| 28 |
+
raise Exception("Image load failed")
|
| 29 |
|
| 30 |
# ==========================================
|
| 31 |
# 2. Core API Functions (10 Main Servers)
|
| 32 |
# ==========================================
|
| 33 |
def generate_hercai(p, w, h, ar):
|
| 34 |
url = f"https://hercai.onrender.com/v3/text2image?prompt={urllib.parse.quote(p)}"
|
| 35 |
+
res = requests.get(url, headers=HEADERS_DEFAULT, timeout=20)
|
| 36 |
if res.status_code == 200: return get_image_from_url(res.json().get("url"))
|
| 37 |
+
raise Exception("Error")
|
| 38 |
|
| 39 |
def generate_pollinations(p, w, h, ar):
|
| 40 |
url = f"https://image.pollinations.ai/prompt/{urllib.parse.quote(p)}?width={w}&height={h}&nologo=true"
|
| 41 |
+
res = requests.get(url, headers=HEADERS_DEFAULT, timeout=20)
|
| 42 |
if res.status_code == 200: return Image.open(BytesIO(res.content))
|
| 43 |
+
raise Exception("Error")
|
| 44 |
|
| 45 |
def generate_google_imagen(p, w, h, ar):
|
| 46 |
+
res = requests.post(f"https://generativelanguage.googleapis.com/v1beta/models/imagen-3.0-generate-001:predict?key={KEYS['google']}", json={"instances": [{"prompt": p}]}, timeout=20)
|
| 47 |
if res.status_code == 200: return Image.open(BytesIO(base64.b64decode(res.json()['predictions'][0]['bytesBase64Encoded'])))
|
| 48 |
+
raise Exception("Error")
|
| 49 |
|
| 50 |
def generate_segmind(p, w, h, ar):
|
| 51 |
+
res = requests.post("https://api.segmind.com/v1/sdxl1.0-txt2img", headers={"x-api-key": KEYS['segmind']}, json={"prompt": p, "samples": 1, "width": w, "height": h}, timeout=20)
|
| 52 |
if res.status_code == 200: return Image.open(BytesIO(res.content))
|
| 53 |
+
raise Exception("Error")
|
| 54 |
|
| 55 |
def generate_getimg(p, w, h, ar):
|
| 56 |
+
res = requests.post("https://api.getimg.ai/v1/essential/text-to-image", headers={"Authorization": f"Bearer {KEYS['getimg']}"}, json={"prompt": p, "width": w, "height": h}, timeout=20)
|
| 57 |
if res.status_code == 200: return Image.open(BytesIO(base64.b64decode(res.json()["image"])))
|
| 58 |
+
raise Exception("Error")
|
| 59 |
|
| 60 |
def generate_modelslab(p, w, h, ar):
|
| 61 |
+
res = requests.post("https://modelslab.com/api/v6/images/text2img", json={"key": KEYS['modelslab'], "prompt": p, "width": str(w), "height": str(h)}, timeout=20)
|
| 62 |
if res.status_code == 200 and "output" in res.json(): return get_image_from_url(res.json()["output"][0])
|
| 63 |
+
raise Exception("Error")
|
| 64 |
|
| 65 |
def generate_stable_horde(p, w, h, ar):
|
| 66 |
+
res = requests.post("https://stablehorde.net/api/v2/generate/async", headers={"apikey": KEYS['stablehorde']}, json={"prompt": p, "params": {"n": 1, "width": 512, "height": 512}}, timeout=10)
|
| 67 |
if res.status_code == 202:
|
| 68 |
job_id = res.json()['id']
|
| 69 |
+
for _ in range(10): # সর্বোচ্চ ২০ সেকেন্ড অপেক্ষা করবে
|
| 70 |
time.sleep(2)
|
| 71 |
+
check = requests.get(f"https://stablehorde.net/api/v2/generate/status/{job_id}", timeout=10)
|
| 72 |
if check.status_code == 200 and check.json().get("done", False): return get_image_from_url(check.json()['generations'][0]['img'])
|
| 73 |
+
raise Exception("Error")
|
| 74 |
|
| 75 |
def generate_hf_flux(p, w, h, ar):
|
| 76 |
client = Client("black-forest-labs/FLUX.1-schnell")
|
|
|
|
| 91 |
url = f"https://api-inference.huggingface.co/models/{model_id}"
|
| 92 |
headers = {"Authorization": f"Bearer {KEYS['huggingface']}"} if KEYS.get('huggingface') and KEYS['huggingface'] != "hf_xxxxxxxxxxxxxxxxxxxxxxxxx" else {}
|
| 93 |
payload = {"inputs": prompt, "parameters": {"width": w, "height": h}}
|
| 94 |
+
res = requests.post(url, headers=headers, json=payload, timeout=25)
|
| 95 |
if res.status_code != 200:
|
| 96 |
+
res = requests.post(url, headers=headers, json={"inputs": prompt}, timeout=25)
|
| 97 |
if res.status_code == 200: return Image.open(BytesIO(res.content))
|
| 98 |
+
raise Exception("Error")
|
| 99 |
|
| 100 |
# ==========================================
|
| 101 |
+
# 3. MEGA API DICTIONARY (Exactly 200 Servers)
|
| 102 |
# ==========================================
|
| 103 |
ALL_APIS = {
|
|
|
|
| 104 |
"Pollinations AI (Unlimited)": generate_pollinations,
|
| 105 |
"Hercai AI (Unlimited)": generate_hercai,
|
| 106 |
"Google Imagen (Daily)": generate_google_imagen,
|
|
|
|
| 113 |
"HF Space: SD3.5": generate_hf_sd3,
|
| 114 |
}
|
| 115 |
|
| 116 |
+
# ১৯০টি বেস্ট Hugging Face মডেল
|
| 117 |
+
hf_models_list = [
|
| 118 |
+
("DreamShaper XL", "Lykon/dreamshaper-xl-1.0"), ("RealVisXL V4.0", "SG161222/RealVisXL_V4.0"), ("OpenJourney", "prompthero/openjourney"),
|
| 119 |
+
("Midjourney V4", "prompthero/midjourney-v4-diffusion"), ("Animagine XL 3.1", "cagliostrolab/animagine-xl-3.1"), ("Playground v2.5", "playgroundai/playground-v2.5-1024px-aesthetic"),
|
| 120 |
+
("Realistic Vision V5", "SG161222/Realistic_Vision_V5.1_noVAE"), ("Anything V5", "stablediffusionapi/anything-v5"), ("Anything V4", "andite/anything-v4.0"),
|
| 121 |
+
("Anything V3", "Linaqruf/anything-v3.0"), ("Waifu Diffusion", "hakurei/waifu-diffusion"), ("Disney Pixar", "stablediffusionapi/disney-pixar-cartoon"),
|
| 122 |
+
("CyberRealistic", "stablediffusionapi/cyberrealistic"), ("Absolute Reality", "stablediffusionapi/absolute-reality-v181"), ("Juggernaut XL", "stablediffusionapi/juggernaut-xl-v5"),
|
| 123 |
+
("SDXL Base 1.0", "stabilityai/stable-diffusion-xl-base-1.0"), ("Stable Diffusion 1.5", "runwayml/stable-diffusion-v1-5"), ("Stable Diffusion 1.4", "CompVis/stable-diffusion-v1-4"),
|
| 124 |
+
("Stable Diffusion 2.1", "stabilityai/stable-diffusion-2-1"), ("EpicRealism", "emilianJR/epiCRealism"), ("Deliberate", "XpucT/Deliberate"),
|
| 125 |
+
("MeinaMix V11", "Meina/MeinaMix_V11"), ("DreamShaper 8", "Lykon/dreamshaper-8"), ("GhostMix", "GhostMix/GhostMix-V2.0"),
|
| 126 |
+
("Pastel-Mix", "andite/pastel-mix"), ("Protogen x3.4", "darkstorm2150/Protogen_x3.4_Official_Release"), ("RevAnimated", "stablediffusionapi/rev-animated"),
|
| 127 |
+
("Comic Babes", "stablediffusionapi/comic-babes"), ("3D Animation Style", "stablediffusionapi/3d-animation-style"), ("NeverEnding Dream", "stablediffusionapi/neverending-dream"),
|
| 128 |
+
("Reliberate", "stablediffusionapi/reliberate"), ("Edge of Realism", "stablediffusionapi/edge-of-realism"), ("AOM3", "stablediffusionapi/abyssorangemix3"),
|
| 129 |
+
("AnyLoRA", "stablediffusionapi/anylora"), ("Counterfeit V3", "stablediffusionapi/counterfeit-v30"), ("Dark Sushi Mix", "stablediffusionapi/dark-sushi-mix"),
|
| 130 |
+
("Photoreal 2.0", "dreamlike-art/dreamlike-photoreal-2.0"), ("Dreamlike Anime", "dreamlike-art/dreamlike-anime-1.0"), ("Dreamlike Diffusion", "dreamlike-art/dreamlike-diffusion-1.0"),
|
| 131 |
+
("OpenDalle V1.1", "dataautogpt3/OpenDalleV1.1"), ("Nitro Diffusion", "nitrosocke/Nitro-Diffusion"), ("Arcane Diffusion", "nitrosocke/Arcane-Diffusion"),
|
| 132 |
+
("Mo-Di Diffusion", "nitrosocke/mo-di-diffusion"), ("Elden Ring", "nitrosocke/elden-ring-diffusion"), ("Spider-Verse", "nitrosocke/spider-verse-diffusion"),
|
| 133 |
+
("Analog Diffusion", "wavymulder/Analog-Diffusion"), ("PaperCut Style", "Fictiverse/Stable_Diffusion_PaperCut_Model"), ("Studio Ghibli", "nitrosocke/Ghibli-Diffusion"),
|
| 134 |
+
("Classic Animation", "nitrosocke/classic-anim-diffusion"), ("Redshift 3D", "nitrosocke/redshift-diffusion"), ("Van Gogh Style", "dallinmackay/Van-Gogh-diffusion"),
|
| 135 |
+
("Tron Legacy", "dallinmackay/Tron-Legacy-diffusion"), ("Trinart V2", "naclbit/trinart_stable_diffusion_v2"), ("Epic Diffusion", "johnslegers/epic-diffusion"),
|
| 136 |
+
("Photorealistic Fuen", "claudfuen/photorealistic-fuen-v1"), ("RPG Artist", "XpucT/RPG"), ("All 526 Animated", "stablediffusionapi/all-526-animated"),
|
| 137 |
+
("Am I Real", "stablediffusionapi/am-i-real"), ("Analog Diffusion API", "stablediffusionapi/analog-diffusion"), ("AnyGen", "stablediffusionapi/anygen"),
|
| 138 |
+
("BG Dream", "stablediffusionapi/bg-dream-dir"), ("CetusMix", "stablediffusionapi/cetusmix"), ("Chilled Re-Generic", "stablediffusionapi/chilled-re-generic"),
|
| 139 |
+
("Children's 3D", "stablediffusionapi/childrens-stories-3d"), ("Complex Lineart", "stablediffusionapi/complex-lineart"), ("Dark Victorian", "stablediffusionapi/dark-victorian-style"),
|
| 140 |
+
("Dreamshaper V6", "stablediffusionapi/dreamshaper-v6"), ("DucHaiten AI Art", "stablediffusionapi/duchaiten-aiart"), ("DVArch", "stablediffusionapi/dvarch"),
|
| 141 |
+
("Fantasy World", "stablediffusionapi/fantasy-world"), ("Grapefruit Anime", "stablediffusionapi/grapefruit"), ("Guweiz Style", "stablediffusionapi/guweiz-style"),
|
| 142 |
+
("Hassaku Anime", "stablediffusionapi/hassaku-hentai-model"), ("MajicMix Realistic", "stablediffusionapi/majicmix-realistic"), ("MeinaMix V9", "stablediffusionapi/meinamix-v9"),
|
| 143 |
+
("Meina Unreal", "stablediffusionapi/meina-unreal"), ("Meina Pastel", "stablediffusionapi/meina-pastel"), ("MoXin Chinese Art", "stablediffusionapi/moxin"),
|
| 144 |
+
("Pastel Mix Stylized", "stablediffusionapi/pastel-mix-stylized-anime"), ("Perfect World", "stablediffusionapi/perfect-world"), ("Portrait Plus", "stablediffusionapi/portrait-plus"),
|
| 145 |
+
("Realistic Vision V2", "stablediffusionapi/realistic-vision-v20"), ("Realistic Vision V4", "stablediffusionapi/realistic-vision-v40"), ("Beautiful People", "stablediffusionapi/shonin-beautiful-people"),
|
| 146 |
+
("Synthwave Punk", "stablediffusionapi/synthwave-punk-v2"), ("The Ally's Mix III", "stablediffusionapi/the-allys-mix-iii"), ("ToonYou", "stablediffusionapi/toonyou"),
|
| 147 |
+
("Vintedois", "stablediffusionapi/vintedois-diffusion"), ("Waifu Diffusion V1.4", "stablediffusionapi/waifu-diffusion-v14"), ("Small SD", "OFA-Sys/small-stable-diffusion-v0"),
|
| 148 |
+
# আরও ৯০টি (মোট ১৯০টি HF মডেল)
|
| 149 |
+
("Realistic Vision V3", "stablediffusionapi/realistic-vision-v30"), ("Realistic Vision V5.0", "stablediffusionapi/realistic-vision-v50"), ("Dreamshaper V7", "stablediffusionapi/dreamshaper-v7"),
|
| 150 |
+
("MeinaMix V10", "stablediffusionapi/meinamix-v10"), ("Blood Orange Mix", "stablediffusionapi/blood-orange-mix"), ("Abyss Orange Mix 2", "stablediffusionapi/abyssorangemix2"),
|
| 151 |
+
("Anything V4.5", "stablediffusionapi/anything-v45"), ("Anything V5 Ink", "stablediffusionapi/anything-v5-ink"), ("AZ Ovya CG Art", "stablediffusionapi/a-z-ovya-cg-art"),
|
| 152 |
+
("Art Diffusion", "stablediffusionapi/art-diffusion"), ("Asian Model", "stablediffusionapi/asian-model"), ("Beautiful Realistic Asian", "stablediffusionapi/beautiful-realistic-asian"),
|
| 153 |
+
("Chillout App", "stablediffusionapi/chillout-app-factory"), ("ChilloutMix", "stablediffusionapi/chilloutmix"), ("ChilloutMix Ni", "stablediffusionapi/chilloutmix-ni"),
|
| 154 |
+
("Cosplay Mix", "stablediffusionapi/cosplay-mix"), ("Cyberpunk Anime 2", "stablediffusionapi/cyberpunk-anime"), ("Dark Sushi 2.5D", "stablediffusionapi/dark-sushi-25d"),
|
| 155 |
+
("Deliberate V2", "stablediffusionapi/deliberate-v2"), ("Deliberate V3", "stablediffusionapi/deliberate-v3"), ("Disney Pixar B", "stablediffusionapi/disney-pixar-cartoon-b"),
|
| 156 |
+
("EpicRealism Natural", "stablediffusionapi/epicrealism-natural"), ("Fantasy Mix", "stablediffusionapi/fantasy-mix"), ("Flat 2D Animerge", "stablediffusionapi/flat-2d-animerge"),
|
| 157 |
+
("Galaxy Time Machine", "stablediffusionapi/galaxy-time-machine"), ("GhostMix V1.2", "stablediffusionapi/ghostmix-v12"), ("Hesemix", "stablediffusionapi/hesemix"),
|
| 158 |
+
("ICBINP", "stablediffusionapi/icbinp"), ("ICBINP Relapse", "stablediffusionapi/icbinp-relapse"), ("Illuminati", "stablediffusionapi/illuminati-diffusion"),
|
| 159 |
+
("Korean 2.5D", "stablediffusionapi/korean-25d"), ("Liberty", "stablediffusionapi/liberty"), ("Lyriel", "stablediffusionapi/lyriel"),
|
| 160 |
+
("MajicMix Fantasy", "stablediffusionapi/majicmix-fantasy"), ("MajicMix Sombre", "stablediffusionapi/majicmix-sombre"), ("Meina Alter", "stablediffusionapi/meina-alter"),
|
| 161 |
+
("Meina Unreal V4", "stablediffusionapi/meina-unreal-v4"), ("Mix Pro V4", "stablediffusionapi/mix-pro-v4"), ("NeverEnding Dream NED", "stablediffusionapi/neverending-dream-ned"),
|
| 162 |
+
("OpenJourney V4", "stablediffusionapi/openjourney-v4"), ("Perfect World V4", "stablediffusionapi/perfect-world-v4"), ("ReV Animated V1.2", "stablediffusionapi/rev-animated-v12"),
|
| 163 |
+
("RPG V4", "stablediffusionapi/rpg-v4"), ("Samdoesarts", "stablediffusionapi/samdoesarts"), ("Shonin Beautiful 2", "stablediffusionapi/shonin-beautiful-people"),
|
| 164 |
+
("Something V2", "stablediffusionapi/something-v2"), ("TMND Mix", "stablediffusionapi/tmnd-mix"), ("ToonYou Beta", "stablediffusionapi/toonyou-beta"),
|
| 165 |
+
("Yohan Diffusion", "stablediffusionapi/yohan-diffusion"), ("YungZ Anime", "stablediffusionapi/yungz-anime"), ("Anime Pastel Dream", "Lykon/anime-pastel-dream"),
|
| 166 |
+
("Anyhentai", "stablediffusionapi/anyhentai"), ("AOM3A3", "stablediffusionapi/abyssorangemix3a3"), ("CamelliaMix", "stablediffusionapi/camelliamix"),
|
| 167 |
+
("Cardos Anime", "stablediffusionapi/cardos-anime"), ("CetusMix Whimsical", "stablediffusionapi/cetusmix-whimsical"), ("ColorBox", "stablediffusionapi/colorbox"),
|
| 168 |
+
("Counterfeit V2", "stablediffusionapi/counterfeit-v20"), ("CuteYukiMix", "stablediffusionapi/cuteyukimix"), ("Darkest Anime", "stablediffusionapi/darkest-anime"),
|
| 169 |
+
("Dreamlike Photoreal", "dreamlike-art/dreamlike-photoreal-1.0"), ("Eimis Anime Models", "stablediffusionapi/eimis-anime-models"), ("Elegance", "stablediffusionapi/elegance"),
|
| 170 |
+
("EpiCRealism Pure", "stablediffusionapi/epicrealism-pure"), ("Ether Real Mix", "stablediffusionapi/ether-real-mix"), ("FaceBomb", "stablediffusionapi/facebomb"),
|
| 171 |
+
("Galena", "stablediffusionapi/galena"), ("Ghibli Background", "stablediffusionapi/ghibli-background"), ("HassanBlend", "stablediffusionapi/hassanblend"),
|
| 172 |
+
("Hentai Diffusion", "stablediffusionapi/hentai-diffusion"), ("KawaMix", "stablediffusionapi/kawamix"), ("Ligne Claire", "stablediffusionapi/ligne-claire"),
|
| 173 |
+
("Lumina", "stablediffusionapi/lumina"), ("Magical Mix", "stablediffusionapi/magical-mix"), ("MechaMix", "stablediffusionapi/mechamix"),
|
| 174 |
+
("Midnight Mixer", "stablediffusionapi/midnight-mixer"), ("Mix Pro V3", "stablediffusionapi/mix-pro-v3"), ("Niji Journey", "stablediffusionapi/niji-journey"),
|
| 175 |
+
("OnlyAnime", "stablediffusionapi/onlyanime"), ("Pastel Boys", "stablediffusionapi/pastel-boys"), ("Pixar Style", "stablediffusionapi/pixar-style"),
|
| 176 |
+
("Realism Engine", "stablediffusionapi/realism-engine"), ("Retro Anime", "stablediffusionapi/retro-anime"), ("SakuraMix", "stablediffusionapi/sakuramix"),
|
| 177 |
+
("Sci-Fi Anime", "stablediffusionapi/sci-fi-anime"), ("Smooth Anime", "stablediffusionapi/smooth-anime"), ("Steampunk Anime", "stablediffusionapi/steampunk-anime"),
|
| 178 |
+
("Vaporwave", "stablediffusionapi/vaporwave"), ("Vintage Anime", "stablediffusionapi/vintage-anime"), ("Watercolor Anime", "stablediffusionapi/watercolor-anime")
|
| 179 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
|
|
|
|
| 181 |
def make_hf_func(model_id):
|
| 182 |
return lambda p, w, h, ar: generate_hf_api(p, model_id, w, h)
|
| 183 |
|
| 184 |
+
for name, model_id in hf_models_list:
|
| 185 |
+
ALL_APIS[f"HF: {name}"] = make_hf_func(model_id)
|
|
|
|
| 186 |
|
| 187 |
# ==========================================
|
| 188 |
+
# 4. Multi-Threaded Generation Logic (10 at a time)
|
| 189 |
# ==========================================
|
| 190 |
+
def fetch_api_task(api_name, api_func, prompt, w, h, ar):
|
| 191 |
+
try:
|
| 192 |
+
img = api_func(prompt, w, h, ar)
|
| 193 |
+
return img, api_name
|
| 194 |
+
except:
|
| 195 |
+
return None, api_name
|
| 196 |
+
|
| 197 |
def generate_image_logic(prompt, style, size, selected_api):
|
| 198 |
if not prompt.strip():
|
| 199 |
yield None, "⚠️ **দয়া করে একটি প্রম্পট লিখুন!**"
|
|
|
|
| 211 |
}
|
| 212 |
enhanced_prompt = f"{prompt.strip()}{style_modifiers.get(style, '')}, aspect ratio {ar}"
|
| 213 |
|
| 214 |
+
# অটোমেটিক মোড: একসাথে ১০টা করে চেক করবে!
|
| 215 |
if selected_api == "অটোমেটিক (Auto Fallback)":
|
| 216 |
+
api_items = list(ALL_APIS.items())
|
| 217 |
+
batch_size = 10 # একসাথে ১০টা কল
|
| 218 |
|
| 219 |
+
for i in range(0, len(api_items), batch_size):
|
| 220 |
+
batch = api_items[i:i+batch_size]
|
| 221 |
+
batch_names = [name for name, _ in batch]
|
| 222 |
+
|
| 223 |
+
yield None, f"⏳ একসাথে ১০টি সার্ভারে কল করা হচ্ছে... (Batch {i//10 + 1}/20)"
|
| 224 |
+
|
| 225 |
+
successful_images = []
|
| 226 |
+
successful_names = []
|
| 227 |
+
|
| 228 |
+
# ThreadPoolExecutor দিয়ে প্যারালাল প্রসেসিং
|
| 229 |
+
with concurrent.futures.ThreadPoolExecutor(max_workers=batch_size) as executor:
|
| 230 |
+
futures = {executor.submit(fetch_api_task, name, func, enhanced_prompt, w, h, ar): name for name, func in batch}
|
| 231 |
+
|
| 232 |
+
for future in concurrent.futures.as_completed(futures):
|
| 233 |
+
img, name = future.result()
|
| 234 |
+
if img:
|
| 235 |
+
successful_images.append(img)
|
| 236 |
+
successful_names.append(name)
|
| 237 |
+
|
| 238 |
+
# যদি ১০টার মধ্যে ১টাও ছবি আসে, তাহলে ইউজারকে দিয়ে দিবে এবং থেমে যাবে
|
| 239 |
+
if successful_images:
|
| 240 |
+
source_text = ", ".join(successful_names)
|
| 241 |
+
yield successful_images, f"✅ **সফল!** একসাথে {len(successful_images)} টি ছবি পাওয়া গেছে।\n(উৎস: {source_text})"
|
| 242 |
+
return
|
| 243 |
+
|
| 244 |
+
yield None, "🚫 **দুঃখিত! বর্তমানে ২০০টি সার্ভারের সবগুলোই ব্যস্ত আছে। কিছুক্ষণ পর আবার চেষ্টা করুন।**"
|
| 245 |
|
| 246 |
+
# ম্যানুয়াল মোড (সিঙ্গেল API)
|
| 247 |
else:
|
| 248 |
yield None, f"⏳ শুধুমাত্র **{selected_api}**-এ কল করা হচ্ছে..."
|
| 249 |
api_func = ALL_APIS[selected_api]
|
| 250 |
try:
|
| 251 |
image = api_func(enhanced_prompt, w, h, ar)
|
| 252 |
+
if image: yield [image], f"✅ **সফল!** আপনি ম্যানুয়ালি {selected_api} ব্যবহার করেছেন।" # Gallery List format
|
| 253 |
else: yield None, f"❌ **দুঃখিত!** {selected_api} বর্তমানে ডাউন।"
|
| 254 |
except Exception as e:
|
| 255 |
yield None, f"❌ **দুঃখিত!** ব্যর্থ হয়েছে। অন্য একটি সার্ভার ট্রাই করুন।"
|
|
|
|
| 260 |
api_choices = ["অটোমেটিক (Auto Fallback)"] + list(ALL_APIS.keys())
|
| 261 |
|
| 262 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 263 |
+
gr.Markdown("<h1 style='text-align: center;'>🎨 Mega AI Image Generator (200 Servers - Batch Processing)</h1>")
|
| 264 |
|
| 265 |
with gr.Row():
|
| 266 |
with gr.Column(scale=1):
|
|
|
|
| 276 |
label="ছবির সাইজ (Size)", value="স্কয়ার (1:1) - Instagram"
|
| 277 |
)
|
| 278 |
|
|
|
|
| 279 |
api_selector = gr.Dropdown(
|
| 280 |
choices=api_choices, label="সার্ভার সিলেক্ট করুন (ডিফল্ট: অটোমেটিক)", value="অটোমেটিক (Auto Fallback)", interactive=True
|
| 281 |
)
|
|
|
|
| 284 |
log_box = gr.Markdown("স্ট্যাটাস: অপেক্ষমান...")
|
| 285 |
|
| 286 |
with gr.Column(scale=1):
|
| 287 |
+
# এখন সিঙ্গেল ইমেজের বদলে গ্যালারি ব্যবহার করা হচ্ছে
|
| 288 |
+
image_output = gr.Gallery(label="জেনারেট হওয়া ছবি (একাধিক হতে পারে)", columns=2, object_fit="contain", height="auto")
|
| 289 |
|
| 290 |
generate_btn.click(
|
| 291 |
fn=generate_image_logic,
|
|
|
|
| 293 |
outputs=[image_output, log_box]
|
| 294 |
)
|
| 295 |
|
| 296 |
+
# মাল্টি-ইউজার সাপোর্ট (একসাথে অনেক মানুষ ব্যবহার করতে পারবে)
|
| 297 |
+
demo.queue(max_size=50)
|
| 298 |
+
|
| 299 |
if __name__ == "__main__":
|
| 300 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|