bunyaminergen commited on
Commit
f31b8c7
·
1 Parent(s): 95af719
Files changed (1) hide show
  1. app.py +6 -8
app.py CHANGED
@@ -1,27 +1,25 @@
1
  import gradio as gr
2
- import openai
3
  import os
4
 
5
- openai.api_key = os.environ['OPENAI_API_KEY']
6
-
7
 
8
  def generate_story(topic):
9
  prompt = f"Write a short, creative, and fun children's story about the following topic:\n\nTopic: {topic}\n\nStory:"
10
- response = openai.ChatCompletion.create(
11
  model="gpt-3.5-turbo",
12
  messages=[{"role": "user", "content": prompt}],
13
- max_tokens=2048,
14
- temperature=0.1
15
  )
16
  story = response.choices[0].message.content.strip()
17
  return story
18
 
19
-
20
  iface = gr.Interface(
21
  fn=generate_story,
22
  inputs=gr.Textbox(label="Story Topic", placeholder="E.g., Adventures of a brave rabbit..."),
23
  outputs=gr.Textbox(label="Generated Story"),
24
- title="✨ UmaiMother ✨",
25
  description="Enter a topic, and a fun story will be automatically generated for you!"
26
  )
27
 
 
1
  import gradio as gr
2
+ from openai import OpenAI
3
  import os
4
 
5
+ client = OpenAI(api_key=os.environ['OPENAI_API_KEY'])
 
6
 
7
  def generate_story(topic):
8
  prompt = f"Write a short, creative, and fun children's story about the following topic:\n\nTopic: {topic}\n\nStory:"
9
+ response = client.chat.completions.create(
10
  model="gpt-3.5-turbo",
11
  messages=[{"role": "user", "content": prompt}],
12
+ max_tokens=500,
13
+ temperature=0.8
14
  )
15
  story = response.choices[0].message.content.strip()
16
  return story
17
 
 
18
  iface = gr.Interface(
19
  fn=generate_story,
20
  inputs=gr.Textbox(label="Story Topic", placeholder="E.g., Adventures of a brave rabbit..."),
21
  outputs=gr.Textbox(label="Generated Story"),
22
+ title="✨ Storyteller ✨",
23
  description="Enter a topic, and a fun story will be automatically generated for you!"
24
  )
25