| | <!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> |
| |
|