File size: 1,295 Bytes
599a9f1
 
b52351a
599a9f1
a616b2e
 
 
 
d16340f
a616b2e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ec62272
 
ee74194
 
 
a82b385
 
ee74194
 
 
 
 
 
e993e59
ee74194
716d4e9
6f001b5
 
ee74194
b52351a
5801106
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
41
42
43
44
45
46
47
48
49
50
51
52
53
from PIL import Image
import requests 
from openai import OpenAI
import gradio as gr
img1 = "img1.png"
img3 = "img3.png"


def get_image(prompt, api_key):
    if api_key == '':
        output= img1
    else:
        try:
            client = OpenAI(api_key=api_key)
            response = client.images.generate(
                model = "dall-e-3",
                prompt = prompt,
                size = "1024x1024",
                n = 1
            )
            image_url = response.data[0].url
            data = requests.get(image_url).content
            f = open('img.jpg','wb') 
            f.write(data)
            f.close()
            img = Image.open('img.jpg')
        
            output = img
        except :
           output = img3
    return output


title = "Please Provide API-Key and Enter your Prompt"
description = """
<img src = "https://upload.wikimedia.org/wikipedia/commons/4/4d/OpenAI_Logo.svg" width=300px> 

# A model that can generate images given a natural language prompt
"""

gr.Interface(
    get_image,
    [
        gr.Textbox(label="Enter your Prompt",),
        gr.Textbox(type = 'password',label="Enter your API-Key", placeholder="API-Key", lines=1)
    ],
    outputs= gr.Image(type='pil'),
    title=title,
    description=description,
 ).launch()