File size: 4,415 Bytes
07e7c2e
 
 
 
3930741
07e7c2e
dc35861
07e7c2e
dc35861
 
 
 
 
 
375c02e
8a598ae
375c02e
dc35861
 
 
 
 
 
 
375c02e
8a598ae
375c02e
dc35861
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
07e7c2e
dc35861
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
07e7c2e
dc35861
 
 
 
 
 
 
 
 
 
3930741
dc35861
07e7c2e
dc35861
07e7c2e
 
 
 
dc35861
 
 
b111b48
dc35861
 
 
 
 
 
07e7c2e
b111b48
dc35861
8a598ae
 
dc35861
 
8a598ae
 
 
375c02e
 
8a598ae
 
 
 
dc35861
375c02e
 
 
 
dc35861
8a598ae
dc35861
 
8a598ae
 
07e7c2e
 
 
dc35861
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
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
import os
import random
import requests
import gradio as gr
from PIL import Image
from io import BytesIO
from gradio_client import Client

# more servers coming soon...


SERVER_NAMES = {
    "google_us": "Google US Server",
    "azure_lite": "Azure Lite Supercomputer Server",
    "artemis" : "Artemis GPU Super cluster",
    "nsfw_core" : "NSFW-Core: Uncensored Server",
    "nsfw_core_2" : "NSFW-Core: Uncensored Server 2",
    
}


SERVER_SOCKETS = {
    "google_us": None,
    "azure_lite": "FLUX-Pro-SERVER1",
    "artemis" : "FLUX-Pro-Artemis-GPU",
    "nsfw_core": "FLUX-Pro-NSFW-LocalCoreProcessor",
    "nsfw_core_2" : "FLUX-Pro-NSFW-LocalCoreProcessor-v2",
    
}

HF_TOKEN = os.environ.get("HF_TOKEN")
FLUX_URL  = os.environ.get("FLUX_URL")



def _open_image_from_str(s: str):
    # base64 decoding
    if s.startswith("http"):
        r = requests.get(s); return Image.open(BytesIO(r.content))
    if os.path.exists(s):
        return Image.open(s)
    # try base64 blob
    try:
        import base64
        _, b64 = s.split(",", 1)
        data = base64.b64decode(b64)
        return Image.open(BytesIO(data))
    except:
        raise ValueError(f"Can't parse image string: {s[:30]}…")



def generate_image(prompt, width, height, seed, randomize, server_choice):

    print("\n\n\n\n"+prompt+"\n\n\n\n")
    
    if randomize:
        seed = random.randint(0, 9_999_999)

    # dict key for this display name
    key = next(k for k, v in SERVER_NAMES.items() if v == server_choice)
    socket = SERVER_SOCKETS.get(key)

    
    if socket is None:
        if not FLUX_URL:
            return "Error: FLUX_URL not set."
        url = (
            FLUX_URL
            .replace("[prompt]", prompt)
            .replace("[w]", str(width))
            .replace("[h]", str(height))
            .replace("[seed]", str(seed))
        )
        r = requests.get(url)
        return Image.open(BytesIO(r.content)) if r.ok else f"FLUX-Pro failed ({r.status_code})"

    
    space_id = f"NihalGazi/{socket}"
    client = Client(space_id, hf_token=HF_TOKEN)
    res = client.predict(
        prompt=prompt,
        width=width,
        height=height,
        seed=seed,
        randomize=randomize,
        api_name="/predict"
    )

    # handle dict or str
    if isinstance(res, dict):
        if res.get("path"):
            return Image.open(res["path"])
        if res.get("url"):
            return _open_image_from_str(res["url"])
        return "No image found in response."
    elif isinstance(res, str):
        return _open_image_from_str(res)
    else:
        return f"Unexpected response type: {type(res)}"

# ─── GRADIO INTERFACE ─────────────────────────────────────────────────────

iface = gr.Interface(
    fn=generate_image,
    inputs=[
        gr.Textbox(label="Prompt", placeholder="Enter your image prompt…"),
        gr.Slider(512, 1280, step=16, value=1280, label="Width"),
        gr.Slider(512, 1280, step=16, value=1280, label="Height"),
        gr.Number(label="Seed", value=0),
        gr.Checkbox(label="Randomize Seed", value=True),
        gr.Dropdown(
            label="Server",
            choices=list(SERVER_NAMES.values()),
            value=SERVER_NAMES["google_us"]
        ),
    ],
    outputs=gr.Image(type="pil"),
    title="Unlimited FLUX‑Pro",
    description = """
**Enter a prompt and tweak your settings:**  
- **Width & Height** – choose your canvas size  
- **Seed** – pick a number or check **Randomize Seed**  
- **Server** – switch between servers if one is slow or fails:
  - **Google US Server**  
  - **Azure Lite Supercomputer Server**  
  - **Artemis GPU Super cluster**  
  - **NSFW‑Core: Uncensored Servers** (for explicit content; use responsibly)
- **Suggestions** – have ideas? I’m open to them!

⚠️ **Caution:**  
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.


> ⚑ 2 NSFW Servers available 


Click **Generate** and enjoy unlimited AI art!

❀️ **Like & follow** for more AI projects:  
β€’ Instagram: [@nihal_gazi_io](https://www.instagram.com/nihal_gazi_io/)  
β€’ Discord:β€―nihal_gazi_io  
"""
)

if __name__ == "__main__":
    iface.launch()