Spaces:
Build error
Build error
Create gradio_dalle.py
Browse files- gradio_dalle.py +25 -0
gradio_dalle.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import openai
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
|
| 6 |
+
load_dotenv()
|
| 7 |
+
|
| 8 |
+
def generate_image(prompt):
|
| 9 |
+
response = openai.images.generate(
|
| 10 |
+
model="dall-e-3",
|
| 11 |
+
prompt=prompt,
|
| 12 |
+
size="1024x1024",
|
| 13 |
+
quality="standard",
|
| 14 |
+
n=1,
|
| 15 |
+
)
|
| 16 |
+
return response.data[0].url
|
| 17 |
+
|
| 18 |
+
app = gr.Interface(
|
| 19 |
+
fn=generate_image,
|
| 20 |
+
inputs=gr.Textbox(label="Describe your image"),
|
| 21 |
+
outputs=gr.Image(label="Generated Image"),
|
| 22 |
+
title="DALL-E Image Generator"
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
app.launch()
|