Spaces:
Runtime error
Runtime error
Commit
·
b30324c
1
Parent(s):
755146c
init asr project
Browse files- Dockerfile +10 -0
- app.py +75 -0
- requiremets.txt +2 -0
- static/main_banner.png +0 -0
Dockerfile
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.8
|
2 |
+
RUN mkdir /app
|
3 |
+
WORKDIR /app
|
4 |
+
COPY requirements.txt .
|
5 |
+
|
6 |
+
RUN pip install -r requirements.txt
|
7 |
+
|
8 |
+
COPY . .
|
9 |
+
|
10 |
+
ENTRYPOINT ["streamlit", "run", "app.py", "--server.port=4000", "--server.address=0.0.0.0", "--client.showErrorDetails=false"]
|
app.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from PIL import Image
|
3 |
+
import os
|
4 |
+
import requests
|
5 |
+
|
6 |
+
|
7 |
+
ASR_API = os.environ['ASR_API']
|
8 |
+
|
9 |
+
def request_to_asr_service(audiofile):
|
10 |
+
|
11 |
+
# file_path = "/media/mohammadkrb/hddExt/personal_projects/vidabia/audio_tests/epit_sample.mp3"
|
12 |
+
# file_data = open(file_path, 'rb')
|
13 |
+
|
14 |
+
files = {'file': (audiofile)}
|
15 |
+
|
16 |
+
response = requests.post(ASR_API, files=files)
|
17 |
+
return response.json()
|
18 |
+
|
19 |
+
st.set_page_config(
|
20 |
+
page_title="Automatic Speech Recognition",
|
21 |
+
page_icon="🗣",
|
22 |
+
layout="centered",
|
23 |
+
initial_sidebar_state="auto",
|
24 |
+
)
|
25 |
+
|
26 |
+
upload_path = "uploads/"
|
27 |
+
download_path = "downloads/"
|
28 |
+
os.makedirs(upload_path, exist_ok=True)
|
29 |
+
os.makedirs(download_path, exist_ok=True)
|
30 |
+
# @st.cache(persist=True,allow_output_mutation=True,show_spinner=False,suppress_st_warning=True)
|
31 |
+
# def asr_inference_wav2vec2(uploaded_file):
|
32 |
+
# asr = Wave2Vec2Inference("facebook/wav2vec2-base-960h")
|
33 |
+
# text = asr.file_to_text(uploaded_file)
|
34 |
+
# return text
|
35 |
+
|
36 |
+
@st.cache(persist=True,allow_output_mutation=True,show_spinner=False,suppress_st_warning=True)
|
37 |
+
def save_text(text, downloaded_txt_file):
|
38 |
+
with open(downloaded_txt_file, 'w') as outtxt:
|
39 |
+
outtxt.write(text)
|
40 |
+
print(downloaded_txt_file)
|
41 |
+
|
42 |
+
@st.cache(persist=True,allow_output_mutation=True,show_spinner=False,suppress_st_warning=True)
|
43 |
+
def download_success():
|
44 |
+
st.balloons()
|
45 |
+
st.success('✅ Download Successful !!')
|
46 |
+
|
47 |
+
main_image = Image.open('static/main_banner.png')
|
48 |
+
|
49 |
+
st.image(main_image,use_column_width='auto')
|
50 |
+
st.title("🗣 Automatic Speech Recognition")
|
51 |
+
st.info('✨ Supports ALL Audio Formats (mp3, wav, ogg, ...).')
|
52 |
+
|
53 |
+
uploaded_file = st.file_uploader("Upload audio file", type=["wav"])
|
54 |
+
if uploaded_file is not None:
|
55 |
+
with open(os.path.join(upload_path,uploaded_file.name),"wb") as f:
|
56 |
+
f.write((uploaded_file).getbuffer())
|
57 |
+
with st.spinner(f"Converting speech to text... 💫"):
|
58 |
+
resp = request_to_asr_service(uploaded_file)
|
59 |
+
text = resp['transcript']
|
60 |
+
# text = asr_inference_wav2vec2(upload_path + uploaded_file.name)
|
61 |
+
st.info(text)
|
62 |
+
downloaded_txt_file = os.path.abspath(os.path.join(download_path,str("processed_"+uploaded_file.name.split(".")[0] + ".txt")))
|
63 |
+
save_text(text, downloaded_txt_file)
|
64 |
+
with open(downloaded_txt_file, "rb") as file:
|
65 |
+
if st.download_button(
|
66 |
+
label="Download ASR Output 🗣",
|
67 |
+
data=file,
|
68 |
+
file_name=str("ASR_output_"+uploaded_file.name.split(".")[0]+ ".txt"),
|
69 |
+
mime='text/plain'
|
70 |
+
):
|
71 |
+
download_success()
|
72 |
+
# else:
|
73 |
+
# st.warning("Please upload your file. Any other audio format is currently not supported")
|
74 |
+
|
75 |
+
st.markdown("<br><hr><center>Made with ❤️ by <a href='https://ahdsoft.ir'><strong>AHD Co</strong></a></center><hr>", unsafe_allow_html=True)
|
requiremets.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
PIL
|
static/main_banner.png
ADDED
![]() |