Spaces:
Build error
Build error
| import streamlit as st | |
| from transformers import pipeline | |
| st.set_page_config(page_title="SmartLearn Rwanda", page_icon="π") | |
| st.title("π SmartLearn Rwanda - AI Educational Tutor") | |
| # ----------------------------- | |
| # Input ya umunyeshuri | |
| # ----------------------------- | |
| name = st.text_input("Andika izina ryawe") | |
| level = st.selectbox("Hitamo icyiciro cyawe:", ["Primary", "Secondary", "High School"]) | |
| subject = st.selectbox("Hitamo isomo:", ["Mathematics", "Science", "English", "History"]) | |
| question = st.text_area("Andika ikibazo cyangwa aho utumva neza:") | |
| # ----------------------------- | |
| # Hugging Face model (text-generation) | |
| # ----------------------------- | |
| def load_model(): | |
| return pipeline("text-generation", model="tiiuae/falcon-7b-instruct", device=-1) # CPU-friendly | |
| qa_pipeline = load_model() | |
| # ----------------------------- | |
| # AI Tutor | |
| # ----------------------------- | |
| if st.button("Saba ibisobanuro"): | |
| if question.strip() == "": | |
| st.warning("Andika ikibazo mbere yo gukanda buto!") | |
| else: | |
| prompt = f""" | |
| Uri umwigisha w'inzobere. Umunyeshuri witwa {name}, ari mu cyiciro cya {level}, afite ikibazo muri {subject}: "{question}". | |
| Sobanura ikibazo mu buryo bworoshye kandi utange urugero rumwe mu Kinyarwanda. | |
| """ | |
| tutor_answer = qa_pipeline(prompt, max_length=300, do_sample=True, temperature=0.7) | |
| st.subheader("Ibisobanuro bya AI:") | |
| st.success(tutor_answer[0]['generated_text']) | |
| # ----------------------------- | |
| # Quiz Generator | |
| # ----------------------------- | |
| if st.button("Tegura quiz ku isomo"): | |
| quiz_prompt = f""" | |
| Uri umwigisha w'inzobere. Tegura ikibazo 3 by'imyitozo ku isomo {subject} mu cyiciro {level}, | |
| hamwe n'igisubizo cyiza kuri buri kibazo mu Kinyarwanda. | |
| """ | |
| quiz = qa_pipeline(quiz_prompt, max_length=400, do_sample=True, temperature=0.7) | |
| st.subheader("Quiz:") | |
| st.text(quiz[0]['generated_text']) | |
| # ----------------------------- | |
| # Automatic feedback | |
| # ----------------------------- | |
| st.markdown("### Automatic feedback ku gisubizo cyawe") | |
| answer_input = st.text_area("Andika igisubizo cyawe hano (kuri quiz)") | |
| if st.button("Genura feedback"): | |
| if answer_input.strip() == "": | |
| st.warning("Andika igisubizo cyawe mbere yo kubona feedback!") | |
| else: | |
| feedback_prompt = f""" | |
| Uri umwigisha w'inzobere. Soma igisubizo gikurikira: "{answer_input}". | |
| Sobanura niba gisubije neza, utange amanota 1-5, kandi utange inama yo kunoza mu Kinyarwanda. | |
| """ | |
| feedback = qa_pipeline(feedback_prompt, max_length=200, do_sample=True, temperature=0.7) | |
| st.subheader("Feedback y'AI:") | |
| st.success(feedback[0]['generated_text']) | |