Update src/streamlit_app.py
Browse files- src/streamlit_app.py +11 -18
src/streamlit_app.py
CHANGED
@@ -3,19 +3,16 @@ from transformers import pipeline
|
|
3 |
from gtts import gTTS
|
4 |
import os
|
5 |
|
6 |
-
# Load a
|
7 |
@st.cache_resource(show_spinner="Loading language model...")
|
8 |
def load_llm():
|
9 |
-
return pipeline("
|
10 |
-
model="
|
11 |
-
tokenizer="
|
12 |
-
max_new_tokens=100,
|
13 |
-
do_sample=True,
|
14 |
-
temperature=0.7)
|
15 |
|
16 |
llm = load_llm()
|
17 |
|
18 |
-
#
|
19 |
def speak(text, filename="response.mp3"):
|
20 |
tts = gTTS(text)
|
21 |
tts.save(filename)
|
@@ -24,20 +21,16 @@ def speak(text, filename="response.mp3"):
|
|
24 |
st.audio(audio_bytes, format="audio/mp3")
|
25 |
os.remove(filename)
|
26 |
|
27 |
-
# UI
|
28 |
st.set_page_config(page_title="AI Learning Buddy", page_icon="🧸")
|
29 |
st.title("🧸 AI Learning Buddy for Kids (Ages 4–7)")
|
30 |
|
31 |
-
st.markdown("Ask
|
32 |
|
33 |
-
|
34 |
-
user_input = st.text_input("Type your question:")
|
35 |
|
36 |
if st.button("Ask the Buddy") and user_input:
|
37 |
-
prompt = f"
|
38 |
result = llm(prompt)[0]["generated_text"]
|
39 |
-
|
40 |
-
|
41 |
-
# Output
|
42 |
-
st.markdown(f"**AI Buddy says:** {answer}")
|
43 |
-
speak(answer)
|
|
|
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)
|
|
|
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}"
|
34 |
result = llm(prompt)[0]["generated_text"]
|
35 |
+
st.markdown(f"**AI Buddy says:** {result}")
|
36 |
+
speak(result)
|
|
|
|
|
|