RafaelJaime commited on
Commit
0374251
1 Parent(s): 5b81c62

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -8
app.py CHANGED
@@ -26,14 +26,14 @@ def measure_performance(func):
26
  return wrapper
27
 
28
  @measure_performance
29
- def generate_story(theme):
30
  prompt = f"Tell me a storie about {theme}"
31
  story = generate_story_pipe(prompt, max_length=400, num_return_sequences=1, temperature=0.7, do_sample=True, repetition_penalty=3.0, eos_token_id=generate_story_pipe.model.config.eos_token_id, pad_token_id=generate_story_pipe.model.config.pad_token_id)
32
  generated_story = story[0]["generated_text"]
33
  return generated_story
34
 
35
  @measure_performance
36
- def gen_tts(text):
37
  audio_arr = generate_audio(text, history_prompt="es_speaker_0")
38
  audio_arr = (audio_arr * 32767).astype(np.int16)
39
  return (SAMPLE_RATE, audio_arr)
@@ -53,9 +53,9 @@ def generate_image(prompt):
53
 
54
  return image
55
 
56
- def generate_story_and_convert_to_audio(theme):
57
- story_text = generate_story(theme)
58
- return gen_tts(story_text)
59
 
60
  def subtitle():
61
  gr.Markdown("""
@@ -146,12 +146,11 @@ with gr.Blocks(css=css) as block:
146
  image_out = gr.Image(label="Generated image", show_label=False)
147
  run_button = gr.Button("Cuéntame la historia")
148
  run_button.click(fn=lambda: gr.update(visible=False), inputs=None, outputs=None, queue=False).then(
149
- fn=generate_story_and_convert_to_audio, inputs=[story_theme], outputs=[audio_out], queue=True).then(
150
- fn=lambda theme: generate_image(theme), inputs=[story_theme], outputs=[image_out], queue=True).then(
151
  fn=lambda: gr.update(visible=True), inputs=None, outputs=None, queue=False)
152
 
153
 
154
- gr.Examples(examples=examples, fn=[generate_story_and_convert_to_audio, generate_image], inputs=[story_theme],
155
  outputs=[audio_out, image_out], cache_examples=True)
156
  end_text()
157
 
 
26
  return wrapper
27
 
28
  @measure_performance
29
+ def generate_story_text(theme):
30
  prompt = f"Tell me a storie about {theme}"
31
  story = generate_story_pipe(prompt, max_length=400, num_return_sequences=1, temperature=0.7, do_sample=True, repetition_penalty=3.0, eos_token_id=generate_story_pipe.model.config.eos_token_id, pad_token_id=generate_story_pipe.model.config.pad_token_id)
32
  generated_story = story[0]["generated_text"]
33
  return generated_story
34
 
35
  @measure_performance
36
+ def generate_tts(text):
37
  audio_arr = generate_audio(text, history_prompt="es_speaker_0")
38
  audio_arr = (audio_arr * 32767).astype(np.int16)
39
  return (SAMPLE_RATE, audio_arr)
 
53
 
54
  return image
55
 
56
+ def generate_story(theme):
57
+ story_text = generate_story_text(theme)
58
+ return (generate_tts(story_text), generate_image(story_text))
59
 
60
  def subtitle():
61
  gr.Markdown("""
 
146
  image_out = gr.Image(label="Generated image", show_label=False)
147
  run_button = gr.Button("Cuéntame la historia")
148
  run_button.click(fn=lambda: gr.update(visible=False), inputs=None, outputs=None, queue=False).then(
149
+ fn=generate_story, inputs=[story_theme], outputs=[audio_out, image_out], queue=True).then(
 
150
  fn=lambda: gr.update(visible=True), inputs=None, outputs=None, queue=False)
151
 
152
 
153
+ gr.Examples(examples=examples, fn=generate_story, inputs=[story_theme],
154
  outputs=[audio_out, image_out], cache_examples=True)
155
  end_text()
156