AmirFARES commited on
Commit
d0dd89e
ยท
1 Parent(s): 8514b46

added upload option

Browse files
Files changed (1) hide show
  1. 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 and get an English accent classification.")
10
 
 
11
  video_url = st.text_input("Video URL (MP4 or Loom):")
12
-
13
- if st.button("Analyze") and video_url:
14
- try:
15
- with st.spinner("Downloading video..."):
16
- video_file = download_video(video_url)
17
-
18
- with st.spinner("Extracting audio..."):
19
- audio_file = extract_audio(video_file)
20
-
21
- with st.spinner("Transcribing & detecting accent..."):
22
- accent, confidence, transcript = detect_accent(audio_file)
23
-
24
- st.success(f"Accent: **{accent}**")
25
- st.metric(label="Confidence", value=f"{confidence}%")
26
- st.text_area("Transcript", transcript, height=150)
27
-
28
- except Exception as e:
29
- st.error(f"Error: {str(e)}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)}")