Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,27 +12,33 @@ def generate_image(api_key, prompt):
|
|
| 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
|
| 24 |
openai.api_key = api_key
|
| 25 |
response = openai.Completion.create(
|
| 26 |
-
model="
|
| 27 |
prompt=f"Title: {story_title}\n\nIn a fantasy world, {names} embarked on an absurd and funny journey. {names}",
|
| 28 |
max_tokens=150
|
| 29 |
)
|
| 30 |
story = response.choices[0].text.strip()
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
return story, *images
|
| 33 |
|
| 34 |
iface = gr.Interface(
|
| 35 |
-
fn=
|
| 36 |
inputs=[
|
| 37 |
gr.components.Textbox(label="OpenAI API Key", type="password"),
|
| 38 |
gr.components.Textbox(label="Enter names (comma-separated for multiple)"),
|
|
@@ -48,4 +54,4 @@ iface = gr.Interface(
|
|
| 48 |
live=True
|
| 49 |
)
|
| 50 |
|
| 51 |
-
iface.launch()
|
|
|
|
| 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 |
+
def create_dalle_prompt(story, story_title):
|
| 23 |
+
return f"Visual representation of the fantasy story titled '{story_title}': {story}"
|
| 24 |
|
| 25 |
+
def generate_story_and_images(api_key, names, story_title):
|
| 26 |
openai.api_key = api_key
|
| 27 |
response = openai.Completion.create(
|
| 28 |
+
model="gpt-3.5-turbo",
|
| 29 |
prompt=f"Title: {story_title}\n\nIn a fantasy world, {names} embarked on an absurd and funny journey. {names}",
|
| 30 |
max_tokens=150
|
| 31 |
)
|
| 32 |
story = response.choices[0].text.strip()
|
| 33 |
+
|
| 34 |
+
# Create a DALLE prompt using the story
|
| 35 |
+
dalle_prompt = create_dalle_prompt(story, story_title)
|
| 36 |
+
images = [generate_image(api_key, f"{dalle_prompt} - Scene {i}") for i in range(1, 5)]
|
| 37 |
+
|
| 38 |
return story, *images
|
| 39 |
|
| 40 |
iface = gr.Interface(
|
| 41 |
+
fn=generate_story_and_images,
|
| 42 |
inputs=[
|
| 43 |
gr.components.Textbox(label="OpenAI API Key", type="password"),
|
| 44 |
gr.components.Textbox(label="Enter names (comma-separated for multiple)"),
|
|
|
|
| 54 |
live=True
|
| 55 |
)
|
| 56 |
|
| 57 |
+
iface.launch()
|