Aniquel commited on
Commit
ee103d5
1 Parent(s): 9b119cf

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ from PIL import Image
4
+ from io import BytesIO
5
+
6
+ # Define the function that generates the image
7
+ def generate_image(prompt):
8
+ response = requests.post("https://api.openai.com/v1/images/generations", json={
9
+ "model": "image-alpha-001",
10
+ "prompt": prompt,
11
+ "num_images": 4,
12
+ "size": "1024x1024",
13
+ "response_format": "url"
14
+ }, headers={
15
+ "Content-Type": "application/json",
16
+ "Authorization": "Bearer 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"
17
+ })
18
+ response.raise_for_status()
19
+ image_url = response.json()["data"][0]["url"]
20
+ image = Image.open(BytesIO(requests.get(image_url).content))
21
+ return image
22
+
23
+
24
+ iface = gr.Interface(
25
+ fn=generate_image,
26
+ inputs=gr.inputs.Textbox(label="Enter Prompt Here"),
27
+ outputs="image",
28
+
29
+ examples=[
30
+ ["a cat sitting on a couch"],
31
+ ["a robot walking in the park"],
32
+ ["a tree made of clouds"],
33
+ ],
34
+ title="TalkGPT Image Generation",
35
+ description="Use AI to generate images based on a prompt.",
36
+ allow_flagging=Never,
37
+ analytics_enabled=True,
38
+ theme="huggingface"
39
+ )