Bondya commited on
Commit
76bead5
·
verified ·
1 Parent(s): a9942bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -10
app.py CHANGED
@@ -11,14 +11,21 @@ def img2text(img):
11
  return text
12
 
13
  # text2story
14
- def text2story(text):
15
- story_text = "" # to be completed
16
- return story_text
 
 
 
 
 
17
 
18
  # text2audio
19
  def text2audio(story_text):
20
- audio_data = "" # to be completed
21
- return audio_data
 
 
22
 
23
 
24
  # main
@@ -42,13 +49,15 @@ if uploaded_file is not None:
42
 
43
  #Stage 2: Text to Story
44
  st.text('Generating a story...')
45
- #story = text2story(scenario)
46
- #st.write(story)
 
47
 
48
  #Stage 3: Story to Audio data
49
- #st.text('Generating audio data...')
50
- #audio_data =text2audio(story)
51
-
 
52
  # Play button
53
  if st.button("Play Audio"):
54
  #st.audio(audio_data['audio'],
 
11
  return text
12
 
13
  # text2story
14
+ def text2story(scenario):
15
+ generator = pipeline("text-generation", model="gpt2")
16
+ story = generator(
17
+ f"Create a children's story based on: {scenario}",
18
+ max_length=300,
19
+ num_return_sequences=1
20
+ )
21
+ return story[0]["generated_text"]
22
 
23
  # text2audio
24
  def text2audio(story_text):
25
+ tts = gTTS(text=story_text, lang="en", slow=False)
26
+ audio_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp3")
27
+ tts.save(audio_file.name)
28
+ return audio_file.name
29
 
30
 
31
  # main
 
49
 
50
  #Stage 2: Text to Story
51
  st.text('Generating a story...')
52
+ story = text2story(scenario)
53
+ st.subheader("Generated Story")
54
+ st.success(story)
55
 
56
  #Stage 3: Story to Audio data
57
+ st.text('Generating audio data...')
58
+ audio_data =text2audio(story)
59
+ st.subheader("Audio Story")
60
+ st.audio(audio_path, format="audio/mp3")
61
  # Play button
62
  if st.button("Play Audio"):
63
  #st.audio(audio_data['audio'],