Jessiesj commited on
Commit
7126d3c
·
verified ·
1 Parent(s): 4a6d038

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -30
app.py CHANGED
@@ -3,28 +3,28 @@ from transformers import pipeline
3
 
4
  # function part
5
  # img2text
6
- def img2text(url):
7
- image_to_text_model = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
8
- text = image_to_text_model(url)[0]["generated_text"]
9
- return text
10
 
11
- # text2story
12
- def text2story(text):
13
- text_to_story = pipeline("text-generation", model="isarth/distill_gpt2_story_generator",
14
- max_length=300, # 增加最大生成长度
15
- min_length=100, # 设置最小生成长度
16
- do_sample=True, # 启用随机采样
17
- temperature=0.9, # 控制随机性(0-1,越大越随机)
18
- top_k=50, # 限制候选词数量
19
- top_p=0.95, # 核采样参数
20
- repetition_penalty=1.2)
21
- # story_text = "" # to be completed
22
- story_text = text_to_story(text)[0]["generated_text"]
23
- return story_text
24
 
25
  # text2audio
26
  def text2audio(story_text):
27
- text_to_audio = pipeline("text-to-audio", model="facebook/musicgen-medium")
28
  audio_data = text_to_audio(story_text)
29
  return audio_data
30
 
@@ -43,22 +43,23 @@ if uploaded_file is not None:
43
 
44
  #Stage 1: Image to Text
45
  st.text('Processing img2text...')
46
- scenario = img2text(uploaded_file.name)
47
- st.write(scenario)
48
 
49
  #Stage 2: Text to Story
50
  st.text('Generating a story...')
51
- story = text2story(scenario)
 
52
  st.write(story)
53
 
54
- # #Stage 3: Story to Audio data
55
- # st.text('Generating audio data...')
56
- # audio_data =text2audio(story)
57
 
58
- # # Play button
59
- # if st.button("Play Audio"):
60
- # st.audio(audio_data['audio'],
61
- # format="audio/wav",
62
- # start_time=0,
63
- # sample_rate = audio_data['sampling_rate'])
64
  # # st.audio("kids_playing_audio.wav")
 
3
 
4
  # function part
5
  # img2text
6
+ # def img2text(url):
7
+ # image_to_text_model = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
8
+ # text = image_to_text_model(url)[0]["generated_text"]
9
+ # return text
10
 
11
+ # # text2story
12
+ # def text2story(text):
13
+ # text_to_story = pipeline("text-generation", model="isarth/distill_gpt2_story_generator",
14
+ # max_length=300, # 增加最大生成长度
15
+ # min_length=100, # 设置最小生成长度
16
+ # do_sample=True, # 启用随机采样
17
+ # temperature=0.9, # 控制随机性(0-1,越大越随机)
18
+ # top_k=50, # 限制候选词数量
19
+ # top_p=0.95, # 核采样参数
20
+ # repetition_penalty=1.2)
21
+ # # story_text = "" # to be completed
22
+ # story_text = text_to_story(text)[0]["generated_text"]
23
+ # return story_text
24
 
25
  # text2audio
26
  def text2audio(story_text):
27
+ text_to_audio = ("text-to-speech", model="facebook/mms-tts-vie")
28
  audio_data = text_to_audio(story_text)
29
  return audio_data
30
 
 
43
 
44
  #Stage 1: Image to Text
45
  st.text('Processing img2text...')
46
+ # scenario = img2text(uploaded_file.name)
47
+ # st.write(scenario)
48
 
49
  #Stage 2: Text to Story
50
  st.text('Generating a story...')
51
+ # story = text2story(scenario)
52
+ story = "children playing in the park illustration and making fun of other characters. The film opens with a character named 'Sooja (Saabani) visiting his friend, Maithana Sarajan's house when they are not able to make any money from their loan by calling him at some stage which would be very difficult for them due lack on time-consuming situations; she had been told that it was going too far as if he could just get away once more without paying off the interest charges; her brother is worried about how much trouble Srinivasa will have between himself while studying abroad where one day someone gets hurt, then starts screaming "Hoopaam", so I'll take care." In another scene A girl tries desperately unsuccessfully vainly trying repeatedly all sorts tricks but no matter what happens before being caught alive or left behind, she becomes quite hysterical after seeing this movie again: It begins out loud singing like a child who wants nothing less than an old man dancing to dance outside a bank window, every little thing happening throughout its course takes place within seconds… At first sight however - although there isn't anything like that real action scenes such people often seem oblivious – it really shows how hard things can go through during childhood times! All these events show up together well into adulthood. This movie ends back towards home life at various stages showing great improvement including improvement along both lines until we know why many youngsters need those moments instead!! That said...the story concludes with...another series"
53
  st.write(story)
54
 
55
+ #Stage 3: Story to Audio data
56
+ st.text('Generating audio data...')
57
+ audio_data =text2audio(story)
58
 
59
+ # Play button
60
+ if st.button("Play Audio"):
61
+ st.audio(audio_data['audio'],
62
+ format="audio/wav",
63
+ start_time=0,
64
+ sample_rate = audio_data['sampling_rate'])
65
  # # st.audio("kids_playing_audio.wav")