Update src/streamlit_app.py
Browse files- 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
|
7 |
-
@st.cache_resource(show_spinner="Loading
|
8 |
def load_llm():
|
9 |
return pipeline("text2text-generation",
|
10 |
-
model="google/flan-t5-
|
11 |
-
tokenizer="google/flan-t5-
|
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 |
-
audio_bytes
|
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
|
27 |
|
28 |
-
st.markdown("
|
29 |
|
30 |
-
user_input = st.text_input("
|
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}"
|