Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,8 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import pipeline,
|
3 |
import pyttsx3
|
4 |
import random
|
|
|
5 |
|
6 |
# Set up the app
|
7 |
st.set_page_config(page_title="ChiliDron", layout="wide", page_icon="π¨")
|
@@ -13,13 +14,13 @@ def load_storytelling_model():
|
|
13 |
|
14 |
@st.cache_resource
|
15 |
def load_phoneme_model():
|
16 |
-
model =
|
17 |
-
|
18 |
-
return model,
|
19 |
|
20 |
# Load models
|
21 |
story_generator = load_storytelling_model()
|
22 |
-
phoneme_model,
|
23 |
|
24 |
# Initialize TTS engine
|
25 |
def initialize_tts():
|
@@ -81,17 +82,16 @@ elif options == "Phoneme Practice":
|
|
81 |
st.header("π€ Phoneme Practice")
|
82 |
st.write("Learn how to pronounce words correctly!")
|
83 |
|
84 |
-
|
85 |
-
|
86 |
-
if
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
st.warning("Please enter a word to practice.")
|
95 |
|
96 |
# Guided Meditation for Kids
|
97 |
elif options == "Guided Meditation":
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import pipeline, AutoModelForCTC, AutoProcessor, Wav2Vec2ForCTC
|
3 |
import pyttsx3
|
4 |
import random
|
5 |
+
import torchaudio
|
6 |
|
7 |
# Set up the app
|
8 |
st.set_page_config(page_title="ChiliDron", layout="wide", page_icon="π¨")
|
|
|
14 |
|
15 |
@st.cache_resource
|
16 |
def load_phoneme_model():
|
17 |
+
model = Wav2Vec2ForCTC.from_pretrained("mirfan899/kids_phoneme_sm_model")
|
18 |
+
processor = AutoProcessor.from_pretrained("mirfan899/kids_phoneme_sm_model")
|
19 |
+
return model, processor
|
20 |
|
21 |
# Load models
|
22 |
story_generator = load_storytelling_model()
|
23 |
+
phoneme_model, phoneme_processor = load_phoneme_model()
|
24 |
|
25 |
# Initialize TTS engine
|
26 |
def initialize_tts():
|
|
|
82 |
st.header("π€ Phoneme Practice")
|
83 |
st.write("Learn how to pronounce words correctly!")
|
84 |
|
85 |
+
uploaded_audio = st.file_uploader("Upload an audio file to analyze phonemes", type=["wav", "mp3"])
|
86 |
+
|
87 |
+
if uploaded_audio:
|
88 |
+
with st.spinner("Analyzing phonemes..."):
|
89 |
+
audio_input, _ = torchaudio.load(uploaded_audio)
|
90 |
+
input_values = phoneme_processor(audio_input, return_tensors="pt", sampling_rate=16000).input_values
|
91 |
+
logits = phoneme_model(input_values).logits
|
92 |
+
predicted_ids = torch.argmax(logits, dim=-1)
|
93 |
+
transcription = phoneme_processor.batch_decode(predicted_ids)
|
94 |
+
st.write(f"Transcription: {transcription[0]}")
|
|
|
95 |
|
96 |
# Guided Meditation for Kids
|
97 |
elif options == "Guided Meditation":
|