Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
-
import json
|
| 4 |
import time
|
| 5 |
import base64
|
| 6 |
import urllib.parse
|
|
@@ -9,25 +8,19 @@ from PIL import Image
|
|
| 9 |
from gradio_client import Client
|
| 10 |
|
| 11 |
# ==========================================
|
| 12 |
-
# 1. API Keys (
|
| 13 |
# ==========================================
|
| 14 |
KEYS = {
|
| 15 |
-
"deepai": "16e69995-00d4-4ffd-993c-a026632f6de6",
|
| 16 |
"segmind": "SG_8d03bc9ab924555c",
|
| 17 |
"getimg": "sk_6bdYCHa5p3E3dFJKIFuQI_8788b3203803717ab8980138a9a13625f1b4bc2419322bf1ad5e593a6734add2",
|
| 18 |
-
"edenai": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiYWU0MzlhYTctMWYyYS00YjYwLWI1ZjctNDllY2Y5NTlhMWJlIiwidHlwZSI6ImFwaV90b2tlbiJ9.dr3_nbmwcjwIp0L19L2e11H2IoAvELRrFaTFNvSxS_8",
|
| 19 |
-
"stability": "sk-JmNBxpvE2AD5JWJEVbYSR0sjosJD4fLU4hh5L6j88SQ3gwEA",
|
| 20 |
-
"tensorart": "ak_tensor_uXCo6TvveNBDpXgKoiGCWG-6fmsDMYdi0kM2UH5rgUk",
|
| 21 |
"google": "AIzaSyBdEqDB6SFI2uQ-5FBr-cCeRj-dkiv8pFY",
|
| 22 |
"stablehorde": "56kkbwcSPfHIr2YsDkpNDQ",
|
| 23 |
"modelslab": "42zL3I6pH7Mv94jhNf4RGyuKGGT3GoEhfXZv47WwmQsfyhgC8XNttfOpvMKL",
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
"
|
| 27 |
-
"huggingface": "hf_xxxxxxxxxxxxxxxxxxxxxxxxx" # স্লো মোডের জন্য তোমার HF Token এখানে দিও
|
| 28 |
}
|
| 29 |
|
| 30 |
-
# ব্রাউজার সিকিউরিটি (যাতে স্প্যাম ভেবে ব্লক না করে)
|
| 31 |
HEADERS_DEFAULT = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"}
|
| 32 |
|
| 33 |
def get_image_from_url(url):
|
|
@@ -36,70 +29,40 @@ def get_image_from_url(url):
|
|
| 36 |
raise Exception(f"Image load failed: {res.status_code}")
|
| 37 |
|
| 38 |
# ==========================================
|
| 39 |
-
# 2.
|
| 40 |
# ==========================================
|
| 41 |
def generate_hercai(p, w, h, ar):
|
| 42 |
url = f"https://hercai.onrender.com/v3/text2image?prompt={urllib.parse.quote(p)}"
|
| 43 |
res = requests.get(url, headers=HEADERS_DEFAULT)
|
| 44 |
if res.status_code == 200: return get_image_from_url(res.json().get("url"))
|
| 45 |
-
raise Exception(
|
| 46 |
|
| 47 |
def generate_pollinations(p, w, h, ar):
|
| 48 |
url = f"https://image.pollinations.ai/prompt/{urllib.parse.quote(p)}?width={w}&height={h}&nologo=true"
|
| 49 |
res = requests.get(url, headers=HEADERS_DEFAULT)
|
| 50 |
if res.status_code == 200: return Image.open(BytesIO(res.content))
|
| 51 |
-
raise Exception(
|
| 52 |
-
|
| 53 |
-
def generate_stability(p, w, h, ar):
|
| 54 |
-
res = requests.post("https://api.stability.ai/v2beta/stable-image/generate/core", headers={"Authorization": f"Bearer {KEYS['stability']}", "Accept": "image/*"}, files={"none": ''}, data={"prompt": p, "output_format": "jpeg", "aspect_ratio": ar})
|
| 55 |
-
if res.status_code == 200: return Image.open(BytesIO(res.content))
|
| 56 |
-
raise Exception(f"API Error {res.status_code}")
|
| 57 |
-
|
| 58 |
-
def generate_getimg(p, w, h, ar):
|
| 59 |
-
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})
|
| 60 |
-
if res.status_code == 200: return Image.open(BytesIO(base64.b64decode(res.json()["image"])))
|
| 61 |
-
raise Exception(f"API Error {res.status_code}")
|
| 62 |
-
|
| 63 |
-
def generate_segmind(p, w, h, ar):
|
| 64 |
-
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})
|
| 65 |
-
if res.status_code == 200: return Image.open(BytesIO(res.content))
|
| 66 |
-
raise Exception(f"API Error {res.status_code}")
|
| 67 |
-
|
| 68 |
-
def generate_fireworks(p, w, h, ar):
|
| 69 |
-
res = requests.post("https://api.fireworks.ai/inference/v1/image_generation/accounts/fireworks/models/stable-diffusion-xl-1024-v1-0", headers={"Authorization": f"Bearer {KEYS['fireworks']}"}, json={"text_prompts": [{"text": p}], "width": w, "height": h})
|
| 70 |
-
if res.status_code == 200: return Image.open(BytesIO(base64.b64decode(res.json()[0]["base64"])))
|
| 71 |
-
raise Exception(f"API Error {res.status_code}")
|
| 72 |
|
| 73 |
def generate_google_imagen(p, w, h, ar):
|
| 74 |
res = requests.post(f"https://generativelanguage.googleapis.com/v1beta/models/imagen-3.0-generate-001:predict?key={KEYS['google']}", json={"instances": [{"prompt": p}]})
|
| 75 |
if res.status_code == 200: return Image.open(BytesIO(base64.b64decode(res.json()['predictions'][0]['bytesBase64Encoded'])))
|
| 76 |
-
raise Exception(
|
| 77 |
|
| 78 |
-
def
|
| 79 |
-
res = requests.post("https://api.
|
| 80 |
-
if res.status_code == 200: return
|
| 81 |
-
raise Exception(
|
| 82 |
|
| 83 |
-
def
|
| 84 |
-
res = requests.post("https://api.
|
| 85 |
-
if res.status_code == 200: return
|
| 86 |
-
raise Exception(
|
| 87 |
|
| 88 |
def generate_modelslab(p, w, h, ar):
|
| 89 |
res = requests.post("https://modelslab.com/api/v6/images/text2img", json={"key": KEYS['modelslab'], "prompt": p, "width": str(w), "height": str(h)})
|
| 90 |
if res.status_code == 200 and "output" in res.json(): return get_image_from_url(res.json()["output"][0])
|
| 91 |
-
raise Exception(
|
| 92 |
-
|
| 93 |
-
def generate_openrouter(p, w, h, ar):
|
| 94 |
-
res = requests.post("https://openrouter.ai/api/v1/chat/completions", headers={"Authorization": f"Bearer {KEYS['openrouter']}"}, json={"model": "google/imagen-3-fast-generate", "messages": [{"role": "user", "content": p}]})
|
| 95 |
-
if res.status_code == 200:
|
| 96 |
-
content = res.json()['choices'][0]['message']['content']
|
| 97 |
-
if "http" in content: return get_image_from_url(content.split("(")[-1].split(")")[0] if "(" in content else content.strip())
|
| 98 |
-
raise Exception(f"API Error {res.status_code}")
|
| 99 |
|
| 100 |
-
# ==========================================
|
| 101 |
-
# 3. SLOW APIs (Hugging Face & Public)
|
| 102 |
-
# ==========================================
|
| 103 |
def generate_stable_horde(p, w, h, ar):
|
| 104 |
res = requests.post("https://stablehorde.net/api/v2/generate/async", headers={"apikey": KEYS['stablehorde']}, json={"prompt": p, "params": {"n": 1, "width": 512, "height": 512}})
|
| 105 |
if res.status_code == 202:
|
|
@@ -108,7 +71,7 @@ def generate_stable_horde(p, w, h, ar):
|
|
| 108 |
time.sleep(2)
|
| 109 |
check = requests.get(f"https://stablehorde.net/api/v2/generate/status/{job_id}")
|
| 110 |
if check.status_code == 200 and check.json().get("done", False): return get_image_from_url(check.json()['generations'][0]['img'])
|
| 111 |
-
raise Exception("Horde
|
| 112 |
|
| 113 |
def generate_hf_flux(p, w, h, ar):
|
| 114 |
client = Client("black-forest-labs/FLUX.1-schnell")
|
|
@@ -133,48 +96,81 @@ def generate_hf_api(prompt, model_id, w, h):
|
|
| 133 |
if res.status_code != 200:
|
| 134 |
res = requests.post(url, headers=headers, json={"inputs": prompt})
|
| 135 |
if res.status_code == 200: return Image.open(BytesIO(res.content))
|
| 136 |
-
raise Exception(
|
| 137 |
|
| 138 |
# ==========================================
|
| 139 |
-
#
|
| 140 |
# ==========================================
|
| 141 |
-
|
| 142 |
-
|
| 143 |
"Pollinations AI (Unlimited)": generate_pollinations,
|
| 144 |
-
"
|
| 145 |
-
"
|
| 146 |
-
"
|
| 147 |
-
"
|
| 148 |
-
"
|
| 149 |
-
"
|
| 150 |
-
"DeepAI": generate_deepai,
|
| 151 |
-
"Eden AI": generate_edenai,
|
| 152 |
-
"ModelsLab": generate_modelslab
|
| 153 |
-
}
|
| 154 |
-
|
| 155 |
-
SLOW_APIS = {
|
| 156 |
-
"Stable Horde (Crowdsourced)": generate_stable_horde,
|
| 157 |
"HF Space: FLUX.1": generate_hf_flux,
|
| 158 |
"HF Space: SDXL Light": generate_hf_sdxl_lightning,
|
| 159 |
"HF Space: SD3.5": generate_hf_sd3,
|
| 160 |
-
"HF API: OpenJourney": lambda p, w, h, ar: generate_hf_api(p, "prompthero/openjourney", w, h),
|
| 161 |
-
"HF API: RealVisXL": lambda p, w, h, ar: generate_hf_api(p, "SG161222/RealVisXL_V4.0", w, h),
|
| 162 |
-
"HF API: Animagine XL": lambda p, w, h, ar: generate_hf_api(p, "cagliostrolab/animagine-xl-3.1", w, h),
|
| 163 |
-
"HF API: Playground v2.5": lambda p, w, h, ar: generate_hf_api(p, "playgroundai/playground-v2.5-1024px-aesthetic", w, h),
|
| 164 |
-
"HF API: DreamShaper XL": lambda p, w, h, ar: generate_hf_api(p, "Lykon/dreamshaper-xl-1.0", w, h),
|
| 165 |
-
"HF API: OpenDalle V1.1": lambda p, w, h, ar: generate_hf_api(p, "dataautogpt3/OpenDalleV1.1", w, h),
|
| 166 |
-
"HF API: Anything V5 (Anime)": lambda p, w, h, ar: generate_hf_api(p, "stablediffusionapi/anything-v5", w, h),
|
| 167 |
-
"HF API: Disney Pixar": lambda p, w, h, ar: generate_hf_api(p, "stablediffusionapi/disney-pixar-cartoon", w, h),
|
| 168 |
-
"HF API: CyberRealistic": lambda p, w, h, ar: generate_hf_api(p, "stablediffusionapi/cyberrealistic", w, h),
|
| 169 |
-
"HF API: Realistic Vision": lambda p, w, h, ar: generate_hf_api(p, "SG161222/Realistic_Vision_V5.1_noVAE", w, h)
|
| 170 |
}
|
| 171 |
|
| 172 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
|
| 174 |
# ==========================================
|
| 175 |
-
#
|
| 176 |
# ==========================================
|
| 177 |
-
def generate_image_logic(prompt, style, size,
|
| 178 |
if not prompt.strip():
|
| 179 |
yield None, "⚠️ **দয়া করে একটি প্রম্পট লিখুন!**"
|
| 180 |
return
|
|
@@ -192,10 +188,9 @@ def generate_image_logic(prompt, style, size, speed_mode, selected_api):
|
|
| 192 |
enhanced_prompt = f"{prompt.strip()}{style_modifiers.get(style, '')}, aspect ratio {ar}"
|
| 193 |
|
| 194 |
if selected_api == "অটোমেটিক (Auto Fallback)":
|
| 195 |
-
|
| 196 |
-
yield None, f"⏳ {speed_mode} মোডে শুরু হচ্ছে..."
|
| 197 |
|
| 198 |
-
for api_name, api_func in
|
| 199 |
yield None, f"⏳ **{api_name}**-এ কল করা হচ্ছে..."
|
| 200 |
try:
|
| 201 |
image = api_func(enhanced_prompt, w, h, ar)
|
|
@@ -203,11 +198,9 @@ def generate_image_logic(prompt, style, size, speed_mode, selected_api):
|
|
| 203 |
yield image, f"✅ **সফল!** অটোমেটিক {api_name} থেকে ছবি তৈরি হয়েছে।"
|
| 204 |
return
|
| 205 |
except Exception as e:
|
| 206 |
-
|
| 207 |
-
error_text = str(e)[:30]
|
| 208 |
-
yield None, f"❌ **{api_name}** ব্যর্থ ({error_text}). পরেরটিতে যাচ্ছে..."
|
| 209 |
continue
|
| 210 |
-
yield None,
|
| 211 |
|
| 212 |
else:
|
| 213 |
yield None, f"⏳ শুধুমাত্র **{selected_api}**-এ কল করা হচ্ছে..."
|
|
@@ -217,16 +210,15 @@ def generate_image_logic(prompt, style, size, speed_mode, selected_api):
|
|
| 217 |
if image: yield image, f"✅ **সফল!** আপনি ম্যানুয়ালি {selected_api} ব্যবহার করেছেন।"
|
| 218 |
else: yield None, f"❌ **দুঃখিত!** {selected_api} বর্তমানে ডাউন।"
|
| 219 |
except Exception as e:
|
| 220 |
-
|
| 221 |
-
yield None, f"❌ **দুঃখিত!** ব্যর্থ হয়েছে ({error_text})। অন্য একটি ট্রাই করুন।"
|
| 222 |
|
| 223 |
# ==========================================
|
| 224 |
-
#
|
| 225 |
# ==========================================
|
| 226 |
api_choices = ["অটোমেটিক (Auto Fallback)"] + list(ALL_APIS.keys())
|
| 227 |
|
| 228 |
-
with gr.Blocks(theme=gr.themes.
|
| 229 |
-
gr.Markdown("<h1 style='text-align: center;'>🎨 Pro AI Image Generator (
|
| 230 |
|
| 231 |
with gr.Row():
|
| 232 |
with gr.Column(scale=1):
|
|
@@ -242,13 +234,8 @@ with gr.Blocks(theme=gr.themes.Base()) as demo:
|
|
| 242 |
label="ছবির সাইজ (Size)", value="স্কয়ার (1:1) - Instagram"
|
| 243 |
)
|
| 244 |
|
| 245 |
-
speed_mode = gr.Radio(
|
| 246 |
-
choices=["Fast (ফাস্ট)", "Slow (স্লো) - High Quality"],
|
| 247 |
-
label="স্পিড মোড (অটোমেটিকের জন্য)", value="Fast (ফাস্ট)"
|
| 248 |
-
)
|
| 249 |
-
|
| 250 |
api_selector = gr.Dropdown(
|
| 251 |
-
choices=api_choices, label="সার্ভার
|
| 252 |
)
|
| 253 |
|
| 254 |
generate_btn = gr.Button("Generate Image", variant="primary")
|
|
@@ -259,7 +246,7 @@ with gr.Blocks(theme=gr.themes.Base()) as demo:
|
|
| 259 |
|
| 260 |
generate_btn.click(
|
| 261 |
fn=generate_image_logic,
|
| 262 |
-
inputs=[prompt_input, style_input, size_input,
|
| 263 |
outputs=[image_output, log_box]
|
| 264 |
)
|
| 265 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
|
|
|
| 3 |
import time
|
| 4 |
import base64
|
| 5 |
import urllib.parse
|
|
|
|
| 8 |
from gradio_client import Client
|
| 9 |
|
| 10 |
# ==========================================
|
| 11 |
+
# 1. API Keys (শুধু দরকারি এবং ডেইলি রিস্টার্ট হওয়াগুলো)
|
| 12 |
# ==========================================
|
| 13 |
KEYS = {
|
|
|
|
| 14 |
"segmind": "SG_8d03bc9ab924555c",
|
| 15 |
"getimg": "sk_6bdYCHa5p3E3dFJKIFuQI_8788b3203803717ab8980138a9a13625f1b4bc2419322bf1ad5e593a6734add2",
|
|
|
|
|
|
|
|
|
|
| 16 |
"google": "AIzaSyBdEqDB6SFI2uQ-5FBr-cCeRj-dkiv8pFY",
|
| 17 |
"stablehorde": "56kkbwcSPfHIr2YsDkpNDQ",
|
| 18 |
"modelslab": "42zL3I6pH7Mv94jhNf4RGyuKGGT3GoEhfXZv47WwmQsfyhgC8XNttfOpvMKL",
|
| 19 |
+
|
| 20 |
+
# ⚠️ তোমার Hugging Face Token এখানে দিতে ভুলবে না
|
| 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):
|
|
|
|
| 29 |
raise Exception(f"Image load failed: {res.status_code}")
|
| 30 |
|
| 31 |
# ==========================================
|
| 32 |
+
# 2. Core API Functions (Unlimited & Daily)
|
| 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("Hercai Error")
|
| 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("Pollinations Error")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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("Google Error")
|
| 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("Segmind Error")
|
| 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("GetImg Error")
|
| 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("ModelsLab Error")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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:
|
|
|
|
| 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("Horde Error")
|
| 75 |
|
| 76 |
def generate_hf_flux(p, w, h, ar):
|
| 77 |
client = Client("black-forest-labs/FLUX.1-schnell")
|
|
|
|
| 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("HF API Error")
|
| 100 |
|
| 101 |
# ==========================================
|
| 102 |
+
# 3. MEGA API DICTIONARY (Exactly 50 Servers)
|
| 103 |
# ==========================================
|
| 104 |
+
ALL_APIS = {
|
| 105 |
+
# ১০টি কোর এবং আনলিমিটেড সার্ভার
|
| 106 |
"Pollinations AI (Unlimited)": generate_pollinations,
|
| 107 |
+
"Hercai AI (Unlimited)": generate_hercai,
|
| 108 |
+
"Google Imagen (Daily)": generate_google_imagen,
|
| 109 |
+
"Segmind (Daily)": generate_segmind,
|
| 110 |
+
"GetImg AI (Monthly)": generate_getimg,
|
| 111 |
+
"ModelsLab (Daily)": generate_modelslab,
|
| 112 |
+
"Stable Horde (Unlimited)": generate_stable_horde,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
"HF Space: FLUX.1": generate_hf_flux,
|
| 114 |
"HF Space: SDXL Light": generate_hf_sdxl_lightning,
|
| 115 |
"HF Space: SD3.5": generate_hf_sd3,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
}
|
| 117 |
|
| 118 |
+
# ৪০টি বেস্ট Hugging Face মডেলের লিস্ট
|
| 119 |
+
hf_models_list = {
|
| 120 |
+
"HF: DreamShaper XL": "Lykon/dreamshaper-xl-1.0",
|
| 121 |
+
"HF: RealVisXL V4.0": "SG161222/RealVisXL_V4.0",
|
| 122 |
+
"HF: OpenJourney": "prompthero/openjourney",
|
| 123 |
+
"HF: Animagine XL 3.1": "cagliostrolab/animagine-xl-3.1",
|
| 124 |
+
"HF: Playground v2.5": "playgroundai/playground-v2.5-1024px-aesthetic",
|
| 125 |
+
"HF: Realistic Vision V5": "SG161222/Realistic_Vision_V5.1_noVAE",
|
| 126 |
+
"HF: Anything V5 (Anime)": "stablediffusionapi/anything-v5",
|
| 127 |
+
"HF: Disney Pixar": "stablediffusionapi/disney-pixar-cartoon",
|
| 128 |
+
"HF: CyberRealistic": "stablediffusionapi/cyberrealistic",
|
| 129 |
+
"HF: Absolute Reality": "stablediffusionapi/absolute-reality-v181",
|
| 130 |
+
"HF: Juggernaut XL": "stablediffusionapi/juggernaut-xl-v5",
|
| 131 |
+
"HF: SDXL Base 1.0": "stabilityai/stable-diffusion-xl-base-1.0",
|
| 132 |
+
"HF: Stable Diffusion 1.5": "runwayml/stable-diffusion-v1-5",
|
| 133 |
+
"HF: Stable Diffusion 2.1": "stabilityai/stable-diffusion-2-1",
|
| 134 |
+
"HF: EpicRealism": "emilianJR/epiCRealism",
|
| 135 |
+
"HF: Deliberate": "XpucT/Deliberate",
|
| 136 |
+
"HF: MeinaMix": "Meina/MeinaMix_V11",
|
| 137 |
+
"HF: DreamShaper 8": "Lykon/dreamshaper-8",
|
| 138 |
+
"HF: GhostMix": "GhostMix/GhostMix-V2.0",
|
| 139 |
+
"HF: Pastel-Mix": "andite/pastel-mix",
|
| 140 |
+
"HF: Protogen x3.4": "darkstorm2150/Protogen_x3.4_Official_Release",
|
| 141 |
+
"HF: RevAnimated": "stablediffusionapi/rev-animated",
|
| 142 |
+
"HF: Comic Babes": "stablediffusionapi/comic-babes",
|
| 143 |
+
"HF: 3D Animation Style": "stablediffusionapi/3d-animation-style",
|
| 144 |
+
"HF: NeverEnding Dream": "stablediffusionapi/neverending-dream",
|
| 145 |
+
"HF: Reliberate": "stablediffusionapi/reliberate",
|
| 146 |
+
"HF: Edge of Realism": "stablediffusionapi/edge-of-realism",
|
| 147 |
+
"HF: AOM3 (Anime)": "stablediffusionapi/abyssorangemix3",
|
| 148 |
+
"HF: AnyLoRA": "stablediffusionapi/anylora",
|
| 149 |
+
"HF: Counterfeit V3": "stablediffusionapi/counterfeit-v30",
|
| 150 |
+
"HF: Dark Sushi Mix": "stablediffusionapi/dark-sushi-mix",
|
| 151 |
+
"HF: Photoreal 2.0": "dreamlike-art/dreamlike-photoreal-2.0",
|
| 152 |
+
"HF: Dreamlike Anime": "dreamlike-art/dreamlike-anime-1.0",
|
| 153 |
+
"HF: Dreamlike Diffusion": "dreamlike-art/dreamlike-diffusion-1.0",
|
| 154 |
+
"HF: OpenDalle V1.1": "dataautogpt3/OpenDalleV1.1",
|
| 155 |
+
"HF: Nitro Diffusion": "nitrosocke/Nitro-Diffusion",
|
| 156 |
+
"HF: Arcane Diffusion": "nitrosocke/Arcane-Diffusion",
|
| 157 |
+
"HF: Mo-Di Diffusion": "nitrosocke/mo-di-diffusion",
|
| 158 |
+
"HF: Elden Ring Style": "nitrosocke/elden-ring-diffusion",
|
| 159 |
+
"HF: Spider-Verse": "nitrosocke/spider-verse-diffusion"
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
# ফাংশন জেনারেটর (কোড ছোট রাখার জন্য)
|
| 163 |
+
def make_hf_func(model_id):
|
| 164 |
+
return lambda p, w, h, ar: generate_hf_api(p, model_id, w, h)
|
| 165 |
+
|
| 166 |
+
for name, model_id in hf_models_list.items():
|
| 167 |
+
ALL_APIS[name] = make_hf_func(model_id)
|
| 168 |
+
|
| 169 |
|
| 170 |
# ==========================================
|
| 171 |
+
# 4. Single Generation Logic
|
| 172 |
# ==========================================
|
| 173 |
+
def generate_image_logic(prompt, style, size, selected_api):
|
| 174 |
if not prompt.strip():
|
| 175 |
yield None, "⚠️ **দয়া করে একটি প্রম্পট লিখুন!**"
|
| 176 |
return
|
|
|
|
| 188 |
enhanced_prompt = f"{prompt.strip()}{style_modifiers.get(style, '')}, aspect ratio {ar}"
|
| 189 |
|
| 190 |
if selected_api == "অটোমেটিক (Auto Fallback)":
|
| 191 |
+
yield None, "⏳ ছবি তৈরি শুরু হচ্ছে..."
|
|
|
|
| 192 |
|
| 193 |
+
for api_name, api_func in ALL_APIS.items():
|
| 194 |
yield None, f"⏳ **{api_name}**-এ কল করা হচ্ছে..."
|
| 195 |
try:
|
| 196 |
image = api_func(enhanced_prompt, w, h, ar)
|
|
|
|
| 198 |
yield image, f"✅ **সফল!** অটোমেটিক {api_name} থেকে ছবি তৈরি হয়েছে।"
|
| 199 |
return
|
| 200 |
except Exception as e:
|
| 201 |
+
yield None, f"❌ **{api_name}** ব্যস্ত বা লিমিট শেষ। পরেরটিতে যাচ্ছে..."
|
|
|
|
|
|
|
| 202 |
continue
|
| 203 |
+
yield None, "🚫 **দুঃখিত! বর্তমানে সবগুলো সার্ভার ব্যস্ত আছে।**"
|
| 204 |
|
| 205 |
else:
|
| 206 |
yield None, f"⏳ শুধুমাত্র **{selected_api}**-এ কল করা হচ্ছে..."
|
|
|
|
| 210 |
if image: yield image, f"✅ **সফল!** আপনি ম্যানুয়ালি {selected_api} ব্যবহার করেছেন।"
|
| 211 |
else: yield None, f"❌ **দুঃখিত!** {selected_api} বর্তমানে ডাউন।"
|
| 212 |
except Exception as e:
|
| 213 |
+
yield None, f"❌ **দুঃখিত!** ব্যর্থ হয়েছে। অন্য একটি সার্ভার ট্রাই করুন।"
|
|
|
|
| 214 |
|
| 215 |
# ==========================================
|
| 216 |
+
# 5. Clean Gradio Web UI
|
| 217 |
# ==========================================
|
| 218 |
api_choices = ["অটোমেটিক (Auto Fallback)"] + list(ALL_APIS.keys())
|
| 219 |
|
| 220 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 221 |
+
gr.Markdown("<h1 style='text-align: center;'>🎨 Pro AI Image Generator (50 Servers)</h1>")
|
| 222 |
|
| 223 |
with gr.Row():
|
| 224 |
with gr.Column(scale=1):
|
|
|
|
| 234 |
label="ছবির সাইজ (Size)", value="স্কয়ার (1:1) - Instagram"
|
| 235 |
)
|
| 236 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
api_selector = gr.Dropdown(
|
| 238 |
+
choices=api_choices, label="সার্ভার সিলেক্ট করুন (ডিফল্ট: অটোমেটিক)", value="অটোমেটিক (Auto Fallback)", interactive=True
|
| 239 |
)
|
| 240 |
|
| 241 |
generate_btn = gr.Button("Generate Image", variant="primary")
|
|
|
|
| 246 |
|
| 247 |
generate_btn.click(
|
| 248 |
fn=generate_image_logic,
|
| 249 |
+
inputs=[prompt_input, style_input, size_input, api_selector],
|
| 250 |
outputs=[image_output, log_box]
|
| 251 |
)
|
| 252 |
|