Commit History

import gradio as gr from transformers import pipeline from fpdf import FPDF import tempfile import os import sqlite3 import hashlib # ====================== # DATABASE SETUP # ====================== conn = sqlite3.connect("teachers.db", check_same_thread=False) c = conn.cursor() c.execute("""CREATE TABLE IF NOT EXISTS users ( username TEXT PRIMARY KEY, password TEXT )""") conn.commit() # ====================== # USER MANAGEMENT # ====================== def add_user(username, password): hashed = hashlib.sha256(password.encode()).hexdigest() try: c.execute("INSERT INTO users (username, password) VALUES (?, ?)", (username, hashed)) conn.commit() return f"User {username} added successfully!" except sqlite3.IntegrityError: return f"User {username} already exists." def login_user(username, password): hashed = hashlib.sha256(password.encode()).hexdigest() c.execute("SELECT * FROM users WHERE username=? AND password=?", (username, hashed)) return c.fetchone() is not None # ====================== # LOAD MODEL # ====================== generator = pipeline( "text2text-generation", model="google/flan-t5-base", max_new_tokens=800, do_sample=True, temperature=0.7 ) # ====================== # PDF FUNCTION # ====================== def make_pdf(text): font_path = "DejaVuSans.ttf" if not os.path.exists(font_path): raise FileNotFoundError("Font file 'DejaVuSans.ttf' not found in python.appy folder.") with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp: pdf = FPDF() pdf.add_page() pdf.set_auto_page_break(auto=True, margin=15) pdf.add_font("DejaVu", "", font_path, uni=True) pdf.set_font("DejaVu", "", 12) pdf.multi_cell(0, 8, text) pdf.output(tmp.name) return tmp.name # ====================== # EDUCATIONAL FUNCTIONS # ====================== def lesson_plan(info, level, language): prompt = f""" Uri AI ifasha abarimu bo mu Rwanda. Kurikiza REB curriculum. Tegura LESSON PLAN yuzuye ku rwego rwa {level}. Koresha ururimi: {language}. Amakuru: {info} Format: Class & Subject Topic Objectives Materials Lesson Steps Assessment Homework """ text = generator(prompt)[0]["generated_text"] pdf_file = make_pdf(text) return text, pdf_file def exams(info, level, language): prompt = f""" Uri AI itegura EXAMS & QUIZZES. Kurikiza REB curriculum. Urwego: {level} Ururimi: {language} Amakuru: {info} Tegura: - 5 Multiple Choice - 5 Short Answer - Total Marks """ text = generator(prompt)[0]["generated_text"] pdf_file = make_pdf(text) return text, pdf_file def marking_scheme(info, level, language): prompt = f""" Uri AI ikora MARKING SCHEME y'ikizamini. Kurikiza REB curriculum. Urwego: {level} Ururimi: {language} Ikizamini: {info} Subiza: - Question - Expected Answer - Marks """ text = generator(prompt)[0]["generated_text"] pdf_file = make_pdf(text) return text, pdf_file def scheme_of_work(info, level, language): prompt = f""" Uri AI ikora SCHEME OF WORK. Kurikiza REB curriculum. Urwego: {level} Ururimi: {language} Amakuru: {info} Tegura table ikubiyemo: Week | Topic | Objectives | Activities | Assessment """ text = generator(prompt)[0]["generated_text"] pdf_file = make_pdf(text) return text, pdf_file # ====================== # GRADIO UI # ====================== with gr.Blocks(title="AI Ifasha Abarimu (REB)") as app: # Track login state login_state = gr.State(False) # --- LOGIN / REGISTER TAB --- with gr.Tab("πŸ”‘ Login / Register"): gr.Markdown("### Injira cyangwa wiyandikishe") username = gr.Textbox(label="Username") password = gr.Textbox(label="Password", type="password") login_btn = gr.Button("Login") register_btn = gr.Button("Register") login_status = gr.Textbox(label="Status") logout_btn = gr.Button("Logout", visible=False) # Login function def do_login(u, p, state): success = login_user(u, p) if success: return f"Welcome {u}!", True, gr.update(visible=True) else: return "Invalid username or password", False, gr.update(visible=False) login_btn.click(do_login, [username, password, login_state], [login_status, login_state, logout_btn]) register_btn.click(add_user, [username, password], login_status) # Logout function def do_logout(): return gr.update(value="Logged out"), False, gr.update(visible=False) logout_btn.click(do_logout, [], [login_status, login_state, logout_btn]) # --- INPUTS (always visible) --- info = gr.Textbox(lines=6, label="Andika amakuru (subject, topic, class, term, etc)") level = gr.Dropdown(["Primary", "Secondary"], label="Level") language = gr.Dropdown(["Ikinyarwanda", "English"], label="Ururimi") # --- MAIN FUNCTIONALITY TABS --- with gr.Tab("πŸ“˜ Lesson Plan") as lp_tab: lp_out = gr.Textbox(label="Lesson Plan Text") lp_pdf = gr.File(label="Download PDF") gr.Button("Generate").click(lesson_plan, [info, level, language], [lp_out, lp_pdf]) with gr.Tab("πŸ“ Exams & Quizzes") as ex_tab: ex_out = gr.Textbox(label="Exams Text") ex_pdf = gr.File(label="Download PDF") gr.Button("Generate").click(exams, [info, level, language], [ex_out, ex_pdf]) with gr.Tab("πŸ“Š Marking Scheme") as ms_tab: ms_out = gr.Textbox(label="Marking Scheme Text") ms_pdf = gr.File(label="Download PDF") gr.Button("Generate").click(marking_scheme, [info, level, language], [ms_out, ms_pdf]) with gr.Tab("πŸ“š Scheme of Work") as sw_tab: sw_out = gr.Textbox(label="Scheme of Work Text") sw_pdf = gr.File(label="Download PDF") gr.Button("Generate").click(scheme_of_work, [info, level, language], [sw_out, sw_pdf]) # --- Show/Hide main tabs depending on login --- def toggle_main_tabs(is_logged_in): return gr.update(visible=is_logged_in), gr.update(visible=is_logged_in), gr.update(visible=is_logged_in), gr.update(visible=is_logged_in) login_state.change(toggle_main_tabs, login_state, [lp_tab, ex_tab, ms_tab, sw_tab]) app.launch()
11baccd
verified

VIATEUR-AI commited on

import gradio as gr from transformers import pipeline from fpdf import FPDF import tempfile import os import sqlite3 import hashlib # ====================== # DATABASE SETUP # ====================== conn = sqlite3.connect("teachers.db", check_same_thread=False) c = conn.cursor() c.execute("""CREATE TABLE IF NOT EXISTS users ( username TEXT PRIMARY KEY, password TEXT )""") conn.commit() # ====================== # USER MANAGEMENT # ====================== def add_user(username, password): hashed = hashlib.sha256(password.encode()).hexdigest() try: c.execute("INSERT INTO users (username, password) VALUES (?, ?)", (username, hashed)) conn.commit() return f"User {username} added successfully!" except sqlite3.IntegrityError: return f"User {username} already exists." def login_user(username, password): hashed = hashlib.sha256(password.encode()).hexdigest() c.execute("SELECT * FROM users WHERE username=? AND password=?", (username, hashed)) return c.fetchone() is not None # ====================== # LOAD MODEL # ====================== generator = pipeline( "text2text-generation", model="google/flan-t5-base", max_new_tokens=800, do_sample=True, temperature=0.7 ) # ====================== # PDF FUNCTION # ====================== def make_pdf(text): font_path = "DejaVuSans.ttf" if not os.path.exists(font_path): raise FileNotFoundError("Font file 'DejaVuSans.ttf' not found in python.appy folder.") with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp: pdf = FPDF() pdf.add_page() pdf.set_auto_page_break(auto=True, margin=15) pdf.add_font("DejaVu", "", font_path, uni=True) pdf.set_font("DejaVu", "", 12) pdf.multi_cell(0, 8, text) pdf.output(tmp.name) return tmp.name # ====================== # EDUCATIONAL FUNCTIONS # ====================== def lesson_plan(info, level, language): prompt = f""" Uri AI ifasha abarimu bo mu Rwanda. Kurikiza REB curriculum. Tegura LESSON PLAN yuzuye ku rwego rwa {level}. Koresha ururimi: {language}. Amakuru: {info} Format: Class & Subject Topic Objectives Materials Lesson Steps Assessment Homework """ text = generator(prompt)[0]["generated_text"] pdf_file = make_pdf(text) return text, pdf_file def exams(info, level, language): prompt = f""" Uri AI itegura EXAMS & QUIZZES. Kurikiza REB curriculum. Urwego: {level} Ururimi: {language} Amakuru: {info} Tegura: - 5 Multiple Choice - 5 Short Answer - Total Marks """ text = generator(prompt)[0]["generated_text"] pdf_file = make_pdf(text) return text, pdf_file def marking_scheme(info, level, language): prompt = f""" Uri AI ikora MARKING SCHEME y'ikizamini. Kurikiza REB curriculum. Urwego: {level} Ururimi: {language} Ikizamini: {info} Subiza: - Question - Expected Answer - Marks """ text = generator(prompt)[0]["generated_text"] pdf_file = make_pdf(text) return text, pdf_file def scheme_of_work(info, level, language): prompt = f""" Uri AI ikora SCHEME OF WORK. Kurikiza REB curriculum. Urwego: {level} Ururimi: {language} Amakuru: {info} Tegura table ikubiyemo: Week | Topic | Objectives | Activities | Assessment """ text = generator(prompt)[0]["generated_text"] pdf_file = make_pdf(text) return text, pdf_file # ====================== # GRADIO UI # ====================== with gr.Blocks(title="AI Ifasha Abarimu (REB)") as app: # Track login state login_state = gr.State(False) # --- LOGIN / REGISTER TAB --- with gr.Tab("πŸ”‘ Login / Register"): gr.Markdown("### Injira cyangwa wiyandikishe") username = gr.Textbox(label="Username") password = gr.Textbox(label="Password", type="password") login_btn = gr.Button("Login") register_btn = gr.Button("Register") login_status = gr.Textbox(label="Status") def do_login(u, p, state): success = login_user(u, p) if success: return f"Welcome {u}!", True else: return "Invalid username or password", False login_btn.click(do_login, [username, password, login_state], [login_status, login_state]) register_btn.click(add_user, [username, password], login_status) # --- MAIN FUNCTIONALITY TABS --- with gr.Tab("πŸ“˜ Lesson Plan") as lp_tab: lp_out = gr.Textbox(label="Lesson Plan Text") lp_pdf = gr.File(label="Download PDF") gr.Button("Generate").click(lesson_plan, [info, level, language], [lp_out, lp_pdf]) with gr.Tab("πŸ“ Exams & Quizzes") as ex_tab: ex_out = gr.Textbox(label="Exams Text") ex_pdf = gr.File(label="Download PDF") gr.Button("Generate").click(exams, [info, level, language], [ex_out, ex_pdf]) with gr.Tab("πŸ“Š Marking Scheme") as ms_tab: ms_out = gr.Textbox(label="Marking Scheme Text") ms_pdf = gr.File(label="Download PDF") gr.Button("Generate").click(marking_scheme, [info, level, language], [ms_out, ms_pdf]) with gr.Tab("πŸ“š Scheme of Work") as sw_tab: sw_out = gr.Textbox(label="Scheme of Work Text") sw_pdf = gr.File(label="Download PDF") gr.Button("Generate").click(scheme_of_work, [info, level, language], [sw_out, sw_pdf]) # Hide main tabs if not logged in def toggle_tabs(is_logged_in): return gr.update(visible=is_logged_in), gr.update(visible=is_logged_in), gr.update(visible=is_logged_in), gr.update(visible=is_logged_in) login_state.change(toggle_tabs, login_state, [lp_tab, ex_tab, ms_tab, sw_tab]) app.launch()
5c3f054
verified

VIATEUR-AI commited on

import gradio as gr from transformers import pipeline from fpdf import FPDF import tempfile import os import sqlite3 import hashlib # ====================== # DATABASE SETUP # ====================== conn = sqlite3.connect("teachers.db", check_same_thread=False) c = conn.cursor() c.execute("""CREATE TABLE IF NOT EXISTS users ( username TEXT PRIMARY KEY, password TEXT )""") conn.commit() # ====================== # USER MANAGEMENT # ====================== def add_user(username, password): hashed = hashlib.sha256(password.encode()).hexdigest() try: c.execute("INSERT INTO users (username, password) VALUES (?, ?)", (username, hashed)) conn.commit() return f"User {username} added successfully!" except sqlite3.IntegrityError: return f"User {username} already exists." def login_user(username, password): hashed = hashlib.sha256(password.encode()).hexdigest() c.execute("SELECT * FROM users WHERE username=? AND password=?", (username, hashed)) return c.fetchone() is not None # ====================== # LOAD MODEL # ====================== generator = pipeline( "text2text-generation", model="google/flan-t5-base", max_new_tokens=800, do_sample=True, temperature=0.7 ) # ====================== # PDF FUNCTION # ====================== def make_pdf(text): font_path = "DejaVuSans.ttf" if not os.path.exists(font_path): raise FileNotFoundError("Font file 'DejaVuSans.ttf' not found in python.appy folder.") with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp: pdf = FPDF() pdf.add_page() pdf.set_auto_page_break(auto=True, margin=15) pdf.add_font("DejaVu", "", font_path, uni=True) pdf.set_font("DejaVu", "", 12) pdf.multi_cell(0, 8, text) pdf.output(tmp.name) return tmp.name # ====================== # EDUCATIONAL FUNCTIONS # ====================== def lesson_plan(info, level, language): prompt = f""" Uri AI ifasha abarimu bo mu Rwanda. Kurikiza REB curriculum. Tegura LESSON PLAN yuzuye ku rwego rwa {level}. Koresha ururimi: {language}. Amakuru: {info} Format: Class & Subject Topic Objectives Materials Lesson Steps Assessment Homework """ text = generator(prompt)[0]["generated_text"] pdf_file = make_pdf(text) return text, pdf_file def exams(info, level, language): prompt = f""" Uri AI itegura EXAMS & QUIZZES. Kurikiza REB curriculum. Urwego: {level} Ururimi: {language} Amakuru: {info} Tegura: - 5 Multiple Choice - 5 Short Answer - Total Marks """ text = generator(prompt)[0]["generated_text"] pdf_file = make_pdf(text) return text, pdf_file def marking_scheme(info, level, language): prompt = f""" Uri AI ikora MARKING SCHEME y'ikizamini. Kurikiza REB curriculum. Urwego: {level} Ururimi: {language} Ikizamini: {info} Subiza: - Question - Expected Answer - Marks """ text = generator(prompt)[0]["generated_text"] pdf_file = make_pdf(text) return text, pdf_file def scheme_of_work(info, level, language): prompt = f""" Uri AI ikora SCHEME OF WORK. Kurikiza REB curriculum. Urwego: {level} Ururimi: {language} Amakuru: {info} Tegura table ikubiyemo: Week | Topic | Objectives | Activities | Assessment """ text = generator(prompt)[0]["generated_text"] pdf_file = make_pdf(text) return text, pdf_file # ====================== # GRADIO UI # ====================== with gr.Blocks(title="AI Ifasha Abarimu (REB)") as app: # --- LOGIN TAB --- with gr.Tab("πŸ”‘ Login / Register"): gr.Markdown("### Injira cyangwa wiyandikishe") username = gr.Textbox(label="Username") password = gr.Textbox(label="Password", type="password") login_btn = gr.Button("Login") register_btn = gr.Button("Register") login_status = gr.Textbox(label="Status") login_btn.click(lambda u, p: "Welcome " + u if login_user(u, p) else "Invalid username or password", [username, password], login_status) register_btn.click(add_user, [username, password], login_status) # --- MAIN FUNCTIONALITY TABS --- info = gr.Textbox(lines=6, label="Andika amakuru (subject, topic, class, term, etc)") level = gr.Dropdown(["Primary", "Secondary"], label="Level") language = gr.Dropdown(["Ikinyarwanda", "English"], label="Ururimi") with gr.Tab("πŸ“˜ Lesson Plan"): lp_out = gr.Textbox(label="Lesson Plan Text") lp_pdf = gr.File(label="Download PDF") gr.Button("Generate").click(lesson_plan, [info, level, language], [lp_out, lp_pdf]) with gr.Tab("πŸ“ Exams & Quizzes"): ex_out = gr.Textbox(label="Exams Text") ex_pdf = gr.File(label="Download PDF") gr.Button("Generate").click(exams, [info, level, language], [ex_out, ex_pdf]) with gr.Tab("πŸ“Š Marking Scheme"): ms_out = gr.Textbox(label="Marking Scheme Text") ms_pdf = gr.File(label="Download PDF") gr.Button("Generate").click(marking_scheme, [info, level, language], [ms_out, ms_pdf]) with gr.Tab("πŸ“š Scheme of Work"): sw_out = gr.Textbox(label="Scheme of Work Text") sw_pdf = gr.File(label="Download PDF") gr.Button("Generate").click(scheme_of_work, [info, level, language], [sw_out, sw_pdf]) app.launch()
11cabc7
verified

VIATEUR-AI commited on

import gradio as gr from transformers import pipeline from fpdf import FPDF import tempfile import os # ====================== # LOAD MODEL # ====================== generator = pipeline( "text2text-generation", model="google/flan-t5-base", max_new_tokens=800, do_sample=True, temperature=0.7 ) # ====================== # PDF FUNCTION WITH UNICODE FONT # ====================== def make_pdf(text): # Ensure the font file is in the same folder as script font_path = "DejaVuSans.ttf" if not os.path.exists(font_path): raise FileNotFoundError( "Font file 'DejaVuSans.ttf' not found. Please download it and put it in the script folder." ) with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp: pdf = FPDF() pdf.add_page() pdf.set_auto_page_break(auto=True, margin=15) # Add Unicode font pdf.add_font("DejaVu", "", font_path, uni=True) pdf.set_font("DejaVu", "", 12) pdf.multi_cell(0, 8, text) pdf.output(tmp.name) return tmp.name # ====================== # LESSON PLAN # ====================== def lesson_plan(info, level, language): prompt = f""" Uri AI ifasha abarimu bo mu Rwanda. Kurikiza REB curriculum. Tegura LESSON PLAN yuzuye ku rwego rwa {level}. Koresha ururimi: {language}. Amakuru: {info} Format: Class & Subject Topic Objectives Materials Lesson Steps Assessment Homework """ text = generator(prompt)[0]["generated_text"] pdf_file = make_pdf(text) return text, pdf_file # ====================== # EXAMS & QUIZZES # ====================== def exams(info, level, language): prompt = f""" Uri AI itegura EXAMS & QUIZZES. Kurikiza REB curriculum. Urwego: {level} Ururimi: {language} Amakuru: {info} Tegura: - 5 Multiple Choice - 5 Short Answer - Total Marks """ text = generator(prompt)[0]["generated_text"] pdf_file = make_pdf(text) return text, pdf_file # ====================== # MARKING SCHEME # ====================== def marking_scheme(info, level, language): prompt = f""" Uri AI ikora MARKING SCHEME y'ikizamini. Kurikiza REB curriculum. Urwego: {level} Ururimi: {language} Ikizamini: {info} Subiza: - Question - Expected Answer - Marks """ text = generator(prompt)[0]["generated_text"] pdf_file = make_pdf(text) return text, pdf_file # ====================== # SCHEME OF WORK # ====================== def scheme_of_work(info, level, language): prompt = f""" Uri AI ikora SCHEME OF WORK. Kurikiza REB curriculum. Urwego: {level} Ururimi: {language} Amakuru: {info} Tegura table ikubiyemo: Week | Topic | Objectives | Activities | Assessment """ text = generator(prompt)[0]["generated_text"] pdf_file = make_pdf(text) return text, pdf_file # ====================== # GRADIO UI # ====================== with gr.Blocks(title="AI Ifasha Abarimu (REB)") as app: gr.Markdown("## πŸ‡·πŸ‡Ό AI Ifasha Abarimu (REB Curriculum)") info = gr.Textbox(lines=6, label="Andika amakuru (subject, topic, class, term, etc)") level = gr.Dropdown(["Primary", "Secondary"], label="Level") language = gr.Dropdown(["Ikinyarwanda", "English"], label="Ururimi") with gr.Tab("πŸ“˜ Lesson Plan"): lp_out = gr.Textbox(label="Lesson Plan Text") lp_pdf = gr.File(label="Download PDF") gr.Button("Generate").click(lesson_plan, [info, level, language], [lp_out, lp_pdf]) with gr.Tab("πŸ“ Exams & Quizzes"): ex_out = gr.Textbox(label="Exams Text") ex_pdf = gr.File(label="Download PDF") gr.Button("Generate").click(exams, [info, level, language], [ex_out, ex_pdf]) with gr.Tab("πŸ“Š Marking Scheme"): ms_out = gr.Textbox(label="Marking Scheme Text") ms_pdf = gr.File(label="Download PDF") gr.Button("Generate").click(marking_scheme, [info, level, language], [ms_out, ms_pdf]) with gr.Tab("πŸ“š Scheme of Work"): sw_out = gr.Textbox(label="Scheme of Work Text") sw_pdf = gr.File(label="Download PDF") gr.Button("Generate").click(scheme_of_work, [info, level, language], [sw_out, sw_pdf]) app.launch()
1a05837
verified

VIATEUR-AI commited on

import gradio as gr from transformers import pipeline from fpdf import FPDF import tempfile # ====================== # LOAD MODEL # ====================== generator = pipeline( "text2text-generation", model="google/flan-t5-base", max_new_tokens=800, do_sample=True, temperature=0.7 ) # ====================== # PDF FUNCTION # ====================== def make_pdf(text): with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp: pdf = FPDF() pdf.add_page() pdf.set_auto_page_break(auto=True, margin=15) pdf.set_font("Arial", size=12) pdf.multi_cell(0, 8, text) pdf.output(tmp.name) return tmp.name # ====================== # LESSON PLAN # ====================== def lesson_plan(info, level, language): prompt = f""" Uri AI ifasha abarimu bo mu Rwanda. Kurikiza REB curriculum. Tegura LESSON PLAN yuzuye ku rwego rwa {level}. Koresha ururimi: {language}. Amakuru: {info} Format: Class & Subject Topic Objectives Materials Lesson Steps Assessment Homework """ text = generator(prompt)[0]["generated_text"] pdf_file = make_pdf(text) return text, pdf_file # ====================== # EXAMS & QUIZZES # ====================== def exams(info, level, language): prompt = f""" Uri AI itegura EXAMS & QUIZZES. Kurikiza REB curriculum. Urwego: {level} Ururimi: {language} Amakuru: {info} Tegura: - 5 Multiple Choice - 5 Short Answer - Total Marks """ text = generator(prompt)[0]["generated_text"] pdf_file = make_pdf(text) return text, pdf_file # ====================== # MARKING SCHEME # ====================== def marking_scheme(info, level, language): prompt = f""" Uri AI ikora MARKING SCHEME y'ikizamini. Kurikiza REB curriculum. Urwego: {level} Ururimi: {language} Ikizamini: {info} Subiza: - Question - Expected Answer - Marks """ text = generator(prompt)[0]["generated_text"] pdf_file = make_pdf(text) return text, pdf_file # ====================== # SCHEME OF WORK # ====================== def scheme_of_work(info, level, language): prompt = f""" Uri AI ikora SCHEME OF WORK. Kurikiza REB curriculum. Urwego: {level} Ururimi: {language} Amakuru: {info} Tegura table ikubiyemo: Week | Topic | Objectives | Activities | Assessment """ text = generator(prompt)[0]["generated_text"] pdf_file = make_pdf(text) return text, pdf_file # ====================== # GRADIO UI # ====================== with gr.Blocks(title="AI Ifasha Abarimu (REB)") as app: gr.Markdown("## πŸ‡·πŸ‡Ό AI Ifasha Abarimu (REB Curriculum)") info = gr.Textbox(lines=6, label="Andika amakuru (subject, topic, class, term, etc)") level = gr.Dropdown(["Primary", "Secondary"], label="Level") language = gr.Dropdown(["Ikinyarwanda", "English"], label="Ururimi") with gr.Tab("πŸ“˜ Lesson Plan"): lp_out = gr.Textbox(label="Lesson Plan Text") lp_pdf = gr.File(label="Download PDF") gr.Button("Generate").click(lesson_plan, [info, level, language], [lp_out, lp_pdf]) with gr.Tab("πŸ“ Exams & Quizzes"): ex_out = gr.Textbox(label="Exams Text") ex_pdf = gr.File(label="Download PDF") gr.Button("Generate").click(exams, [info, level, language], [ex_out, ex_pdf]) with gr.Tab("πŸ“Š Marking Scheme"): ms_out = gr.Textbox(label="Marking Scheme Text") ms_pdf = gr.File(label="Download PDF") gr.Button("Generate").click(marking_scheme, [info, level, language], [ms_out, ms_pdf]) with gr.Tab("πŸ“š Scheme of Work"): sw_out = gr.Textbox(label="Scheme of Work Text") sw_pdf = gr.File(label="Download PDF") gr.Button("Generate").click(scheme_of_work, [info, level, language], [sw_out, sw_pdf]) app.launch()
e51f22c
verified

VIATEUR-AI commited on

import gradio as gr from transformers import pipeline from fpdf import FPDF # ====================== # LOAD MODEL # ====================== generator = pipeline( "text2text-generation", model="google/flan-t5-base", max_new_tokens=800 ) # ====================== # PDF FUNCTION # ====================== def make_pdf(text, filename): pdf = FPDF() pdf.add_page() pdf.set_auto_page_break(auto=True, margin=15) pdf.add_font("DejaVu", "", "DejaVuSans.ttf", uni=True) pdf.set_font("DejaVu", size=12) pdf.multi_cell(0, 8, text) pdf.output(filename) return filename # ====================== # LESSON PLAN # ====================== def lesson_plan(info, level, language): prompt = f""" Uri AI ifasha abarimu bo mu Rwanda. Kurikiza REB curriculum. Tegura LESSON PLAN yuzuye ku rwego rwa {level}. Koresha ururimi: {language}. Amakuru: {info} Format: Class & Subject Topic Objectives Materials Lesson Steps Assessment Homework """ text = generator(prompt)[0]["generated_text"] pdf = make_pdf(text, "lesson_plan.pdf") return text, pdf # ====================== # EXAMS & QUIZZES # ====================== def exams(info, level, language): prompt = f""" Uri AI itegura EXAMS & QUIZZES. Kurikiza REB curriculum. Urwego: {level} Ururimi: {language} Amakuru: {info} Tegura: - 5 Multiple Choice - 5 Short Answer - Total Marks """ text = generator(prompt)[0]["generated_text"] pdf = make_pdf(text, "exam.pdf") return text, pdf # ====================== # MARKING SCHEME # ====================== def marking_scheme(info, level, language): prompt = f""" Uri AI ikora MARKING SCHEME y'ikizamini. Kurikiza REB curriculum. Urwego: {level} Ururimi: {language} Ikizamini: {info} Subiza: - Question - Expected Answer - Marks """ text = generator(prompt)[0]["generated_text"] pdf = make_pdf(text, "marking_scheme.pdf") return text, pdf # ====================== # SCHEME OF WORK # ====================== def scheme_of_work(info, level, language): prompt = f""" Uri AI ikora SCHEME OF WORK. Kurikiza REB curriculum. Urwego: {level} Ururimi: {language} Amakuru: {info} Tegura table ikubiyemo: Week | Topic | Objectives | Activities | Assessment """ text = generator(prompt)[0]["generated_text"] pdf = make_pdf(text, "scheme_of_work.pdf") return text, pdf # ====================== # GRADIO UI # ====================== with gr.Blocks(title="AI Ifasha Abarimu (REB)") as app: gr.Markdown("## πŸ‡·πŸ‡Ό AI Ifasha Abarimu (REB Curriculum)") info = gr.Textbox(lines=6, label="Andika amakuru (subject, topic, class, term, etc)") level = gr.Dropdown(["Primary", "Secondary"], label="Level") language = gr.Dropdown(["Ikinyarwanda", "English"], label="Ururimi") with gr.Tab("πŸ“˜ Lesson Plan"): lp_out = gr.Textbox() lp_pdf = gr.File() gr.Button("Generate").click(lesson_plan, [info, level, language], [lp_out, lp_pdf]) with gr.Tab("πŸ“ Exams & Quizzes"): ex_out = gr.Textbox() ex_pdf = gr.File() gr.Button("Generate").click(exams, [info, level, language], [ex_out, ex_pdf]) with gr.Tab("πŸ“Š Marking Scheme"): ms_out = gr.Textbox() ms_pdf = gr.File() gr.Button("Generate").click(marking_scheme, [info, level, language], [ms_out, ms_pdf]) with gr.Tab("πŸ“š Scheme of Work"): sw_out = gr.Textbox() sw_pdf = gr.File() gr.Button("Generate").click(scheme_of_work, [info, level, language], [sw_out, sw_pdf]) app.launch()
ec16dec
verified

VIATEUR-AI commited on

Update app.py
472808a
verified

VIATEUR-AI commited on

import gradio as gr from transformers import pipeline from fpdf import FPDF import os # ====================== # LOAD MODEL # ====================== generator = pipeline( "text2text-generation", model="google/flan-t5-base", max_new_tokens=600 ) # ====================== # FUNCTION # ====================== def tegura_isomo(amakuru, level, ururimi): prompt = f""" Uri AI ifasha abarimu bo mu Rwanda. Kurikiza REB curriculum. Tegura isomo ryuzuye ku rwego rwa {level}. Koresha ururimi: {ururimi}. Amakuru y'isomo: {amakuru} Subiza uko bikurikira: Class & Subject: Topic: Objectives: Materials: Lesson Steps: - Introduction - Development - Activities - Assessment Homework: """ result = generator(prompt) text = result[0]["generated_text"] # ====================== # CREATE PDF (UNICODE) # ====================== pdf = FPDF() pdf.add_page() pdf.set_auto_page_break(auto=True, margin=15) # Add Unicode font pdf.add_font("DejaVu", "", "DejaVuSans.ttf", uni=True) pdf.set_font("DejaVu", size=12) pdf.multi_cell(0, 8, text) file_path = "lesson_plan.pdf" pdf.output(file_path) return text, file_path # ====================== # GRADIO INTERFACE # ====================== app = gr.Interface( fn=tegura_isomo, inputs=[ gr.Textbox(lines=6, label="Andika amakuru y’isomo (subject, topic, igihe, etc)"), gr.Dropdown(["Primary", "Secondary"], label="Level"), gr.Dropdown(["Ikinyarwanda", "English"], label="Ururimi") ], outputs=[ gr.Textbox(label="Lesson Plan"), gr.File(label="Kuramo PDF") ], title="AI Ifasha Abarimu (REB Curriculum)", description="Iyi AI itegura lesson plan zemewe na REB, mu Kinyarwanda cyangwa English, ikanagenera PDF." ) app.launch()
855c1d2
verified

VIATEUR-AI commited on

Update app.py
caaf0c3
verified

VIATEUR-AI commited on

gradio transformers torch fpdf
f56622f
verified

VIATEUR-AI commited on

import gradio as gr from transformers import pipeline from fpdf import FPDF import os # Model generator = pipeline( "text2text-generation", model="google/flan-t5-base", max_new_tokens=600 ) def tegura_isomo(amakuru, level, ururimi): prompt = f""" Uri AI ifasha abarimu ba {level} mu Rwanda. Kurikiza REB curriculum. Tegura isomo ryuzuye mu rurimi: {ururimi}. Amakuru: {amakuru} Subiza uko bikurikira: - Class & Subject - Topic - Objectives - Materials - Lesson Steps (Introduction, Development, Activities, Assessment) - Homework """ result = generator(prompt) text = result[0]["generated_text"] # Gukora PDF pdf = FPDF() pdf.add_page() pdf.set_auto_page_break(auto=True, margin=15) pdf.set_font("Arial", size=12) for line in text.split("\n"): pdf.multi_cell(0, 8, line) file_path = "lesson_plan.pdf" pdf.output(file_path) return text, file_path app = gr.Interface( fn=tegura_isomo, inputs=[ gr.Textbox(lines=5, label="Andika amakuru y’isomo"), gr.Dropdown(["Primary", "Secondary"], label="Level"), gr.Dropdown(["Ikinyarwanda", "English"], label="Ururimi") ], outputs=[ gr.Textbox(label="Lesson Plan"), gr.File(label="Kuramo PDF") ], title="AI Ifasha Abarimu (REB Curriculum)", description="Tegura amasomo ya Primary & Secondary, uhitemo ururimi, ubone PDF" ) app.launch()
7ce1f24
verified

VIATEUR-AI commited on

gradio transformers torch
d9702b1
verified

VIATEUR-AI commited on

Update app.py
7caffee
verified

VIATEUR-AI commited on

Rename requirements . text to requirements.txt
68c4ea5
verified

VIATEUR-AI commited on

transformers==4.41.2 torch==2.2.0 sentencepiece==0.1.99 accelerate==0.29.3 gradio==4.31.3 numpy soundfile TTS==0.22.0
a42bc14
verified

VIATEUR-AI commited on

body { background-color: #f1f5f9; } h1 { text-align: center; color: #2d6cdf; font-weight: 900; }
7339b17
verified

VIATEUR-AI commited on

gradio transformers torch sentencepiece accelerate TTS numpy soundfile
a69078c
verified

VIATEUR-AI commited on

import gradio as gr from transformers import pipeline from TTS.api import TTS # ----------------------------- # 1. Load Speech-to-Text (Whisper) # ----------------------------- stt = pipeline( "automatic-speech-recognition", model="openai/whisper-large-v3", device="cpu" ) # ----------------------------- # 2. Load Translation (M2M100) # ----------------------------- translator = pipeline( "translation", model="facebook/m2m100_418M" ) # List of supported languages languages = { "English": "en", "French": "fr", "Kinyarwanda": "rw", "Swahili": "sw", "German": "de", "Spanish": "es", "Portuguese": "pt", "Italian": "it", "Chinese (Mandarin)": "zh", "Japanese": "ja", "Korean": "ko", "Arabic": "ar", "Russian": "ru", } # ----------------------------- # 3. Load Text-to-Speech (XTTSv2) # ----------------------------- tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2") # ----------------------------- # MAIN FUNCTION # ----------------------------- def process_audio(audio, target_lang): # Step 1: STT text = stt(audio)["text"] # Step 2: Translate lang_code = languages[target_lang] translation = translator( text, forced_bos_token_id=translator.tokenizer.get_lang_id(lang_code) )[0]["translation_text"] # Step 3: TTS output_audio_path = "output.wav" tts.tts_to_file( text=translation, file_path=output_audio_path, speaker_wav=None, language=lang_code ) return text, translation, output_audio_path # ----------------------------- # 4. Gradio UI # ----------------------------- with gr.Blocks(css="custom.css") as app: gr.Markdown("<h1>🌍 Multilingual Voice-to-Voice AI Translator</h1>") gr.Markdown("Record or upload audio β†’ AI Converts speech β†’ Translates β†’ Speaks output voice.") with gr.Row(): audio_input = gr.Audio(type="filepath", label="🎀 Upload or Record Audio") lang_input = gr.Dropdown(list(languages.keys()), label="🌐 Choose Target Language") with gr.Row(): text_out = gr.Textbox(label="πŸ“ Transcribed Text") translation_out = gr.Textbox(label="🌍 Translated Text") audio_out = gr.Audio(label="πŸ”Š AI Generated Voice Output") submit = gr.Button("πŸš€ Translate & Convert") submit.click( fn=process_audio, inputs=[audio_input, lang_input], outputs=[text_out, translation_out, audio_out] ) app.launch()
53ed5ad
verified

VIATEUR-AI commited on

Create custom . css
1805434
verified

VIATEUR-AI commited on

Create requirements . text
9bc286c
verified

VIATEUR-AI commited on

initial commit
074a256
verified

VIATEUR-AI commited on

Duplicate from gradio-templates/chatbot
e80214b
verified

VIATEUR-AI pngwn HF Staff commited on