Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
10 |
-
|
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("
|
20 |
rst = pipe(audioname)
|
21 |
return rst
|
22 |
|
|
|
|
|
23 |
def translation(txt):
|
24 |
-
pipe = pipeline("
|
25 |
-
rst = pipe(txt)
|
26 |
return rst
|
27 |
|
28 |
-
|
29 |
def main():
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
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()
|