Walmart-the-bag's picture
Update app.py
2fc1e78 verified
raw
history blame
1.4 kB
import gradio as gr
import requests
import json
import time
url = "https://nexra.aryahcr.cc/api/image/complements"
headers = {"Content-Type": "application/json"}
def generate_image(prompt, model):
data = {"prompt": prompt, "model": model}
response = requests.post(url, headers=headers, data=json.dumps(data))
if response.status_code == 200:
response_data = response.json()
image_id = response_data.get("id")
while True:
status_response = requests.get(f"{url}/{image_id}")
if status_response.status_code == 200:
status_data = status_response.json()
status = status_data.get("status")
if status == "completed":
images = status_data.get("images")
if images:
return images[0]
return no_nsfw_image_path
elif status in ["error", "not_found"]:
return no_nsfw_image_path
time.sleep(1)
return no_nsfw_image_path
iface = gr.Interface(
fn=generate_image,
inputs=[gr.Textbox(label="Enter prompt"), gr.Radio(["dalle2"], label="Select Model")],
outputs=gr.Image(type="filepath"),
title="DALLE2 Generation",
description="DALLE-2 Generation from Nextra API, NOTE: DALL-E 3 is not supported yet."
)
iface.launch(share=True)