Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,8 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import openai
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
def generate_image(api_key, prompt):
|
| 5 |
openai.api_key = api_key
|
|
@@ -9,7 +12,13 @@ def generate_image(api_key, prompt):
|
|
| 9 |
size="1024x1024"
|
| 10 |
)
|
| 11 |
image_url = response['data'][0]['url']
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
def generate_story(api_key, names, story_title):
|
| 15 |
openai.api_key = api_key
|
|
@@ -31,12 +40,12 @@ iface = gr.Interface(
|
|
| 31 |
],
|
| 32 |
outputs=[
|
| 33 |
"text",
|
| 34 |
-
gr.components.Image(label="Image 1", type="
|
| 35 |
-
gr.components.Image(label="Image 2", type="
|
| 36 |
-
gr.components.Image(label="Image 3", type="
|
| 37 |
-
gr.components.Image(label="Image 4", type="
|
| 38 |
],
|
| 39 |
live=True
|
| 40 |
)
|
| 41 |
|
| 42 |
-
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import openai
|
| 3 |
+
import requests
|
| 4 |
+
from PIL import Image
|
| 5 |
+
from io import BytesIO
|
| 6 |
|
| 7 |
def generate_image(api_key, prompt):
|
| 8 |
openai.api_key = api_key
|
|
|
|
| 12 |
size="1024x1024"
|
| 13 |
)
|
| 14 |
image_url = response['data'][0]['url']
|
| 15 |
+
|
| 16 |
+
# Download the image and open it with PIL
|
| 17 |
+
response = requests.get(image_url)
|
| 18 |
+
image = Image.open(BytesIO(response.content))
|
| 19 |
+
|
| 20 |
+
return image
|
| 21 |
+
|
| 22 |
|
| 23 |
def generate_story(api_key, names, story_title):
|
| 24 |
openai.api_key = api_key
|
|
|
|
| 40 |
],
|
| 41 |
outputs=[
|
| 42 |
"text",
|
| 43 |
+
gr.components.Image(label="Image 1", type="pil"),
|
| 44 |
+
gr.components.Image(label="Image 2", type="pil"),
|
| 45 |
+
gr.components.Image(label="Image 3", type="pil"),
|
| 46 |
+
gr.components.Image(label="Image 4", type="pil")
|
| 47 |
],
|
| 48 |
live=True
|
| 49 |
)
|
| 50 |
|
| 51 |
+
iface.launch()
|