Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,37 @@
|
|
| 1 |
-
|
| 2 |
-
import
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import json
|
| 4 |
|
| 5 |
+
url = "https://nexra.aryahcr.cc/api/image/complements"
|
| 6 |
+
headers = {
|
| 7 |
+
"Content-Type": "application/json"
|
| 8 |
+
}
|
| 9 |
|
| 10 |
+
def generate_image(prompt, model):
|
| 11 |
+
data = {
|
| 12 |
+
"prompt": prompt,
|
| 13 |
+
"model": model,
|
| 14 |
+
}
|
| 15 |
+
try:
|
| 16 |
+
response = requests.post(url, headers=headers, data=json.dumps(data))
|
| 17 |
+
raw_response = response.text.strip()
|
| 18 |
+
|
| 19 |
+
if response.status_code == 200:
|
| 20 |
+
cleaned_response = raw_response.lstrip('_')
|
| 21 |
+
response_data = json.loads(cleaned_response)
|
| 22 |
+
|
| 23 |
+
if 'images' in response_data and isinstance(response_data['images'], list):
|
| 24 |
+
image_url = response_data['images'][0]
|
| 25 |
+
return image_url
|
| 26 |
+
else:
|
| 27 |
+
return "Error: No image data in the response."
|
| 28 |
+
else:
|
| 29 |
+
return f"Error: {response.status_code}"
|
| 30 |
+
except json.JSONDecodeError:
|
| 31 |
+
return "Error: Invalid JSON response."
|
| 32 |
+
except Exception as e:
|
| 33 |
+
return str(e)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
iface = gr.Interface(fn=generate_image, inputs=[gr.Textbox(label="Enter prompt"), gr.Radio(["dalle2"], label="Select Model")], outputs="image", title="DALLE2 Generation", description="Disclaimer: This uses the Nexra API for image generation. I cannot guarantee rate limits, if you do not recieve an image please try again. I will change to use a different API soon. DALL-E 3 is not supported yet.")
|
| 37 |
+
iface.launch()
|