File size: 1,148 Bytes
1902db3 a715ccc c4f1406 edebd7a a715ccc c4f1406 edebd7a a715ccc c4f1406 a715ccc c4f1406 a715ccc f30b5e5 a715ccc c4f1406 a715ccc c4f1406 a715ccc c4f1406 a715ccc c4f1406 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import streamlit as st
from transformers import pipeline
from gtts import gTTS
import os
# Load a fully public language model
@st.cache_resource(show_spinner="Loading language model...")
def load_llm():
return pipeline("text2text-generation",
model="google/flan-t5-base",
tokenizer="google/flan-t5-base")
llm = load_llm()
# Text-to-speech function
def speak(text, filename="response.mp3"):
tts = gTTS(text)
tts.save(filename)
audio_file = open(filename, "rb")
audio_bytes = audio_file.read()
st.audio(audio_bytes, format="audio/mp3")
os.remove(filename)
# Streamlit UI
st.set_page_config(page_title="AI Learning Buddy", page_icon="🧸")
st.title("🧸 AI Learning Buddy for Kids (Ages 4–7)")
st.markdown("Ask your question below and the AI Buddy will answer in a fun, friendly voice!")
user_input = st.text_input("Type your question (e.g., What's 2 + 3?):")
if st.button("Ask the Buddy") and user_input:
prompt = f"Explain to a 5-year-old: {user_input}"
result = llm(prompt)[0]["generated_text"]
st.markdown(f"**AI Buddy says:** {result}")
speak(result)
|