Update src/streamlit_app.py
Browse files- src/streamlit_app.py +11 -8
src/streamlit_app.py
CHANGED
@@ -3,12 +3,12 @@ from transformers import pipeline
|
|
3 |
from gtts import gTTS
|
4 |
import os
|
5 |
|
6 |
-
# Load
|
7 |
@st.cache_resource(show_spinner="Loading language model...")
|
8 |
def load_llm():
|
9 |
return pipeline("text-generation",
|
10 |
-
model="
|
11 |
-
tokenizer="
|
12 |
max_new_tokens=100,
|
13 |
do_sample=True,
|
14 |
temperature=0.7)
|
@@ -24,17 +24,20 @@ 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 (4–7)")
|
30 |
|
31 |
-
st.markdown("Ask
|
32 |
|
33 |
-
|
|
|
34 |
|
35 |
if st.button("Ask the Buddy") and user_input:
|
36 |
-
prompt = f"You are a
|
37 |
result = llm(prompt)[0]["generated_text"]
|
38 |
answer = result.split("Answer:")[-1].strip()
|
|
|
|
|
39 |
st.markdown(f"**AI Buddy says:** {answer}")
|
40 |
speak(answer)
|
|
|
3 |
from gtts import gTTS
|
4 |
import os
|
5 |
|
6 |
+
# Load a safe, instruction-tuned language model
|
7 |
@st.cache_resource(show_spinner="Loading language model...")
|
8 |
def load_llm():
|
9 |
return pipeline("text-generation",
|
10 |
+
model="mistralai/Mistral-7B-Instruct-v0.1",
|
11 |
+
tokenizer="mistralai/Mistral-7B-Instruct-v0.1",
|
12 |
max_new_tokens=100,
|
13 |
do_sample=True,
|
14 |
temperature=0.7)
|
|
|
24 |
st.audio(audio_bytes, format="audio/mp3")
|
25 |
os.remove(filename)
|
26 |
|
27 |
+
# UI setup
|
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 anything fun or educational — math, animals, colors, or stories!")
|
32 |
|
33 |
+
# Input field
|
34 |
+
user_input = st.text_input("Type your question:")
|
35 |
|
36 |
if st.button("Ask the Buddy") and user_input:
|
37 |
+
prompt = f"You are a kind, fun teacher for a 5-year-old child. Answer in a simple and cheerful tone.\n\nQuestion: {user_input}\nAnswer:"
|
38 |
result = llm(prompt)[0]["generated_text"]
|
39 |
answer = result.split("Answer:")[-1].strip()
|
40 |
+
|
41 |
+
# Output
|
42 |
st.markdown(f"**AI Buddy says:** {answer}")
|
43 |
speak(answer)
|