siviku commited on
Commit
9becbf3
·
verified ·
1 Parent(s): c4f1406

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +9 -10
src/streamlit_app.py CHANGED
@@ -3,31 +3,30 @@ from transformers import pipeline
3
  from gtts import gTTS
4
  import os
5
 
6
- # Load a fully public language model
7
- @st.cache_resource(show_spinner="Loading language model...")
8
  def load_llm():
9
  return pipeline("text2text-generation",
10
- model="google/flan-t5-base",
11
- tokenizer="google/flan-t5-base")
12
 
13
  llm = load_llm()
14
 
15
- # Text-to-speech function
16
  def speak(text, filename="response.mp3"):
17
  tts = gTTS(text)
18
  tts.save(filename)
19
  audio_file = open(filename, "rb")
20
- audio_bytes = audio_file.read()
21
- st.audio(audio_bytes, format="audio/mp3")
22
  os.remove(filename)
23
 
24
  # Streamlit UI
25
  st.set_page_config(page_title="AI Learning Buddy", page_icon="🧸")
26
- st.title("🧸 AI Learning Buddy for Kids (Ages 4–7)")
27
 
28
- st.markdown("Ask your question below and the AI Buddy will answer in a fun, friendly voice!")
29
 
30
- user_input = st.text_input("Type your question (e.g., What's 2 + 3?):")
31
 
32
  if st.button("Ask the Buddy") and user_input:
33
  prompt = f"Explain to a 5-year-old: {user_input}"
 
3
  from gtts import gTTS
4
  import os
5
 
6
+ # Load small public instruction model
7
+ @st.cache_resource(show_spinner="Loading AI Buddy...")
8
  def load_llm():
9
  return pipeline("text2text-generation",
10
+ model="google/flan-t5-small",
11
+ tokenizer="google/flan-t5-small")
12
 
13
  llm = load_llm()
14
 
15
+ # Text-to-speech
16
  def speak(text, filename="response.mp3"):
17
  tts = gTTS(text)
18
  tts.save(filename)
19
  audio_file = open(filename, "rb")
20
+ st.audio(audio_bytes := audio_file.read(), format="audio/mp3")
 
21
  os.remove(filename)
22
 
23
  # Streamlit UI
24
  st.set_page_config(page_title="AI Learning Buddy", page_icon="🧸")
25
+ st.title("🧸 AI Learning Buddy (Ages 4–7)")
26
 
27
+ st.markdown("Type a fun question and hear the AI Buddy reply!")
28
 
29
+ user_input = st.text_input("Ask your question:")
30
 
31
  if st.button("Ask the Buddy") and user_input:
32
  prompt = f"Explain to a 5-year-old: {user_input}"