Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| # Skills + lessons + quizzes | |
| knowledge = { | |
| "Gusudira": { | |
| "lessons": [ | |
| "Ambara gloves na goggles mbere yo gusudira, menya safety.", | |
| "Menya ubwoko bwa welding: MIG, TIG, Arc. Practice simple joints.", | |
| "Advanced Welding: Complex joints, maintain safety, practice daily." | |
| ], | |
| "quiz": [ | |
| {"q": "Ni ibiki ugomba kwambara mbere yo gusudira?", "a": "gloves na goggles"}, | |
| {"q": "Ni ubuhe bwoko bwa welding bw'ibanze?", "a": "simple joints"}, | |
| {"q": "Ni iki ugomba gukora buri munsi?", "a": "practice daily"} | |
| ] | |
| }, | |
| "Ububaji": { | |
| "lessons": [ | |
| "Hammer na Saw ni ibikoresho by'ingenzi, ambara gloves.", | |
| "Measure, cut wood, assemble furniture basics.", | |
| "Advanced Carpentry: Cabinets, shelves, daily practice." | |
| ], | |
| "quiz": [ | |
| {"q": "Ni ibikoresho by'ingenzi mu bubaji?", "a": "hammer na saw"}, | |
| {"q": "Ni iki ugomba gukora mbere yo gutema ibiti?", "a": "measure"}, | |
| {"q": "Ni iki ugomba gukora buri munsi?", "a": "practice daily"} | |
| ] | |
| } | |
| } | |
| user_progress = {} | |
| def get_skill(user_input, dropdown_skill): | |
| if dropdown_skill and dropdown_skill != "Hitamo skill": | |
| return dropdown_skill | |
| text = user_input.lower() | |
| for skill in knowledge.keys(): | |
| if skill.lower() in text: | |
| return skill | |
| return None | |
| def vocational_ai(voice_input, dropdown_skill, user_name="Student", answer=None): | |
| skill = get_skill(voice_input, dropdown_skill) | |
| if not skill: | |
| return "Sinamenye umwuga. Sobanura neza icyo ushaka kwiga.", None, None | |
| if user_name not in user_progress: | |
| user_progress[user_name] = {"skill": skill, "lesson": 0} | |
| else: | |
| if user_progress[user_name]["skill"] != skill: | |
| user_progress[user_name] = {"skill": skill, "lesson": 0} | |
| else: | |
| lesson_index = user_progress[user_name]["lesson"] | |
| if answer: | |
| correct_answer = knowledge[skill]["quiz"][lesson_index]["a"].lower() | |
| if answer.strip().lower() == correct_answer: | |
| user_progress[user_name]["lesson"] += 1 | |
| else: | |
| return f"β Igisubizo cyawe ntabwo ari cyo. Gerageza ugenzure quiz:", knowledge[skill]["quiz"][lesson_index]["q"], None | |
| lesson_index = user_progress[user_name]["lesson"] | |
| if lesson_index >= len(knowledge[skill]["lessons"]): | |
| return f"π Congratulations {user_name}! You have completed all lessons for {skill}.", None, None | |
| lesson_text = knowledge[skill]["lessons"][lesson_index] | |
| quiz_q = knowledge[skill]["quiz"][lesson_index]["q"] | |
| # Modern card-style message | |
| response_text = f""" | |
| π¦ **{skill} - Lesson {lesson_index+1}** | |
| {lesson_text} | |
| π© **Quiz:** | |
| {quiz_q} | |
| """ | |
| return response_text, quiz_q, None | |
| # Super modern Blocks interface | |
| with gr.Blocks() as iface: | |
| gr.Markdown("# π Vocational AI β Super Modern Learning") | |
| gr.Markdown("Vuga cyangwa uhitemo skill, AI izagusubiza mu Kinyarwanda kandi ikurikirane quiz.") | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| voice_input = gr.Audio(sources=["microphone"], type="filepath", label="π€ Vuga umwuga wifuza kwiga") | |
| dropdown_skill = gr.Dropdown(["Hitamo skill"] + list(knowledge.keys()), label="π Hitamo skill") | |
| user_name = gr.Textbox(label="π§ Izina ryawe", placeholder="John Doe") | |
| answer = gr.Textbox(label="βοΈ Subiza Quiz", placeholder="Andika igisubizo hano, optional") | |
| submit_btn = gr.Button("βΆοΈ Tangira Lesson / Submit Quiz") | |
| with gr.Column(scale=2): | |
| lesson_output = gr.Markdown(label="π Lesson & Quiz Card") | |
| quiz_output = gr.Textbox(label="π Quiz Question", interactive=False) | |
| feedback_output = gr.Textbox(label="π¬ Feedback", interactive=False) | |
| submit_btn.click( | |
| fn=vocational_ai, | |
| inputs=[voice_input, dropdown_skill, user_name, answer], | |
| outputs=[lesson_output, quiz_output, feedback_output] | |
| ) | |
| iface.launch() |