Blessin commited on
Commit
f2b54b6
·
1 Parent(s): 6539ee9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -16
app.py CHANGED
@@ -2,10 +2,7 @@ import gradio as gr
2
  import openai
3
 
4
  def generate_image(api_key, prompt):
5
- # Initialize OpenAI with the provided API key
6
  openai.api_key = api_key
7
-
8
- # Generate the image
9
  response = openai.Image.create(
10
  prompt=prompt,
11
  n=1,
@@ -15,35 +12,29 @@ def generate_image(api_key, prompt):
15
  return image_url
16
 
17
  def generate_story(api_key, names, story_title):
18
- # Initialize OpenAI with the provided API key
19
  openai.api_key = api_key
20
-
21
- # Generate the story
22
  response = openai.Completion.create(
23
  model="text-davinci-003",
24
  prompt=f"Title: {story_title}\n\nIn a fantasy world, {names} embarked on an absurd and funny journey. {names}",
25
  max_tokens=150
26
  )
27
  story = response.choices[0].text.strip()
28
-
29
- # Generate 4 images inspired by the story title
30
  images = [generate_image(api_key, f"Fantasy image inspired by {story_title} - Scene {i}") for i in range(1, 5)]
31
-
32
  return story, *images
33
 
34
  iface = gr.Interface(
35
  fn=generate_story,
36
  inputs=[
37
- gr.inputs.Textbox(label="OpenAI API Key", type="password"),
38
- gr.inputs.Textbox(label="Enter names (comma-separated for multiple)"),
39
- gr.inputs.Textbox(label="Enter story title")
40
  ],
41
  outputs=[
42
  "text",
43
- gr.outputs.Image(label="Image 1"),
44
- gr.outputs.Image(label="Image 2"),
45
- gr.outputs.Image(label="Image 3"),
46
- gr.outputs.Image(label="Image 4")
47
  ],
48
  live=True
49
  )
 
2
  import openai
3
 
4
  def generate_image(api_key, prompt):
 
5
  openai.api_key = api_key
 
 
6
  response = openai.Image.create(
7
  prompt=prompt,
8
  n=1,
 
12
  return image_url
13
 
14
  def generate_story(api_key, names, story_title):
 
15
  openai.api_key = api_key
 
 
16
  response = openai.Completion.create(
17
  model="text-davinci-003",
18
  prompt=f"Title: {story_title}\n\nIn a fantasy world, {names} embarked on an absurd and funny journey. {names}",
19
  max_tokens=150
20
  )
21
  story = response.choices[0].text.strip()
 
 
22
  images = [generate_image(api_key, f"Fantasy image inspired by {story_title} - Scene {i}") for i in range(1, 5)]
 
23
  return story, *images
24
 
25
  iface = gr.Interface(
26
  fn=generate_story,
27
  inputs=[
28
+ gr.components.Textbox(label="OpenAI API Key", type="password"),
29
+ gr.components.Textbox(label="Enter names (comma-separated for multiple)"),
30
+ gr.components.Textbox(label="Enter story title")
31
  ],
32
  outputs=[
33
  "text",
34
+ gr.components.Image(label="Image 1", type="url"),
35
+ gr.components.Image(label="Image 2", type="url"),
36
+ gr.components.Image(label="Image 3", type="url"),
37
+ gr.components.Image(label="Image 4", type="url")
38
  ],
39
  live=True
40
  )