CoolFace
Apppublic

Shahzad124/e-learningPlatform

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
0likes
app.py69 linesDownload Raw Back to root
1import streamlit as st2import sqlite33 4# Connect to SQLite database5def get_db_connection():6    conn = sqlite3.connect('shahzad_platform.db')7    conn.row_factory = sqlite3.Row8    return conn9 10def display_lessons():11    conn = get_db_connection()12    lessons = conn.execute('SELECT * FROM lessons').fetchall()13    conn.close()14    return lessons15 16def display_lesson(lesson_id):17    conn = get_db_connection()18    lesson = conn.execute('SELECT * FROM lessons WHERE id = ?', (lesson_id,)).fetchone()19    quizzes = conn.execute('SELECT * FROM quizzes WHERE lesson_id = ?', (lesson_id,)).fetchall()20    conn.close()21    return lesson, quizzes22 23def display_quiz(quiz_id):24    conn = get_db_connection()25    quiz = conn.execute('SELECT * FROM quizzes WHERE id = ?', (quiz_id,)).fetchone()26    conn.close()27    return quiz28 29# Streamlit App30def app():31    st.title("Shahzad E-Learning Platform")32 33    st.sidebar.title("Navigation")34    app_mode = st.sidebar.selectbox("Choose an option", ["Home", "Lessons", "Progress"])35 36    if app_mode == "Home":37        st.write("Welcome to the Shahzad E-learning Platform! Please select an option from the sidebar.")38    elif app_mode == "Lessons":39        st.subheader("Available Lessons")40        lessons = display_lessons()41        lesson_titles = [lesson['title'] for lesson in lessons]42        lesson_selection = st.selectbox("Select a lesson", lesson_titles)43        44        if lesson_selection:45            lesson_id = [lesson['id'] for lesson in lessons if lesson['title'] == lesson_selection][0]46            lesson, quizzes = display_lesson(lesson_id)47            st.write(f"**Lesson:** {lesson['title']}")48            st.write(f"{lesson['content']}")49            50            # Show quizzes51            st.subheader("Quizzes")52            for quiz in quizzes:53                if st.button(f"Start Quiz: {quiz['question']}"):54                    user_answer = st.text_input("Your Answer:")55                    if user_answer:56                        correct_answer = quiz['correct_answer']57                        if user_answer.lower() == correct_answer.lower():58                            st.success("Correct!")59                        else:60                            st.error(f"Wrong! Correct answer: {correct_answer}")61 62    elif app_mode == "Progress":63        st.subheader("Your Progress")64        # Assuming you have a session or login system, display quiz results.65        st.write("Progress tracking will go here.")66 67if __name__ == "__main__":68    app()69