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()