File size: 1,073 Bytes
0e6c6f9
 
 
887d429
deace36
 
 
e8f2b4e
0e6c6f9
 
4389221
e8f2b4e
d08c0ba
 
887d429
 
 
 
 
 
 
 
 
 
 
 
 
 
e8f2b4e
887d429
 
deace36
 
 
 
0e6c6f9
e8f2b4e
deace36
887d429
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
39
40
import os
import gradio as gr
import openai
import requests
from PIL import Image
import io
import numpy as np

openai.api_key = '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' # your api key

def DALLE(user_input):
    prompt = user_input
    response = prompt
    
    # Create the DALL-E image using the OpenAI API
    data = {
        "model": "image-alpha-001",
        "prompt": f"{prompt}:::",
        "n": 1,
        "size": "1024x1024",
        "response_format": "url"
    }
    headers = {
        "Content-Type": "application/json",
        "Authorization": f"Bearer {openai.api_key}"
    }
    response = requests.post("https://api.openai.com/v1/images/generations", json=data, headers=headers)
    response.raise_for_status()
    
    # Convert the image to a format that Gradio can display
    img_bytes = io.BytesIO(requests.get(response.json()["data"][0]["url"]).content)
    img = Image.open(img_bytes)
    img_arr = np.array(img)
    
    return img_arr

iface = gr.Interface(fn=DALLE, inputs="text", outputs="image", title="bhAI")
iface.launch()