Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
examples=[
|
29 |
+
["a cat sitting on a couch"],
|
30 |
+
["a robot walking in the park"],
|
31 |
+
["a tree made of clouds"],
|
32 |
+
],
|
33 |
+
title="TalkGPT Image Generation",
|
34 |
+
description="Use AI to generate images based on a prompt.",
|
35 |
+
allow_flagging=False,
|
36 |
+
analytics_enabled=False,
|
37 |
+
theme="huggingface"
|
38 |
+
)
|