Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,7 +10,7 @@ from sklearn.metrics.pairwise import cosine_similarity
|
|
| 10 |
st.set_page_config(
|
| 11 |
page_title="Education with Fun",
|
| 12 |
layout="centered",
|
| 13 |
-
page_icon="
|
| 14 |
)
|
| 15 |
|
| 16 |
# --- Background Image ---
|
|
@@ -35,15 +35,15 @@ set_bg()
|
|
| 35 |
st.markdown(
|
| 36 |
"""
|
| 37 |
<div style='text-align: center; padding: 20px; background-color: rgba(255, 255, 255, 0.8); border-radius: 15px;'>
|
| 38 |
-
<h1 style='color: green;'
|
| 39 |
<h4>Learn Science with Stories and Audio (Grade 5 & 6)</h4>
|
| 40 |
</div>
|
| 41 |
""", unsafe_allow_html=True
|
| 42 |
)
|
| 43 |
|
| 44 |
# --- Grade & Subject Selection ---
|
| 45 |
-
grade = st.selectbox("
|
| 46 |
-
subject = st.selectbox("
|
| 47 |
|
| 48 |
# --- Search online content ---
|
| 49 |
def search_online_syllabus(grade, subject):
|
|
@@ -83,8 +83,8 @@ def get_answer(user_question, syllabus_text):
|
|
| 83 |
top_idx = cosine_similarities.argmax()
|
| 84 |
best_chunk = chunks[top_idx]
|
| 85 |
|
| 86 |
-
beginner = f"
|
| 87 |
-
story = f"
|
| 88 |
return beginner, story
|
| 89 |
|
| 90 |
# --- Urdu Text-to-Speech ---
|
|
@@ -99,18 +99,18 @@ st.markdown("### ❓ Ask your question (Urdu or English):")
|
|
| 99 |
question = st.text_area("", placeholder="e.g., What is evaporation? / بخارات کیا ہوتے ہیں؟")
|
| 100 |
|
| 101 |
# --- Submit Button ---
|
| 102 |
-
if st.button("
|
| 103 |
-
with st.spinner("
|
| 104 |
syllabus_text = search_online_syllabus(grade, subject)
|
| 105 |
|
| 106 |
beginner, story = get_answer(question, syllabus_text)
|
| 107 |
|
| 108 |
-
st.subheader("
|
| 109 |
st.success(beginner)
|
| 110 |
|
| 111 |
-
st.subheader("
|
| 112 |
st.info(story)
|
| 113 |
|
| 114 |
-
if st.button("
|
| 115 |
audio_path = text_to_speech_urdu(beginner + "۔ " + story)
|
| 116 |
st.audio(audio_path, format='audio/mp3')
|
|
|
|
| 10 |
st.set_page_config(
|
| 11 |
page_title="Education with Fun",
|
| 12 |
layout="centered",
|
| 13 |
+
page_icon="📘" # Changed to string emoji for compatibility
|
| 14 |
)
|
| 15 |
|
| 16 |
# --- Background Image ---
|
|
|
|
| 35 |
st.markdown(
|
| 36 |
"""
|
| 37 |
<div style='text-align: center; padding: 20px; background-color: rgba(255, 255, 255, 0.8); border-radius: 15px;'>
|
| 38 |
+
<h1 style='color: green;'>📘 Education with Fun</h1>
|
| 39 |
<h4>Learn Science with Stories and Audio (Grade 5 & 6)</h4>
|
| 40 |
</div>
|
| 41 |
""", unsafe_allow_html=True
|
| 42 |
)
|
| 43 |
|
| 44 |
# --- Grade & Subject Selection ---
|
| 45 |
+
grade = st.selectbox("🎓 Select Grade:", ["Grade 5", "Grade 6"])
|
| 46 |
+
subject = st.selectbox("📚 Select Subject:", ["Science"])
|
| 47 |
|
| 48 |
# --- Search online content ---
|
| 49 |
def search_online_syllabus(grade, subject):
|
|
|
|
| 83 |
top_idx = cosine_similarities.argmax()
|
| 84 |
best_chunk = chunks[top_idx]
|
| 85 |
|
| 86 |
+
beginner = f"📗 سیدھا سا جواب: {best_chunk}"
|
| 87 |
+
story = f"📙 کہانی کی صورت میں: ایک دن ایک طالب علم نے پوچھا، '{user_question}'۔ استاد نے جواب دیا: {best_chunk}"
|
| 88 |
return beginner, story
|
| 89 |
|
| 90 |
# --- Urdu Text-to-Speech ---
|
|
|
|
| 99 |
question = st.text_area("", placeholder="e.g., What is evaporation? / بخارات کیا ہوتے ہیں؟")
|
| 100 |
|
| 101 |
# --- Submit Button ---
|
| 102 |
+
if st.button("🔍 Get Answer"):
|
| 103 |
+
with st.spinner("📡 Searching online syllabus..."):
|
| 104 |
syllabus_text = search_online_syllabus(grade, subject)
|
| 105 |
|
| 106 |
beginner, story = get_answer(question, syllabus_text)
|
| 107 |
|
| 108 |
+
st.subheader("💡 Beginner-Friendly Answer:")
|
| 109 |
st.success(beginner)
|
| 110 |
|
| 111 |
+
st.subheader("📖 Storytelling Style Answer:")
|
| 112 |
st.info(story)
|
| 113 |
|
| 114 |
+
if st.button("🔈 Hear Urdu Audio"):
|
| 115 |
audio_path = text_to_speech_urdu(beginner + "۔ " + story)
|
| 116 |
st.audio(audio_path, format='audio/mp3')
|