File size: 902 Bytes
f632572
ee103d5
 
c00d13d
ee103d5
 
 
f0efdce
 
 
ee103d5
c05eb2d
 
 
 
 
 
11d0bda
afa85d1
 
c05eb2d
8421132
ee103d5
 
 
 
 
 
 
 
 
 
 
 
 
64e5cbd
ee103d5
78610a7
ee103d5
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 requests
import openai
from PIL import Image
from io import BytesIO

openai.api_key = os.getenv("OPENAI_API_KEY")


# Define the function that generates the image
def generate_image(prompt):
    response = openai.Image.create(
      prompt=prompt,
      n=1,
      size="1024x1024"
    )    
    image_url = response()["data"][0]["url"]
    image = Image.open(BytesIO(requests.get(image_url).content))
    return image

 

iface = gr.Interface(
    fn=generate_image,
    inputs=gr.inputs.Textbox(label="Enter Prompt Here"),
    outputs="image",
    
    examples=[
        ["a cat sitting on a couch"],
        ["a robot walking in the park"],
        ["a tree made of clouds"],
    ],
    title="TalkGPT Image Generation",
    description="Use AI to generate images based on a prompt.",
    allow_flagging=False,
    analytics_enabled=True,
    theme="compact"
)