Spaces:
Running
Running
<html> | |
<head> | |
<title>API Documentation</title> | |
<style> | |
body { | |
font-family: Arial, sans-serif; | |
padding: 20px; | |
} | |
h1 { | |
margin-bottom: 20px; | |
} | |
.endpoint { | |
margin-bottom: 30px; | |
} | |
.endpoint h3 { | |
margin-top: 0; | |
font-size: 1.2em; | |
font-weight: bold; | |
} | |
.method { | |
margin-bottom: 10px; | |
} | |
.code-block { | |
background-color: #f4f4f4; | |
padding: 10px; | |
font-family: monospace; | |
margin-bottom: 20px; | |
} | |
.code-block pre { | |
margin: 0; | |
} | |
.sample-code { | |
background-color: #f4f4f4; | |
padding: 10px; | |
margin-bottom: 20px; | |
} | |
.sample-code pre { | |
margin: 0; | |
overflow-x: auto; | |
} | |
</style> | |
<script> | |
document.addEventListener("DOMContentLoaded", function() { | |
const endpoints = document.querySelectorAll(".endpoint"); | |
endpoints.forEach(function(endpoint) { | |
const codeBlock = endpoint.querySelector(".code-block"); | |
const sampleCode = endpoint.querySelector(".sample-code"); | |
const showButton = document.createElement("button"); | |
showButton.textContent = "Show Example Code"; | |
showButton.addEventListener("click", function() { | |
codeBlock.style.display = "block"; | |
sampleCode.style.display = "block"; | |
showButton.style.display = "none"; | |
}); | |
endpoint.appendChild(showButton); | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<h1>API Documentation</h1> | |
<div class="endpoint"> | |
<h3>Generate Image</h3> | |
<p class="method">Endpoint: <code>/api/generate</code></p> | |
<p class="method">Method: <code>POST</code></p> | |
<p class="method">Description: Generate an image based on the provided parameters.</p> | |
<div class="code-block" style="display: none;"> | |
<p>Request Payload:</p> | |
<pre> | |
{ | |
"prompt": "Woman sitting on a table, looking at the sky, seen from behind", | |
"style": "ANIME_V2", | |
"ratio": "RATIO_16X9", | |
"model": "REALISTIC" | |
} | |
</pre> | |
</div> | |
<div class="code-block" style="display: none;"> | |
<p>Response:</p> | |
<pre> | |
{ | |
"error": "An error occurred while generating the image." | |
} | |
</pre> | |
</div> | |
<div class="sample-code" style="display: none;"> | |
<p>Sample Code:</p> | |
<pre> | |
import requests | |
url = 'https://imseldrith-imagine.hf.space/api/generate' | |
headers = {'Content-Type':'application/json'} | |
payload = { | |
'prompt': "Woman sitting on a table, looking at the sky, seen from behind", | |
'style': 'ANIME_V2', | |
'ratio': 'RATIO_16X9', | |
'model': 'REALISTIC' | |
} | |
response = requests.post(url, json=payload) | |
if response.status_code == 200: | |
# Image generation successful | |
with open('generated_image.jpg', 'wb') as image_file: | |
image_file.write(response.content) | |
print('Image saved successfully!') | |
else: | |
# Error occurred during image generation | |
error_data = response.json() | |
error_message = error_data.get('error', 'Unknown error') | |
print(f'Failed to generate image: {error_message}') | |
</pre> | |
</div> | |
</div> | |
<!-- Add more endpoints and documentation as needed --> | |
</body> | |
</html> | |