Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,17 +6,20 @@ import os as os
|
|
| 6 |
openai.api_key = os.environ.get('openai-api')
|
| 7 |
|
| 8 |
#Functions
|
| 9 |
-
def generate_story(character1, character2, character3, character4, localizer, agefor, language):
|
| 10 |
-
agefor = min(max(agefor,
|
| 11 |
|
| 12 |
# Define the prompt
|
| 13 |
prompt = f'A story about {character1}, {character2}, {character3}, and {character4}, set in {localizer}.' \
|
| 14 |
-
f'The story is intended for a child aged {agefor}.'
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
# Define the request to the OpenAI API
|
| 17 |
-
response = openai.
|
| 18 |
engine="gpt-3.5-turbo",
|
| 19 |
-
prompt=
|
| 20 |
temperature=0.9,
|
| 21 |
max_tokens=1000
|
| 22 |
)
|
|
@@ -35,14 +38,17 @@ with gr.Blocks() as demo:
|
|
| 35 |
with gr.Row():
|
| 36 |
content = gr.Textbox(label="What you want to hear about in this story", placeholder= "a giant elephant eating pink banana, a broken chair, ...")
|
| 37 |
with gr.Row():
|
| 38 |
-
|
|
|
|
|
|
|
| 39 |
agefor = gr.Slider(minimum=0, maximum=20, step=1, default=10, label="Age of the child")
|
| 40 |
-
language = gr.Dropdown(choices=["Mandarin", "Cantonese", "French", "English", "Korean", "Italian", "German", "Russian"], label="Language of the story")
|
| 41 |
with gr.Row():
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
| 46 |
|
| 47 |
demo.launch()
|
| 48 |
|
|
|
|
| 6 |
openai.api_key = os.environ.get('openai-api')
|
| 7 |
|
| 8 |
#Functions
|
| 9 |
+
def generate_story(character1, character2, character3, character4, localizer, agefor, language, wordstouse):
|
| 10 |
+
agefor = min(max(agefor, 2), 20) # Ensure agefor is between 0 and 20
|
| 11 |
|
| 12 |
# Define the prompt
|
| 13 |
prompt = f'A story about {character1}, {character2}, {character3}, and {character4}, set in {localizer}.' \
|
| 14 |
+
f'The story is intended for a child aged {agefor}.' \
|
| 15 |
+
f'As much as possible use words that are in this list: {wordstouse}.'
|
| 16 |
+
|
| 17 |
+
inject = [{"role":"user", "content":f"prompt"}]
|
| 18 |
|
| 19 |
# Define the request to the OpenAI API
|
| 20 |
+
response = openai.ChatCompletion.create(
|
| 21 |
engine="gpt-3.5-turbo",
|
| 22 |
+
prompt=inject,
|
| 23 |
temperature=0.9,
|
| 24 |
max_tokens=1000
|
| 25 |
)
|
|
|
|
| 38 |
with gr.Row():
|
| 39 |
content = gr.Textbox(label="What you want to hear about in this story", placeholder= "a giant elephant eating pink banana, a broken chair, ...")
|
| 40 |
with gr.Row():
|
| 41 |
+
wordstouse = gr.Textbox(label="Words for reading", info="Put here the words you would like the child to train on, not compulstory", placeholder= "the then car if this ...")
|
| 42 |
+
with gr.Row():
|
| 43 |
+
localizer = gr.Textbox(label="Location", value="Hong Kong", placeholder="Location")
|
| 44 |
agefor = gr.Slider(minimum=0, maximum=20, step=1, default=10, label="Age of the child")
|
| 45 |
+
language = gr.Dropdown(choices=["Mandarin", "Cantonese", "French", "English", "Korean", "Italian", "German", "Russian"], label="Language of the story", value="English")
|
| 46 |
with gr.Row():
|
| 47 |
+
btn = gr.Button("Make me a bed time story")
|
| 48 |
+
with gr.Row():
|
| 49 |
+
out = gr.Textbox(label="Here's my story")
|
| 50 |
+
|
| 51 |
+
btn.click(fn=generate_story, inputs=[character1, character2, character3, character4, localizer, agefor, language, wordstouse], outputs=out)
|
| 52 |
|
| 53 |
demo.launch()
|
| 54 |
|