sss2000 commited on
Commit
d531300
1 Parent(s): a7fda38

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ mport streamlit as st
2
+ from transformers import pipeline
3
+
4
+ st.set_page_config(page_title="Your English audio to Chinese text,
5
+ page_icon="🦜")
6
+ st.header("Turn Your English Audio to Chinese text")
7
+ uploaded_file = st.file_uploader("Select an audio file",type=["mp3","mp4"])
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(model="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()