Avi3738 commited on
Commit
8003291
Β·
verified Β·
1 Parent(s): 1501e2d

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +195 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,195 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import random
3
+ import requests
4
+ import gradio as gr
5
+ from PIL import Image
6
+ from io import BytesIO
7
+ from gradio_client import Client
8
+
9
+
10
+ sponsor_html = """
11
+ <div style="display:flex; padding: 0em; justify-content: center; gap: 1em; border-radius: 2em;">
12
+ <img src="https://static-00.iconduck.com/assets.00/google-cloud-icon-2048x1288-h9qynww8.png"
13
+ style="height:1em; width:auto; object-fit:contain;"
14
+ title="Google Cloud for Startups"/>
15
+ <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/9/93/Amazon_Web_Services_Logo.svg/2560px-Amazon_Web_Services_Logo.svg.png"
16
+ style="height:1em; width:auto; object-fit:contain;"
17
+ title="AWS Activate"/>
18
+ <img src="https://ageyetech.com/wp-content/uploads/2020/07/AgEye_nvidia_inception_logo_new.png"
19
+ style="height:1em; width:auto; object-fit:contain;"
20
+ title="NVIDIA Inception"/>
21
+ <img src="https://azurecomcdn.azureedge.net/cvt-8310f955fa0c7812bd316a20d46a917e5b94170e9e9da481ca3045acae446bb5/svg/logo.svg"
22
+ style="height:1em; width:auto; object-fit:contain;"
23
+ title="Azure for Startups"/>
24
+ <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/4b/Cloudflare_Logo.svg/2560px-Cloudflare_Logo.svg.png"
25
+ style="height:1em; width:auto; object-fit:contain;"
26
+ title="Cloudflare"/>
27
+ <img src="https://scaleway.com/cdn-cgi/image/width=640/https://www-uploads.scaleway.com/Scaleway_3_D_Logo_57e7fb833f.png"
28
+ style="height:1em; width:auto; object-fit:contain;"
29
+ title="Scaleway"/>
30
+ <img src="https://cdn.prod.website-files.com/63e26df0d6659968e46142f7/63e27b40e661321d5278519b_logotype-bb8cd083.svg"
31
+ style="height:1em; width:auto; object-fit:contain;"
32
+ title="Modal"/>
33
+ <img src="https://pollinations.ai/favicon.ico"
34
+ style="height:1em; width:auto; object-fit:contain;"
35
+ title="Pollination.ai"/>
36
+ </div>
37
+ """
38
+
39
+ # more servers coming soon...
40
+
41
+
42
+ SERVER_NAMES = {
43
+ "google_us": "Google US Server",
44
+ "azure_lite": "Azure Lite Supercomputer Server",
45
+ "artemis" : "Artemis GPU Super cluster",
46
+ "nb_dr" : "NebulaDrive Tensor Server",
47
+ "pixelnet" : "PixelNet NPU Server",
48
+ "nsfw_core" : "NSFW-Core: Uncensored Server",
49
+ "nsfw_core_2" : "NSFW-Core: Uncensored Server 2",
50
+ "nsfw_core_3" : "NSFW-Core: Uncensored Server 3",
51
+ "nsfw_core_4" : "NSFW-Core: Uncensored Server 4",
52
+ }
53
+
54
+
55
+ SERVER_SOCKETS = {
56
+ "google_us": None,
57
+ "azure_lite": "FLUX-Pro-SERVER1",
58
+ "artemis" : "FLUX-Pro-Artemis-GPU",
59
+ "nb_dr" : "FLUX-Pro-NEBULADRIVE",
60
+ "pixelnet" : "FLUX-Pro-PIXELNET",
61
+ "nsfw_core": "FLUX-Pro-NSFW-LocalCoreProcessor",
62
+ "nsfw_core_2" : "FLUX-Pro-NSFW-LocalCoreProcessor-v2",
63
+ "nsfw_core_3" : "FLUX-Pro-NSFW-LocalCoreProcessor-v3",
64
+ "nsfw_core_4" : "FLUX-Pro-NSFW-LocalCoreProcessor-v4",
65
+ }
66
+
67
+ HF_TOKEN = os.environ.get("HF_TOKEN")
68
+ FLUX_URL = os.environ.get("FLUX_URL")
69
+
70
+
71
+ def _open_image_from_str(s: str):
72
+ # base64 decoding
73
+ if s.startswith("http"):
74
+ r = requests.get(s); return Image.open(BytesIO(r.content))
75
+ if os.path.exists(s):
76
+ return Image.open(s)
77
+ # try base64 blob
78
+ try:
79
+ import base64
80
+ _, b64 = s.split(",", 1)
81
+ data = base64.b64decode(b64)
82
+ return Image.open(BytesIO(data))
83
+ except:
84
+ raise ValueError(f"Can't parse image string: {s[:30]}…")
85
+
86
+
87
+ def generate_image(prompt, width, height, seed, randomize, server_choice):
88
+
89
+ print(prompt+"\n\n\n\n")
90
+ # determine seed
91
+ if randomize:
92
+ seed = random.randint(0, 9_999_999)
93
+ used_seed = seed
94
+
95
+ # pick server key and socket
96
+ key = next(k for k, v in SERVER_NAMES.items() if v == server_choice)
97
+ socket = SERVER_SOCKETS.get(key)
98
+
99
+ # generate image via FLUX or HF space
100
+ if socket is None:
101
+ if not FLUX_URL:
102
+ return "Error: FLUX_URL not set.", used_seed
103
+ url = (
104
+ FLUX_URL
105
+ .replace("[prompt]", prompt)
106
+ .replace("[w]", str(width))
107
+ .replace("[h]", str(height))
108
+ .replace("[seed]", str(seed))
109
+ )
110
+ r = requests.get(url)
111
+ img = Image.open(BytesIO(r.content)) if r.ok else f"FLUX-Pro failed ({r.status_code})"
112
+ else:
113
+ space_id = f"NihalGazi/{socket}"
114
+ client = Client(space_id, hf_token=HF_TOKEN)
115
+ res = client.predict(
116
+ prompt=prompt,
117
+ width=width,
118
+ height=height,
119
+ seed=seed,
120
+ randomize=randomize,
121
+ api_name="/predict"
122
+ )
123
+ if isinstance(res, dict):
124
+ if res.get("path"):
125
+ img = Image.open(res["path"])
126
+ elif res.get("url"):
127
+ img = _open_image_from_str(res["url"])
128
+ else:
129
+ img = "No image found in response."
130
+ elif isinstance(res, str):
131
+ img = _open_image_from_str(res)
132
+ else:
133
+ img = f"Unexpected response type: {type(res)}"
134
+
135
+ # return both image and used seed
136
+ return img, used_seed
137
+
138
+ # ─── GRADIO INTERFACE ─────────────────────────────────────────────────────
139
+ with gr.Blocks(theme=gr.themes.Default()) as demo:
140
+ gr.Markdown(
141
+ """
142
+ # Unlimited FLUX-Pro
143
+
144
+ **Enter a prompt and tweak your settings:**
145
+ - **Width & Height** – choose your canvas size
146
+ - **Seed** – pick a number or check **Randomize Seed**
147
+ - **Server** – switch between servers if one is slow or fails:
148
+ - **Google US Server**
149
+ - **Azure Lite Supercomputer Server**
150
+ - **Artemis GPU Super cluster**
151
+ - **NebulaDrive Tensor Server**
152
+ - **PixelNet NPU Server**
153
+ - **NSFW‑Core: Uncensored Servers** (for explicit content; use responsibly)
154
+ - **Suggestions** – have ideas? I’m open to them!
155
+
156
+ ⚠️ **Caution:**
157
+ The **NSFW‑Core** server can generate adult‑only content. You must be of legal age in your jurisdiction and comply with all local laws and platform policies. Developer is not liable for misuse.
158
+
159
+
160
+ > ⚑ 4 NSFW Servers available
161
+
162
+
163
+ Click **Generate** and enjoy unlimited AI art!
164
+
165
+ ❀️ **Like & follow** for more AI projects:
166
+ β€’ Instagram: [@nihal_gazi_io](https://www.instagram.com/nihal_gazi_io/)
167
+ β€’ Discord:β€―nihal_gazi_io
168
+ """
169
+ )
170
+
171
+ # Inputs
172
+ prompt = gr.Textbox(label="Prompt", placeholder="Enter your image prompt…", lines=4)
173
+ width = gr.Slider(512, 2048, step=16, value=1280, label="Width")
174
+ height = gr.Slider(512, 2048, step=16, value=1280, label="Height")
175
+ seed = gr.Number(label="Seed", value=0)
176
+ rand = gr.Checkbox(label="Randomize Seed", value=True)
177
+ server = gr.Dropdown(label="Server", choices=list(SERVER_NAMES.values()),
178
+ value=list(SERVER_NAMES.values())[0])
179
+
180
+ generate_btn = gr.Button("Generate")
181
+
182
+ # Outputs: image and seed display
183
+ output = gr.Image(type="pil", label="Generated Image")
184
+ seed_display = gr.Textbox(label="Used Seed", interactive=False)
185
+
186
+ generate_btn.click(
187
+ generate_image,
188
+ inputs=[prompt, width, height, seed, rand, server],
189
+ outputs=[output, seed_display]
190
+ )
191
+
192
+ # Sponsor wall
193
+ gr.HTML(sponsor_html)
194
+
195
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ requests