File size: 10,147 Bytes
78ab8dd
 
 
 
f12bb2e
78ab8dd
 
 
4d57e77
f12bb2e
4d57e77
 
 
78ab8dd
4d57e77
 
f12bb2e
 
 
 
78ab8dd
4d57e77
f12bb2e
 
4d57e77
f12bb2e
 
4d57e77
f12bb2e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78ab8dd
 
 
f95c35e
78ab8dd
 
 
 
f95c35e
78ab8dd
 
f95c35e
 
78ab8dd
f95c35e
78ab8dd
 
f12bb2e
78ab8dd
 
 
 
f95c35e
78ab8dd
f95c35e
78ab8dd
f95c35e
78ab8dd
 
4d57e77
78ab8dd
 
 
f12bb2e
 
 
 
 
 
 
 
 
 
 
f65de15
 
f12bb2e
f65de15
f12bb2e
 
 
78ab8dd
 
 
f95c35e
f12bb2e
f95c35e
f12bb2e
78ab8dd
 
f12bb2e
 
78ab8dd
f12bb2e
78ab8dd
f95c35e
 
4d57e77
f95c35e
f12bb2e
f95c35e
 
4d57e77
78ab8dd
 
 
f95c35e
 
78ab8dd
 
f12bb2e
f95c35e
 
 
 
 
 
78ab8dd
 
f12bb2e
f95c35e
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import streamlit as st
import random

# ------------------------------
# Quiz Data (10 categories × 5 questions each)
# ------------------------------
quizzes = {
    "Science": [
        {"question": "What planet is known as the Red Planet?", "options": ["Earth", "Mars", "Venus", "Jupiter"], "answer": "Mars"},
        {"question": "What gas do plants absorb?", "options": ["Oxygen", "Carbon Dioxide", "Nitrogen", "Hydrogen"], "answer": "Carbon Dioxide"},
        {"question": "Water freezes at what temperature (C)?", "options": ["0", "32", "-10", "100"], "answer": "0"},
        {"question": "What organ produces insulin?", "options": ["Liver", "Heart", "Pancreas", "Lung"], "answer": "Pancreas"},
        {"question": "What is the chemical symbol for gold?", "options": ["Au", "Ag", "Go", "Gd"], "answer": "Au"},
    ],
    "Artificial Intelligence (AI)": [
        {"question": "What does AI stand for?", "options": ["Artificial Intelligence", "Automatic Integration", "Automated Interface", "Actual Intelligence"], "answer": "Artificial Intelligence"},
        {"question": "Which company developed ChatGPT?", "options": ["Google", "Meta", "OpenAI", "Microsoft"], "answer": "OpenAI"},
        {"question": "Which model is used for generating human-like text?", "options": ["CNN", "GPT", "RNN", "SVM"], "answer": "GPT"},
        {"question": "Turing Test is used to test?", "options": ["Intelligence", "Speed", "Memory", "Computation"], "answer": "Intelligence"},
        {"question": "Which is not a type of AI?", "options": ["Narrow AI", "General AI", "Super AI", "Organic AI"], "answer": "Organic AI"},
    ],
    "Machine Learning (ML)": [
        {"question": "Which of the following is a supervised learning algorithm?", "options": ["K-Means", "Linear Regression", "PCA", "DBSCAN"], "answer": "Linear Regression"},
        {"question": "ML uses what to make predictions?", "options": ["Data", "Rules", "Hardware", "Code"], "answer": "Data"},
        {"question": "Which library is used in ML?", "options": ["NumPy", "Pandas", "Scikit-learn", "OpenCV"], "answer": "Scikit-learn"},
        {"question": "Which is not an ML algorithm?", "options": ["SVM", "CNN", "Decision Tree", "KNN"], "answer": "CNN"},
        {"question": "What type of data does supervised learning require?", "options": ["Unlabeled", "Categorical", "Labeled", "Binary"], "answer": "Labeled"},
    ],
    "Deep Learning (DL)": [
        {"question": "Deep Learning is a subset of?", "options": ["Machine Learning", "Data Mining", "Statistics", "Robotics"], "answer": "Machine Learning"},
        {"question": "Which architecture is common in DL?", "options": ["CNN", "SVM", "KNN", "PCA"], "answer": "CNN"},
        {"question": "Which library is used for DL?", "options": ["TensorFlow", "NumPy", "Matplotlib", "OpenCV"], "answer": "TensorFlow"},
        {"question": "RNNs are best for what type of data?", "options": ["Images", "Time Series", "Tables", "Graphs"], "answer": "Time Series"},
        {"question": "Which function is used in neural networks?", "options": ["Activation", "Loss", "Gradient", "Bias"], "answer": "Activation"},
    ],
    "Computer Vision (CV)": [
        {"question": "What is the goal of CV?", "options": ["Understand images", "Translate text", "Play games", "Store files"], "answer": "Understand images"},
        {"question": "Which library is popular in CV?", "options": ["OpenCV", "Pandas", "Flask", "Numpy"], "answer": "OpenCV"},
        {"question": "What technique is used for object detection?", "options": ["YOLO", "RNN", "PCA", "SVM"], "answer": "YOLO"},
        {"question": "What file format is NOT an image?", "options": ["JPG", "PNG", "TXT", "GIF"], "answer": "TXT"},
        {"question": "Which model type is used for image classification?", "options": ["CNN", "RNN", "LSTM", "DBSCAN"], "answer": "CNN"},
    ],
    "Health": [
        {"question": "Which vitamin is gained from sunlight?", "options": ["A", "B12", "C", "D"], "answer": "D"},
        {"question": "What is the normal human body temperature?", "options": ["36.5°C", "37°C", "38°C", "39°C"], "answer": "37°C"},
        {"question": "Which organ pumps blood?", "options": ["Lungs", "Liver", "Heart", "Kidney"], "answer": "Heart"},
        {"question": "Which disease affects lungs?", "options": ["Asthma", "Diabetes", "Arthritis", "Jaundice"], "answer": "Asthma"},
        {"question": "What nutrient builds muscle?", "options": ["Protein", "Carbohydrate", "Fat", "Sugar"], "answer": "Protein"},
    ],
    "Environment": [
        {"question": "Which gas causes global warming?", "options": ["CO2", "O2", "N2", "H2"], "answer": "CO2"},
        {"question": "What is the main source of air pollution?", "options": ["Vehicles", "Trees", "Wind", "Mountains"], "answer": "Vehicles"},
        {"question": "Which is a renewable resource?", "options": ["Solar", "Coal", "Oil", "Gas"], "answer": "Solar"},
        {"question": "Which layer protects us from UV rays?", "options": ["Ozone", "Clouds", "Stratosphere", "Troposphere"], "answer": "Ozone"},
        {"question": "Which ocean is the largest?", "options": ["Atlantic", "Pacific", "Indian", "Arctic"], "answer": "Pacific"},
    ],
    "Mathematics": [
        {"question": "What is 12 × 8?", "options": ["96", "108", "88", "104"], "answer": "96"},
        {"question": "Square root of 64?", "options": ["6", "7", "8", "9"], "answer": "8"},
        {"question": "π (Pi) value to 2 decimal places?", "options": ["3.12", "3.14", "3.16", "3.18"], "answer": "3.14"},
        {"question": "What is 15% of 200?", "options": ["30", "25", "20", "35"], "answer": "30"},
        {"question": "What is 100 ÷ 5?", "options": ["20", "15", "10", "25"], "answer": "20"},
    ],
    "Literature": [
        {"question": "Who wrote 'Hamlet'?", "options": ["Shakespeare", "Chaucer", "Shelley", "Austen"], "answer": "Shakespeare"},
        {"question": "'Pride and Prejudice' author?", "options": ["Jane Austen", "Bronte", "Eliot", "Shelley"], "answer": "Jane Austen"},
        {"question": "Sherlock Holmes creator?", "options": ["Doyle", "Christie", "Rowling", "Brown"], "answer": "Doyle"},
        {"question": "Which book starts with 'Call me Ishmael'?", "options": ["Moby Dick", "Odyssey", "Ulysses", "Don Quixote"], "answer": "Moby Dick"},
        {"question": "Language of 'Les Misérables'?", "options": ["French", "English", "German", "Spanish"], "answer": "French"},
    ],
    "History": [
        {"question": "First President of USA?", "options": ["Lincoln", "Washington", "Adams", "Jefferson"], "answer": "Washington"},
        {"question": "Year WWII ended?", "options": ["1945", "1939", "1950", "1940"], "answer": "1945"},
        {"question": "Pyramids built by?", "options": ["Egyptians", "Romans", "Greeks", "Mayans"], "answer": "Egyptians"},
        {"question": "Who discovered America?", "options": ["Columbus", "Da Gama", "Magellan", "Marco Polo"], "answer": "Columbus"},
        {"question": "Start of Industrial Revolution?", "options": ["England", "France", "USA", "Germany"], "answer": "England"},
    ]
}

# ------------------------------
# Functions
# ------------------------------
def load_questions(category):
    return random.sample(quizzes[category], 5)

def evaluate(questions):
    score = 0
    results = []
    for i, q in enumerate(questions):
        selected = st.session_state.get(f"answer_{i}")
        correct = q["answer"]
        is_correct = selected == correct
        if is_correct:
            score += 1
        results.append({"question": q["question"], "selected": selected, "correct": correct, "is_correct": is_correct})
    return score, results

def show_feedback(score):
    if score == 5:
        st.success("🌟 Perfect! You got 5/5! 🎉")
    elif score >= 3:
        st.info(f"👍 Good Job! You scored {score}/5")
    else:
        st.warning(f"📖 Keep practicing. You scored {score}/5")

# ------------------------------
# Streamlit UI
# ------------------------------
st.set_page_config(page_title="BrainQuest AI", layout="centered")

# First page welcome screen
if "started" not in st.session_state:
    st.session_state.started = False

if not st.session_state.started:
    st.markdown("""
        <div style='text-align:center;'>
            <h1 style='font-size:48px;'>🎓 Welcome to BrainQuest AI</h1>
            <p style='font-size:24px;'>Test your knowledge across 10 powerful fields</p>
        </div>
    """, unsafe_allow_html=True)

    if st.button("🚀 Get Started Now", key="start_button", help="Click to begin the quiz experience"):
        st.session_state.started = True

    st.stop()

# Sidebar
with st.sidebar:
    st.title("ℹ️ About")
    st.markdown("""
    **🎓 BrainQuest AI**
    - 10 Dynamic Categories  
    - Built with ❤️ by **Sabir Ali**  
    - Fully Offline, Fast & Engaging
    """)

st.title("🧠 Choose a Quiz Category")
category = st.selectbox("📘 Select Category", list(quizzes.keys()))

if st.button("Start Quiz"):
    st.session_state.questions = load_questions(category)
    st.session_state.submitted = False
    for i in range(5):
        st.session_state[f"answer_{i}"] = None

if "questions" in st.session_state and not st.session_state.submitted:
    for i, q in enumerate(st.session_state.questions):
        st.markdown(f"**Q{i+1}:** {q['question']}")
        st.radio("Your Answer:", q["options"], key=f"answer_{i}", label_visibility="collapsed")
        st.markdown("---")

    if st.button("Submit Answers"):
        st.session_state.submitted = True
        score, results = evaluate(st.session_state.questions)
        show_feedback(score)

        st.markdown("## 📊 Results Summary")
        for i, r in enumerate(results):
            emoji = "✅" if r["is_correct"] else "❌"
            st.markdown(f"**Q{i+1}:** {r['question']}")
            st.markdown(f"- Your answer: `{r['selected']}` {emoji}")
            if not r["is_correct"]:
                st.markdown(f"- Correct answer: `{r['correct']}`")
            st.markdown("---")

        if st.button("🔁 Try Another Quiz"):
            st.session_state.questions = []
            st.session_state.submitted = False