Spaces:
Paused
Paused
Added age settings
Browse files
app.py
CHANGED
@@ -46,19 +46,19 @@ def join_wav_files(input_files, output_file):
|
|
46 |
with wave.open(input_file, 'rb') as input:
|
47 |
output.writeframes(input.readframes(input.getnframes()))
|
48 |
|
49 |
-
def generate_story(text, lang):
|
50 |
"""Generate a story using the langchain library and OpenAI's GPT-3 model."""
|
51 |
prompt = PromptTemplate(
|
52 |
-
input_variables=["text", "lang"],
|
53 |
template="""
|
54 |
You are a fun and seasoned storyteller.
|
55 |
-
Generate a short bedtime story for a
|
56 |
Your story must be written in {lang}.
|
57 |
Use short sentences. The story is not too long, but not too short either.
|
58 |
"""
|
59 |
)
|
60 |
story = LLMChain(llm=llm, prompt=prompt)
|
61 |
-
story_result = story.run(text=text, lang=lang)
|
62 |
print(story_result)
|
63 |
print("""
|
64 |
—
|
@@ -92,8 +92,8 @@ def generate_story(text, lang):
|
|
92 |
|
93 |
return story_result, 'output.mp3'
|
94 |
|
95 |
-
def app(text, lang):
|
96 |
-
story = generate_story(text, lang)
|
97 |
return story
|
98 |
|
99 |
css = """
|
@@ -122,13 +122,14 @@ with gr.Blocks(css=css) as demo:
|
|
122 |
|
123 |
with gr.Group():
|
124 |
text = gr.Textbox(label="Subject: what the story should be about ?", info="Will generate and tell a story about {your text input}")
|
125 |
-
|
126 |
-
|
|
|
127 |
submit_btn = gr.Button('Submit')
|
128 |
|
129 |
audio = gr.Audio(label="The story audio told")
|
130 |
story = gr.Textbox(label="The story text")
|
131 |
|
132 |
-
submit_btn.click(fn=app, inputs=[text, lang], outputs=[story, audio])
|
133 |
|
134 |
demo.launch()
|
|
|
46 |
with wave.open(input_file, 'rb') as input:
|
47 |
output.writeframes(input.readframes(input.getnframes()))
|
48 |
|
49 |
+
def generate_story(text, lang, age):
|
50 |
"""Generate a story using the langchain library and OpenAI's GPT-3 model."""
|
51 |
prompt = PromptTemplate(
|
52 |
+
input_variables=["text", "lang", "age"],
|
53 |
template="""
|
54 |
You are a fun and seasoned storyteller.
|
55 |
+
Generate a short bedtime story for a {age} years old audience about {text}.
|
56 |
Your story must be written in {lang}.
|
57 |
Use short sentences. The story is not too long, but not too short either.
|
58 |
"""
|
59 |
)
|
60 |
story = LLMChain(llm=llm, prompt=prompt)
|
61 |
+
story_result = story.run(text=text, lang=lang, age=age)
|
62 |
print(story_result)
|
63 |
print("""
|
64 |
—
|
|
|
92 |
|
93 |
return story_result, 'output.mp3'
|
94 |
|
95 |
+
def app(text, lang, age):
|
96 |
+
story = generate_story(text, lang, age)
|
97 |
return story
|
98 |
|
99 |
css = """
|
|
|
122 |
|
123 |
with gr.Group():
|
124 |
text = gr.Textbox(label="Subject: what the story should be about ?", info="Will generate and tell a story about {your text input}")
|
125 |
+
with gr.Row():
|
126 |
+
lang = gr.Dropdown(label="Pick a language", choices=["English", "French", "German", "Hindi", "Italian", "Polish", "Portuguese", "Spanish"], value="English")
|
127 |
+
age = gr.Dropdown(label="Age target", choices=["3","4","5","6","7"], value="5")
|
128 |
submit_btn = gr.Button('Submit')
|
129 |
|
130 |
audio = gr.Audio(label="The story audio told")
|
131 |
story = gr.Textbox(label="The story text")
|
132 |
|
133 |
+
submit_btn.click(fn=app, inputs=[text, lang, age], outputs=[story, audio])
|
134 |
|
135 |
demo.launch()
|