File size: 7,063 Bytes
0a7e466
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Image Generation API</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            background-color: #0d1117;
            color: #c9d1d9;
            padding: 20px;
        }
        .container {
            max-width: 850px;
            margin: auto;
            background: #161b22;
            padding: 25px;
            border-radius: 10px;
            box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.5);
            border: 1px solid #30363d;
        }
        h1 {
            color: #58a6ff;
            text-align: center;
        }
        h2, h3 {
            color: #1f6feb;
        }
        p {
            line-height: 1.6;
        }
        .endpoint {
            padding: 15px;
            border-bottom: 1px solid #30363d;
        }
        code, pre {
            display: block;
            background-color: #0d1117;
            color: #58a6ff;
            padding: 10px;
            border-radius: 5px;
            font-family: 'Courier New', monospace;
            white-space: pre-wrap;
            word-wrap: break-word;
            border-left: 4px solid #58a6ff;
        }
        .footer {
            text-align: center;
            margin-top: 20px;
            color: #8b949e;
        }

        h1{
         font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
         color: rgb(3, 234, 219);
         padding: 1em;
         font-size: 3em;
         font-weight: bolder;
        }

        .baseurl{
         font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
         text-transform:inherit;
         position: relative;
         text-align: center;
         font-size: 1.3em;
        }

        .h3{
            font-size: 1.5em;
            color: #58a6ff;

        }

    </style>
</head>
<body>
    <div class="container">
        <h1>Image Generation API</h1>        
        <h2>⚑ Available Endpoints</h2>

        <div class="baseurl">
            <div>
                <span class="h3" >[</span>
                <span>BASEURL</span>
                <span class="h3">]</span>
                <span class="h3">:</span>
                <span>
                    <span class="h3">"</span>
                    <span>HTTPS://ADARSHJI-API.HF.SPACE/</span>
                    <span class="h3">"</span>
                </span>
            </div>
        </div>
        
        <div class="endpoint">
            <h3>πŸš€ Generate Image</h3>
            <p><strong>Endpoint:</strong> <code>[POST] /generate/image</code></p>
            <p><strong>Description:</strong> Generates an AI image based on the given prompt.</p>
            <p><strong>Request Body:</strong></p>
            <pre>{
    "prompt": "A futuristic cityscape",
    "model": "black-forest-labs-flux-1-dev",
    "width": 1024,
    "height": 1024,
    "guidance_scale": 3.5,
    "seed": 0,
    "provider": "blackforestlabs"
}</pre>
            <p><strong>Response Example:</strong></p>
            <pre>{
    "Result": "http://adarshji-api.hf.space/images/1234567890.jpg"
}</pre>
        </div>

        <div class="endpoint">
            <h3>πŸ“Œ Get Available Providers</h3>
            <p><strong>Endpoint:</strong> <code>[POST] /providers</code></p>
            <p><strong>Description:</strong> Retrieves a list of supported image providers.</p>
            <p><strong>Response Example:</strong></p>
            <pre>{
    "providers": ["blackforestlabs", "flux", "blackforestlabs-schnell"]
}</pre>
        </div>

        <div class="endpoint">
            <h3>πŸ“‹ Get Models by Provider</h3>
            <p><strong>Endpoint:</strong> <code>GET /generate/image/model</code></p>
            <p><strong>Description:</strong> Retrieves available models for a given provider.</p>
            <p><strong>Request Body:</strong></p>
            <pre>{
    "provider": "blackforestlabs"
}</pre>
            <p><strong>Response Example:</strong></p>
            <pre>{
    "models": ["flux-1", "flux-2", "hyper-realistic-v3"]
}</pre>
        </div>

        <div class="endpoint">
            <h3>🏠 Homepage</h3>
            <p><strong>Endpoint:</strong> <code>GET /</code></p>
            <p><strong>Description:</strong> Returns this documentation page.</p>
        </div>

        <h2>🐍 Python Usage Example</h2>
        <p>Here is how you can use the API in Python to generate an image:</p>
        <pre><code>
import requests

BASE_URL = "https://adarshji-api.hf.space/"

def generate_image(
    prompt,
    model="black-forest-labs-flux-1-dev",
    width=1024,
    height=1024,
    guidance_scale=3.5,
    seed=0,
    provider="blackforestlabs"
    ):
    
    url = f"{BASE_URL}/generate/image"
    
    payload = {
        "prompt": prompt,
        "model": model,
        "width": width,
        "height": height,
        "guidance_scale": guidance_scale,
        "seed": seed,
        "provider": provider
    }
    
    headers = {'Content-Type': 'application/json'}
    
    response = requests.post(url, json=payload, headers=headers)
    
    if response.status_code == 200:
    
        try:
            data = response.json()
            print("Image URL:", data)
        except requests.exceptions.JSONDecodeError:
            print("Error: Failed to decode JSON response.")
    
    else:
        print(f"Error: {response.status_code}, {response.text}")

def get_providers():

    url = f"{BASE_URL}/providers"

    headers = {'Content-Type': 'application/json'}
    
    response = requests.get(url, headers=headers)
    
    if response.status_code == 200:
        try:
        data = response.json()
        print("Available Providers:", data.get("providers"))
        except requests.exceptions.JSONDecodeError:
            print("Error: Failed to decode JSON response.")
    else:
        print(f"Error: {response.status_code}, {response.text}")
            
def get_models(provider="blackforestlabs"):
    url = f"{BASE_URL}/generate/image/model"
    payload = {"provider": provider}
    headers = {'Content-Type': 'application/json'}
    
    response = requests.post(url, json=payload, headers=headers)
    
    if response.status_code == 200:
    try:
        data = response.json()
        print(f"Models for {provider}:", data.get("models"))
    except requests.exceptions.JSONDecodeError:
        print("Error: Failed to decode JSON response.")
    else:
        print(f"Error: {response.status_code}, {response.text}")

if __name__ == "__main__":
    print("Getting providers:")
    get_providers()

    print("\nGetting models for 'blackforestlabs':")
    get_models("blackforestlabs")

    print("\nGenerating image:")
    generate_image(prompt="A beautiful sunset over the ocean.")
            
</code></pre>

        <div class="footer">
            <p>πŸš€ API v1.0 | Designed By ADARSH ❀❀</p>
        </div>
    </div>
</body>
</html>