sss2000 commited on
Commit
954468c
1 Parent(s): e9c6889

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -26
app.py CHANGED
@@ -1,43 +1,43 @@
1
  import streamlit as st
2
- import gradio as gr
3
  from transformers import pipeline
4
 
5
  st.set_page_config(page_title="Your English audio to Chinese text", page_icon="🦜")
6
  st.header("Turn Your English Audio to Chinese text")
7
- uploaded_file = st.file_uploader("Select an audio file")
8
 
9
- if uploaded_file is not None:
10
- print(uploaded_file)
11
- bytes_data = uploaded_file.getvalue()
12
- with open(uploaded_file.name, "wb") as file:
13
- file.write(bytes_data)
14
- st.image(uploaded_file, caption="Uploaded Audio",
15
- use_column_width=True)
16
-
17
- # function part
18
  def audio2txt(audioname):
19
- pipe = pipeline("Automatic-Speech-Recognition", model="avery0/pipeline1model2")
20
  rst = pipe(audioname)
21
  return rst
22
 
 
 
23
  def translation(txt):
24
- pipe = pipeline("translation", model="DDDSSS/translation_en-zh")
25
- rst = pipe(txt)
26
  return rst
27
 
28
-
29
  def main():
30
- #Stage 1: Aido to Text
31
- st.text('Processing audio2txt...')
32
- txt = audio2txt(uploaded_file.name)
33
- st.write(txt)
34
-
35
- #Stage 2: Text to Story
36
- st.text('Generating a translation...')
37
- txt2 = translation(txt)
38
- st.write(txt2)
39
-
 
 
 
 
 
 
 
 
40
 
41
- # main part
42
  if __name__ == "__main__":
43
  main()
 
1
  import streamlit as st
 
2
  from transformers import pipeline
3
 
4
  st.set_page_config(page_title="Your English audio to Chinese text", page_icon="🦜")
5
  st.header("Turn Your English Audio to Chinese text")
 
6
 
7
+ # Function to convert audio to text
8
+ @st.cache
 
 
 
 
 
 
 
9
  def audio2txt(audioname):
10
+ pipe = pipeline("automatic-speech-recognition", model="avery0/pipeline1model2")
11
  rst = pipe(audioname)
12
  return rst
13
 
14
+ # Function to translate text
15
+ @st.cache
16
  def translation(txt):
17
+ pipe = pipeline("translation_en_to_zh", model="DDDSSS/translation_en-zh")
18
+ rst = pipe(txt, max_length=40)
19
  return rst
20
 
21
+ # Main function
22
  def main():
23
+ uploaded_file = st.file_uploader("Select an audio file")
24
+
25
+ if uploaded_file is not None:
26
+ bytes_data = uploaded_file.getvalue()
27
+ with open(uploaded_file.name, "wb") as file:
28
+ file.write(bytes_data)
29
+
30
+ st.image(uploaded_file, caption="Uploaded Audio", use_column_width=True)
31
+
32
+ # Stage 1: Audio to Text
33
+ st.text('Processing audio2txt...')
34
+ txt = audio2txt(uploaded_file.name)
35
+ st.write(txt)
36
+
37
+ # Stage 2: Text to Translation
38
+ st.text('Generating a translation...')
39
+ txt2 = translation(txt)
40
+ st.write(txt2)
41
 
 
42
  if __name__ == "__main__":
43
  main()