File size: 1,429 Bytes
a03174d
 
 
861d39e
a03174d
 
 
 
861d39e
a03174d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import requests
import json

url = "https://nexra.aryahcr.cc/api/image/complements"
headers = {
    "Content-Type": "application/json"
}

def generate_image(prompt, model):
    data = {
        "prompt": prompt,
        "model": model,
    }
    try:
        response = requests.post(url, headers=headers, data=json.dumps(data))
        raw_response = response.text.strip()

        if response.status_code == 200:
            cleaned_response = raw_response.lstrip('_')
            response_data = json.loads(cleaned_response)
            
            if 'images' in response_data and isinstance(response_data['images'], list):
                image_url = response_data['images'][0]
                return image_url
            else:
                return "Error: No image data in the response."
        else:
            return f"Error: {response.status_code}"
    except json.JSONDecodeError:
        return "Error: Invalid JSON response."
    except Exception as e:
        return str(e)


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.")
iface.launch()