Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,46 +2,79 @@ import streamlit as st
|
|
| 2 |
import random
|
| 3 |
|
| 4 |
# ------------------------------
|
| 5 |
-
# Quiz Data (10 categories ×
|
| 6 |
# ------------------------------
|
| 7 |
quizzes = {
|
| 8 |
"Science": [
|
| 9 |
{"question": "What planet is known as the Red Planet?", "options": ["Earth", "Mars", "Venus", "Jupiter"], "answer": "Mars"},
|
| 10 |
-
{"question": "
|
| 11 |
{"question": "Water freezes at what temperature (C)?", "options": ["0", "32", "-10", "100"], "answer": "0"},
|
| 12 |
{"question": "What organ produces insulin?", "options": ["Liver", "Heart", "Pancreas", "Lung"], "answer": "Pancreas"},
|
| 13 |
{"question": "What is the chemical symbol for gold?", "options": ["Au", "Ag", "Go", "Gd"], "answer": "Au"},
|
| 14 |
-
{"question": "What is the speed of light?", "options": ["300,000 km/s", "150,000 km/s", "500,000 km/s", "100,000 km/s"], "answer": "300,000 km/s"},
|
| 15 |
-
{"question": "Which gas is most abundant in the Earth's atmosphere?", "options": ["Oxygen", "Carbon Dioxide", "Nitrogen", "Hydrogen"], "answer": "Nitrogen"},
|
| 16 |
-
{"question": "What planet has the most moons?", "options": ["Jupiter", "Saturn", "Uranus", "Neptune"], "answer": "Saturn"},
|
| 17 |
-
{"question": "Which vitamin is produced in human skin in response to sunlight?", "options": ["A", "B12", "C", "D"], "answer": "D"},
|
| 18 |
-
{"question": "Which element has the atomic number 1?", "options": ["Oxygen", "Helium", "Hydrogen", "Carbon"], "answer": "Hydrogen"},
|
| 19 |
],
|
| 20 |
"Artificial Intelligence (AI)": [
|
| 21 |
{"question": "What does AI stand for?", "options": ["Artificial Intelligence", "Automatic Integration", "Automated Interface", "Actual Intelligence"], "answer": "Artificial Intelligence"},
|
| 22 |
-
{"question": "Which
|
| 23 |
-
{"question": "Which
|
| 24 |
-
{"question": "
|
| 25 |
-
{"question": "Which
|
| 26 |
-
{"question": "Which company developed ChatGPT?", "options": ["Google", "Facebook", "OpenAI", "Microsoft"], "answer": "OpenAI"},
|
| 27 |
-
{"question": "Which term describes AI that can learn from data?", "options": ["Machine Learning", "Hardcoding", "Compilation", "Automation"], "answer": "Machine Learning"},
|
| 28 |
-
{"question": "Which AI field handles speech recognition?", "options": ["NLP", "CV", "ML", "DL"], "answer": "NLP"},
|
| 29 |
-
{"question": "What is an agent in AI?", "options": ["Performer of actions", "Debugger", "Toolbox", "Compiler"], "answer": "Performer of actions"},
|
| 30 |
-
{"question": "AI that mimics human brain is called?", "options": ["Neural Network", "SVM", "Logistic Regression", "KNN"], "answer": "Neural Network"},
|
| 31 |
],
|
| 32 |
"Machine Learning (ML)": [
|
| 33 |
-
{"question": "
|
| 34 |
-
{"question": "
|
| 35 |
-
{"question": "K-Means is used for?", "options": ["Classification", "Regression", "Clustering", "Prediction"], "answer": "Clustering"},
|
| 36 |
{"question": "Which library is used in ML?", "options": ["NumPy", "Pandas", "Scikit-learn", "OpenCV"], "answer": "Scikit-learn"},
|
| 37 |
-
{"question": "Which is
|
| 38 |
-
{"question": "
|
| 39 |
-
{"question": "Overfitting happens when?", "options": ["Model learns too much", "Too little data", "Too much bias", "None"], "answer": "Model learns too much"},
|
| 40 |
-
{"question": "Which technique is used to reduce features?", "options": ["PCA", "KNN", "SVM", "RNN"], "answer": "PCA"},
|
| 41 |
-
{"question": "Which of these is a tree-based method?", "options": ["Random Forest", "SVM", "Naive Bayes", "PCA"], "answer": "Random Forest"},
|
| 42 |
-
{"question": "Which concept measures error?", "options": ["Loss function", "Activation", "Weight", "Bias"], "answer": "Loss function"},
|
| 43 |
],
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
}
|
| 46 |
|
| 47 |
# ------------------------------
|
|
@@ -59,12 +92,7 @@ def evaluate(questions):
|
|
| 59 |
is_correct = selected == correct
|
| 60 |
if is_correct:
|
| 61 |
score += 1
|
| 62 |
-
results.append({
|
| 63 |
-
"question": q["question"],
|
| 64 |
-
"selected": selected,
|
| 65 |
-
"correct": correct,
|
| 66 |
-
"is_correct": is_correct
|
| 67 |
-
})
|
| 68 |
return score, results
|
| 69 |
|
| 70 |
def show_feedback(score):
|
|
@@ -80,37 +108,45 @@ def show_feedback(score):
|
|
| 80 |
# ------------------------------
|
| 81 |
st.set_page_config(page_title="BrainQuest AI", layout="centered")
|
| 82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
with st.sidebar:
|
| 84 |
st.title("ℹ️ About")
|
| 85 |
st.markdown("""
|
| 86 |
**🎓 BrainQuest AI**
|
| 87 |
-
|
| 88 |
-
- Educational Quiz App
|
| 89 |
- Built with ❤️ by **Sabir Ali**
|
| 90 |
-
-
|
| 91 |
-
- No login, No database
|
| 92 |
""")
|
| 93 |
|
| 94 |
-
st.title("
|
| 95 |
-
st.
|
| 96 |
-
st.markdown("---")
|
| 97 |
-
|
| 98 |
-
# Session Initialization
|
| 99 |
-
if "questions" not in st.session_state:
|
| 100 |
-
st.session_state.questions = []
|
| 101 |
-
st.session_state.submitted = False
|
| 102 |
-
|
| 103 |
-
# Category Selection
|
| 104 |
-
category = st.selectbox("📘 Choose a Category", list(quizzes.keys()))
|
| 105 |
|
| 106 |
-
if st.button("
|
| 107 |
st.session_state.questions = load_questions(category)
|
| 108 |
st.session_state.submitted = False
|
| 109 |
for i in range(5):
|
| 110 |
st.session_state[f"answer_{i}"] = None
|
| 111 |
|
| 112 |
-
|
| 113 |
-
if st.session_state.questions and not st.session_state.submitted:
|
| 114 |
for i, q in enumerate(st.session_state.questions):
|
| 115 |
st.markdown(f"**Q{i+1}:** {q['question']}")
|
| 116 |
st.radio("Your Answer:", q["options"], key=f"answer_{i}", label_visibility="collapsed")
|
|
@@ -121,7 +157,7 @@ if st.session_state.questions and not st.session_state.submitted:
|
|
| 121 |
score, results = evaluate(st.session_state.questions)
|
| 122 |
show_feedback(score)
|
| 123 |
|
| 124 |
-
st.markdown("##
|
| 125 |
for i, r in enumerate(results):
|
| 126 |
emoji = "✅" if r["is_correct"] else "❌"
|
| 127 |
st.markdown(f"**Q{i+1}:** {r['question']}")
|
|
@@ -130,6 +166,6 @@ if st.session_state.questions and not st.session_state.submitted:
|
|
| 130 |
st.markdown(f"- Correct answer: `{r['correct']}`")
|
| 131 |
st.markdown("---")
|
| 132 |
|
| 133 |
-
if st.button("
|
| 134 |
st.session_state.questions = []
|
| 135 |
st.session_state.submitted = False
|
|
|
|
| 2 |
import random
|
| 3 |
|
| 4 |
# ------------------------------
|
| 5 |
+
# Quiz Data (10 categories × 5 questions each)
|
| 6 |
# ------------------------------
|
| 7 |
quizzes = {
|
| 8 |
"Science": [
|
| 9 |
{"question": "What planet is known as the Red Planet?", "options": ["Earth", "Mars", "Venus", "Jupiter"], "answer": "Mars"},
|
| 10 |
+
{"question": "What gas do plants absorb?", "options": ["Oxygen", "Carbon Dioxide", "Nitrogen", "Hydrogen"], "answer": "Carbon Dioxide"},
|
| 11 |
{"question": "Water freezes at what temperature (C)?", "options": ["0", "32", "-10", "100"], "answer": "0"},
|
| 12 |
{"question": "What organ produces insulin?", "options": ["Liver", "Heart", "Pancreas", "Lung"], "answer": "Pancreas"},
|
| 13 |
{"question": "What is the chemical symbol for gold?", "options": ["Au", "Ag", "Go", "Gd"], "answer": "Au"},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
],
|
| 15 |
"Artificial Intelligence (AI)": [
|
| 16 |
{"question": "What does AI stand for?", "options": ["Artificial Intelligence", "Automatic Integration", "Automated Interface", "Actual Intelligence"], "answer": "Artificial Intelligence"},
|
| 17 |
+
{"question": "Which company developed ChatGPT?", "options": ["Google", "Meta", "OpenAI", "Microsoft"], "answer": "OpenAI"},
|
| 18 |
+
{"question": "Which model is used for generating human-like text?", "options": ["CNN", "GPT", "RNN", "SVM"], "answer": "GPT"},
|
| 19 |
+
{"question": "Turing Test is used to test?", "options": ["Intelligence", "Speed", "Memory", "Computation"], "answer": "Intelligence"},
|
| 20 |
+
{"question": "Which is not a type of AI?", "options": ["Narrow AI", "General AI", "Super AI", "Organic AI"], "answer": "Organic AI"},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
],
|
| 22 |
"Machine Learning (ML)": [
|
| 23 |
+
{"question": "Which of the following is a supervised learning algorithm?", "options": ["K-Means", "Linear Regression", "PCA", "DBSCAN"], "answer": "Linear Regression"},
|
| 24 |
+
{"question": "ML uses what to make predictions?", "options": ["Data", "Rules", "Hardware", "Code"], "answer": "Data"},
|
|
|
|
| 25 |
{"question": "Which library is used in ML?", "options": ["NumPy", "Pandas", "Scikit-learn", "OpenCV"], "answer": "Scikit-learn"},
|
| 26 |
+
{"question": "Which is not an ML algorithm?", "options": ["SVM", "CNN", "Decision Tree", "KNN"], "answer": "CNN"},
|
| 27 |
+
{"question": "What type of data does supervised learning require?", "options": ["Unlabeled", "Categorical", "Labeled", "Binary"], "answer": "Labeled"},
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
],
|
| 29 |
+
"Deep Learning (DL)": [
|
| 30 |
+
{"question": "Deep Learning is a subset of?", "options": ["Machine Learning", "Data Mining", "Statistics", "Robotics"], "answer": "Machine Learning"},
|
| 31 |
+
{"question": "Which architecture is common in DL?", "options": ["CNN", "SVM", "KNN", "PCA"], "answer": "CNN"},
|
| 32 |
+
{"question": "Which library is used for DL?", "options": ["TensorFlow", "NumPy", "Matplotlib", "OpenCV"], "answer": "TensorFlow"},
|
| 33 |
+
{"question": "RNNs are best for what type of data?", "options": ["Images", "Time Series", "Tables", "Graphs"], "answer": "Time Series"},
|
| 34 |
+
{"question": "Which function is used in neural networks?", "options": ["Activation", "Loss", "Gradient", "Bias"], "answer": "Activation"},
|
| 35 |
+
],
|
| 36 |
+
"Computer Vision (CV)": [
|
| 37 |
+
{"question": "What is the goal of CV?", "options": ["Understand images", "Translate text", "Play games", "Store files"], "answer": "Understand images"},
|
| 38 |
+
{"question": "Which library is popular in CV?", "options": ["OpenCV", "Pandas", "Flask", "Numpy"], "answer": "OpenCV"},
|
| 39 |
+
{"question": "What technique is used for object detection?", "options": ["YOLO", "RNN", "PCA", "SVM"], "answer": "YOLO"},
|
| 40 |
+
{"question": "What file format is NOT an image?", "options": ["JPG", "PNG", "TXT", "GIF"], "answer": "TXT"},
|
| 41 |
+
{"question": "Which model type is used for image classification?", "options": ["CNN", "RNN", "LSTM", "DBSCAN"], "answer": "CNN"},
|
| 42 |
+
],
|
| 43 |
+
"Health": [
|
| 44 |
+
{"question": "Which vitamin is gained from sunlight?", "options": ["A", "B12", "C", "D"], "answer": "D"},
|
| 45 |
+
{"question": "What is the normal human body temperature?", "options": ["36.5°C", "37°C", "38°C", "39°C"], "answer": "37°C"},
|
| 46 |
+
{"question": "Which organ pumps blood?", "options": ["Lungs", "Liver", "Heart", "Kidney"], "answer": "Heart"},
|
| 47 |
+
{"question": "Which disease affects lungs?", "options": ["Asthma", "Diabetes", "Arthritis", "Jaundice"], "answer": "Asthma"},
|
| 48 |
+
{"question": "What nutrient builds muscle?", "options": ["Protein", "Carbohydrate", "Fat", "Sugar"], "answer": "Protein"},
|
| 49 |
+
],
|
| 50 |
+
"Environment": [
|
| 51 |
+
{"question": "Which gas causes global warming?", "options": ["CO2", "O2", "N2", "H2"], "answer": "CO2"},
|
| 52 |
+
{"question": "What is the main source of air pollution?", "options": ["Vehicles", "Trees", "Wind", "Mountains"], "answer": "Vehicles"},
|
| 53 |
+
{"question": "Which is a renewable resource?", "options": ["Solar", "Coal", "Oil", "Gas"], "answer": "Solar"},
|
| 54 |
+
{"question": "Which layer protects us from UV rays?", "options": ["Ozone", "Clouds", "Stratosphere", "Troposphere"], "answer": "Ozone"},
|
| 55 |
+
{"question": "Which ocean is the largest?", "options": ["Atlantic", "Pacific", "Indian", "Arctic"], "answer": "Pacific"},
|
| 56 |
+
],
|
| 57 |
+
"Mathematics": [
|
| 58 |
+
{"question": "What is 12 × 8?", "options": ["96", "108", "88", "104"], "answer": "96"},
|
| 59 |
+
{"question": "Square root of 64?", "options": ["6", "7", "8", "9"], "answer": "8"},
|
| 60 |
+
{"question": "π (Pi) value to 2 decimal places?", "options": ["3.12", "3.14", "3.16", "3.18"], "answer": "3.14"},
|
| 61 |
+
{"question": "What is 15% of 200?", "options": ["30", "25", "20", "35"], "answer": "30"},
|
| 62 |
+
{"question": "What is 100 ÷ 5?", "options": ["20", "15", "10", "25"], "answer": "20"},
|
| 63 |
+
],
|
| 64 |
+
"Literature": [
|
| 65 |
+
{"question": "Who wrote 'Hamlet'?", "options": ["Shakespeare", "Chaucer", "Shelley", "Austen"], "answer": "Shakespeare"},
|
| 66 |
+
{"question": "'Pride and Prejudice' author?", "options": ["Jane Austen", "Bronte", "Eliot", "Shelley"], "answer": "Jane Austen"},
|
| 67 |
+
{"question": "Sherlock Holmes creator?", "options": ["Doyle", "Christie", "Rowling", "Brown"], "answer": "Doyle"},
|
| 68 |
+
{"question": "Which book starts with 'Call me Ishmael'?", "options": ["Moby Dick", "Odyssey", "Ulysses", "Don Quixote"], "answer": "Moby Dick"},
|
| 69 |
+
{"question": "Language of 'Les Misérables'?", "options": ["French", "English", "German", "Spanish"], "answer": "French"},
|
| 70 |
+
],
|
| 71 |
+
"History": [
|
| 72 |
+
{"question": "First President of USA?", "options": ["Lincoln", "Washington", "Adams", "Jefferson"], "answer": "Washington"},
|
| 73 |
+
{"question": "Year WWII ended?", "options": ["1945", "1939", "1950", "1940"], "answer": "1945"},
|
| 74 |
+
{"question": "Pyramids built by?", "options": ["Egyptians", "Romans", "Greeks", "Mayans"], "answer": "Egyptians"},
|
| 75 |
+
{"question": "Who discovered America?", "options": ["Columbus", "Da Gama", "Magellan", "Marco Polo"], "answer": "Columbus"},
|
| 76 |
+
{"question": "Start of Industrial Revolution?", "options": ["England", "France", "USA", "Germany"], "answer": "England"},
|
| 77 |
+
]
|
| 78 |
}
|
| 79 |
|
| 80 |
# ------------------------------
|
|
|
|
| 92 |
is_correct = selected == correct
|
| 93 |
if is_correct:
|
| 94 |
score += 1
|
| 95 |
+
results.append({"question": q["question"], "selected": selected, "correct": correct, "is_correct": is_correct})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
return score, results
|
| 97 |
|
| 98 |
def show_feedback(score):
|
|
|
|
| 108 |
# ------------------------------
|
| 109 |
st.set_page_config(page_title="BrainQuest AI", layout="centered")
|
| 110 |
|
| 111 |
+
# First page welcome screen
|
| 112 |
+
if "started" not in st.session_state:
|
| 113 |
+
st.session_state.started = False
|
| 114 |
+
|
| 115 |
+
if not st.session_state.started:
|
| 116 |
+
st.markdown("""
|
| 117 |
+
<div style='text-align:center;'>
|
| 118 |
+
<h1 style='font-size:48px;'>🎓 Welcome to BrainQuest AI</h1>
|
| 119 |
+
<p style='font-size:24px;'>Test your knowledge across 10 powerful fields</p>
|
| 120 |
+
<br>
|
| 121 |
+
<form action="/">
|
| 122 |
+
<input type="submit" value="🚀 Get Started Now" style="font-size:24px; padding:10px 30px; background-color:#4CAF50; color:white; border:none; border-radius:10px;">
|
| 123 |
+
</form>
|
| 124 |
+
</div>
|
| 125 |
+
""", unsafe_allow_html=True)
|
| 126 |
+
if st.button("Get Started Now"):
|
| 127 |
+
st.session_state.started = True
|
| 128 |
+
st.stop()
|
| 129 |
+
|
| 130 |
+
# Sidebar
|
| 131 |
with st.sidebar:
|
| 132 |
st.title("ℹ️ About")
|
| 133 |
st.markdown("""
|
| 134 |
**🎓 BrainQuest AI**
|
| 135 |
+
- 10 Dynamic Categories
|
|
|
|
| 136 |
- Built with ❤️ by **Sabir Ali**
|
| 137 |
+
- Fully Offline, Fast & Engaging
|
|
|
|
| 138 |
""")
|
| 139 |
|
| 140 |
+
st.title("🧠 Choose a Quiz Category")
|
| 141 |
+
category = st.selectbox("📘 Select Category", list(quizzes.keys()))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
|
| 143 |
+
if st.button("Start Quiz"):
|
| 144 |
st.session_state.questions = load_questions(category)
|
| 145 |
st.session_state.submitted = False
|
| 146 |
for i in range(5):
|
| 147 |
st.session_state[f"answer_{i}"] = None
|
| 148 |
|
| 149 |
+
if "questions" in st.session_state and not st.session_state.submitted:
|
|
|
|
| 150 |
for i, q in enumerate(st.session_state.questions):
|
| 151 |
st.markdown(f"**Q{i+1}:** {q['question']}")
|
| 152 |
st.radio("Your Answer:", q["options"], key=f"answer_{i}", label_visibility="collapsed")
|
|
|
|
| 157 |
score, results = evaluate(st.session_state.questions)
|
| 158 |
show_feedback(score)
|
| 159 |
|
| 160 |
+
st.markdown("## 📊 Results Summary")
|
| 161 |
for i, r in enumerate(results):
|
| 162 |
emoji = "✅" if r["is_correct"] else "❌"
|
| 163 |
st.markdown(f"**Q{i+1}:** {r['question']}")
|
|
|
|
| 166 |
st.markdown(f"- Correct answer: `{r['correct']}`")
|
| 167 |
st.markdown("---")
|
| 168 |
|
| 169 |
+
if st.button("🔁 Try Another Quiz"):
|
| 170 |
st.session_state.questions = []
|
| 171 |
st.session_state.submitted = False
|