dhanishetty's picture
Update app.py
a82b385 verified
raw
history blame
1.03 kB
from PIL import Image
import requests
from openai import OpenAI
import gradio as gr
def get_image(prompt,textbox):
prompt = prompt
client = OpenAI(api_key=textbox)
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')
return img
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()