mohAhmad commited on
Commit
60d035f
β€’
1 Parent(s): 8da67e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -16
app.py CHANGED
@@ -1,7 +1,8 @@
1
  import streamlit as st
2
- from transformers import pipeline, AutoModelForSeq2SeqLM, AutoTokenizer
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 = AutoModelForSeq2SeqLM.from_pretrained("mirfan899/kids_phoneme_sm_model")
17
- tokenizer = AutoTokenizer.from_pretrained("mirfan899/kids_phoneme_sm_model")
18
- return model, tokenizer
19
 
20
  # Load models
21
  story_generator = load_storytelling_model()
22
- phoneme_model, phoneme_tokenizer = load_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
- word_to_practice = st.text_input("Enter a word to practice its phonemes:")
85
-
86
- if st.button("Get Phonemes"):
87
- if word_to_practice:
88
- with st.spinner("Analyzing phonemes..."):
89
- inputs = phoneme_tokenizer.encode(word_to_practice, return_tensors="pt")
90
- outputs = phoneme_model.generate(inputs)
91
- phonemes = phoneme_tokenizer.decode(outputs[0], skip_special_tokens=True)
92
- st.write(f"Phonemes for '{word_to_practice}': {phonemes}")
93
- else:
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":