AmirFARES commited on
Commit
aa5ec1b
ยท
1 Parent(s): f6b78b1

updated the home and info pages

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +87 -27
src/streamlit_app.py CHANGED
@@ -2,46 +2,106 @@ import streamlit as st
2
  from downloader import download_video
3
  from extractor import extract_audio
4
  from detector import detect_accent
5
-
6
  import asyncio
 
 
7
  try:
8
  asyncio.get_running_loop()
9
  except RuntimeError:
10
  loop = asyncio.new_event_loop()
11
  asyncio.set_event_loop(loop)
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
- st.set_page_config(page_title="Accent Detector", page_icon="๐ŸŽ™๏ธ")
 
15
 
16
- st.title("๐ŸŽ™๏ธ English Accent Classifier")
17
- st.write("Paste a public Loom or MP4 link to get an English accent classification.")
18
 
19
- # Input option (URL only)
20
- video_url = st.text_input("Video URL (MP4 or Loom):")
 
 
 
 
 
21
 
22
- # When user clicks Analyze
23
- if st.button("Analyze"):
24
 
25
- if not video_url:
26
- st.error("Please provide a video URL.")
27
- else:
28
- try:
29
- # Step 1: Download video
30
- with st.spinner("Downloading video..."):
31
- video_file_path = download_video(video_url)
32
 
33
- # Step 2: Extract audio
34
- with st.spinner("Extracting audio..."):
35
- audio_file = extract_audio(video_file_path)
36
 
37
- # Step 3: Detect accent
38
- with st.spinner("Transcribing & detecting accent..."):
39
- accent, confidence, transcript = detect_accent(audio_file)
40
 
41
- # Display results
42
- st.success(f"Accent: **{accent}**")
43
- st.metric(label="Confidence", value=f"{confidence}%")
44
- st.text_area("Transcript", transcript, height=150, disabled=True)
45
 
46
- except Exception as e:
47
- st.error(f"Error: {str(e)}")
 
2
  from downloader import download_video
3
  from extractor import extract_audio
4
  from detector import detect_accent
 
5
  import asyncio
6
+
7
+ # Setup async event loop
8
  try:
9
  asyncio.get_running_loop()
10
  except RuntimeError:
11
  loop = asyncio.new_event_loop()
12
  asyncio.set_event_loop(loop)
13
 
14
+ st.set_page_config(page_title="Accentometer", page_icon="๐ŸŽ™๏ธ")
15
+
16
+ # Sidebar navigation
17
+ st.sidebar.title("๐ŸŽ™๏ธ Accentometer")
18
+ page = st.sidebar.radio("", ["Home", "Info"])
19
+
20
+ # ---------------------------
21
+ # Page 1: Home
22
+ # ---------------------------
23
+ if page == "Home":
24
+ st.title("๐ŸŽ™๏ธ Accentometer")
25
+
26
+ # โœ… Example video links
27
+ st.markdown("### ๐ŸŽง Try with these example MP4 links:")
28
+
29
+ st.text("Australian: https://docs.google.com/uc?export=download&id=12dKoO-jgWgjor_aQpovbtwOulMQBEEps")
30
+ st.text("British: https://docs.google.com/uc?export=download&id=10aiY_0dnsWXqhxeNL54n5LYe6l4XquR8")
31
+ st.text("American: https://docs.google.com/uc?export=download&id=1k1wfSxmQ-ZbYCKNZrb0aF8xfM6JWEfKQ")
32
+
33
+ st.markdown("<br><br>", unsafe_allow_html=True)
34
+
35
+ st.write("Paste a direct public MP4 video URL to **classify the English accent, get transcript**.")
36
+
37
+ video_url = st.text_input("Direct Video URL (MP4 only):")
38
+
39
+ if st.button("Analyze"):
40
+ if not video_url:
41
+ st.error("Please provide a valid MP4 video URL.")
42
+ else:
43
+ try:
44
+ with st.spinner("Downloading video..."):
45
+ video_file_path = download_video(video_url)
46
+
47
+ with st.spinner("Extracting audio..."):
48
+ audio_file = extract_audio(video_file_path)
49
+
50
+ with st.spinner("Transcribing & detecting accent..."):
51
+ accent, confidence, transcript = detect_accent(audio_file)
52
+
53
+ st.success(f"Accent: **{accent}**")
54
+ st.metric(label="Confidence", value=f"{confidence}%")
55
+ st.text_area("Transcript", transcript, height=150, disabled=True)
56
+
57
+ except Exception as e:
58
+ st.error(f"Error: {str(e)}")
59
+
60
+
61
+ # ---------------------------
62
+ # Page 2: Info
63
+ # ---------------------------
64
+ elif page == "Info":
65
+
66
+ st.title("โ„น๏ธ About Accentometer")
67
+
68
+ st.markdown("""
69
+ ### ๐Ÿง  What is Accentometer?
70
+
71
+ **Accentometer** is a simple **demo** application for English accent classification.
72
+ It doesn't use any advanced machine learning or deep learning models beyond basic heuristics.
73
+
74
+ ---
75
+
76
+ ### โš™๏ธ How It Works
77
+
78
+ 1. **Video Downloader**
79
+ Accepts only **direct MP4 links**.
80
+ (Loom URLs arenโ€™t supported in this free demo version โ€” integration would require a paid Loom API or other backend setup.)
81
 
82
+ 2. **Audio Extraction**
83
+ Uses the `moviepy` library to extract the audio from the video.
84
 
85
+ 3. **Speech-to-Text**
86
+ Applies the `openai/whisper-base` model from Hugging Face to transcribe the audio into text.
87
 
88
+ 4. **Accent Detection**
89
+ Runs simple **hand-crafted heuristic rules** over the transcribed text to classify the accent into:
90
+ - ๐Ÿ‡บ๐Ÿ‡ธ American
91
+ - ๐Ÿ‡ฌ๐Ÿ‡ง British
92
+ - ๐Ÿ‡ฆ๐Ÿ‡บ Australian
93
+ - ๐Ÿ‡ฎ๐Ÿ‡ณ Indian
94
+ - โ“ Unknown
95
 
96
+ ---
 
97
 
98
+ ### ๐Ÿš€ Possible Improvements
 
 
 
 
 
 
99
 
100
+ If you're interested in expanding this demo into a more robust application:
 
 
101
 
102
+ - **Support More Input Options**: Upload local MP4 files, YouTube links, Loom links (via API), Additional video formats, etc.
103
+ - **Improve Accent Detection**: Train a custom model using a labeled accent dataset, or integrate a model like `accent-id-commonaccent_xlsr-en-english`, or other approaches.
 
104
 
105
+ ---
106
+ """)
 
 
107