Spaces:
Sleeping
Sleeping
added upload option
Browse files- src/streamlit_app.py +43 -19
src/streamlit_app.py
CHANGED
|
@@ -6,24 +6,48 @@ from detector import detect_accent
|
|
| 6 |
st.set_page_config(page_title="Accent Detector", page_icon="๐๏ธ")
|
| 7 |
|
| 8 |
st.title("๐๏ธ English Accent Classifier")
|
| 9 |
-
st.write("Paste a public Loom or MP4 link
|
| 10 |
|
|
|
|
| 11 |
video_url = st.text_input("Video URL (MP4 or Loom):")
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
st.set_page_config(page_title="Accent Detector", page_icon="๐๏ธ")
|
| 7 |
|
| 8 |
st.title("๐๏ธ English Accent Classifier")
|
| 9 |
+
st.write("Paste a public Loom or MP4 link OR upload a video file to get an English accent classification.")
|
| 10 |
|
| 11 |
+
# Input options:
|
| 12 |
video_url = st.text_input("Video URL (MP4 or Loom):")
|
| 13 |
+
uploaded_file = st.file_uploader("Or upload a video file (MP4)", type=["mp4"])
|
| 14 |
+
|
| 15 |
+
# When user clicks Analyze
|
| 16 |
+
if st.button("Analyze"):
|
| 17 |
+
|
| 18 |
+
# Validate input
|
| 19 |
+
if not video_url and not uploaded_file:
|
| 20 |
+
st.error("Please provide a video URL or upload a video file.")
|
| 21 |
+
else:
|
| 22 |
+
try:
|
| 23 |
+
# Step 1: get the video file path for extractor
|
| 24 |
+
|
| 25 |
+
if uploaded_file is not None:
|
| 26 |
+
# uploaded_file is BytesIO-like object
|
| 27 |
+
# We need to save it to a temporary file path for extract_audio()
|
| 28 |
+
import tempfile
|
| 29 |
+
|
| 30 |
+
with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as tmp:
|
| 31 |
+
tmp.write(uploaded_file.read())
|
| 32 |
+
video_file_path = tmp.name
|
| 33 |
+
|
| 34 |
+
else:
|
| 35 |
+
# Download video from URL to local file path (your existing function)
|
| 36 |
+
with st.spinner("Downloading video..."):
|
| 37 |
+
video_file_path = download_video(video_url)
|
| 38 |
+
|
| 39 |
+
# Step 2: extract audio
|
| 40 |
+
with st.spinner("Extracting audio..."):
|
| 41 |
+
audio_file = extract_audio(video_file_path)
|
| 42 |
+
|
| 43 |
+
# Step 3: detect accent
|
| 44 |
+
with st.spinner("Transcribing & detecting accent..."):
|
| 45 |
+
accent, confidence, transcript = detect_accent(audio_file)
|
| 46 |
+
|
| 47 |
+
# Display results
|
| 48 |
+
st.success(f"Accent: **{accent}**")
|
| 49 |
+
st.metric(label="Confidence", value=f"{confidence}%")
|
| 50 |
+
st.text_area("Transcript", transcript, height=150)
|
| 51 |
+
|
| 52 |
+
except Exception as e:
|
| 53 |
+
st.error(f"Error: {str(e)}")
|