Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
# ------------------------------
|
| 4 |
+
# App Setup
|
| 5 |
+
# ------------------------------
|
| 6 |
+
st.set_page_config(page_title="AI For Everyone", layout="centered")
|
| 7 |
+
|
| 8 |
+
# ------------------------------
|
| 9 |
+
# Quiz Data (Expanded Topics)
|
| 10 |
+
# ------------------------------
|
| 11 |
+
ai_modules = {
|
| 12 |
+
"π€ What is AI?": {
|
| 13 |
+
"intro": "Artificial Intelligence (AI) means teaching machines to think, learn, and act like humans. AI can recognize images, understand voices, play games, and even help doctors.",
|
| 14 |
+
"quiz": [
|
| 15 |
+
{"question": "What does AI stand for?", "options": ["Artificial Intelligence", "Automatic Internet", "Advanced Input", "Auto Instruction"], "answer": "Artificial Intelligence"},
|
| 16 |
+
{"question": "Which is an example of AI?", "options": ["Fan", "Refrigerator", "Google Assistant", "Iron"], "answer": "Google Assistant"},
|
| 17 |
+
{"question": "AI can help in which of these?", "options": ["Cooking", "Driving", "Sleeping", "None"], "answer": "Driving"},
|
| 18 |
+
{"question": "What is NOT an AI skill?", "options": ["Talking", "Sleeping", "Recognizing faces", "Learning"], "answer": "Sleeping"},
|
| 19 |
+
{"question": "AI is used in which app?", "options": ["YouTube", "Alarm Clock", "Torch", "Calendar"], "answer": "YouTube"},
|
| 20 |
+
]
|
| 21 |
+
},
|
| 22 |
+
"π¬ How ChatGPT Works": {
|
| 23 |
+
"intro": "ChatGPT is a type of AI that understands your questions and gives smart answers using a large amount of text data it learned from books, websites, and more.",
|
| 24 |
+
"quiz": [
|
| 25 |
+
{"question": "What is ChatGPT?", "options": ["Robot", "AI Chatbot", "Game", "Website"], "answer": "AI Chatbot"},
|
| 26 |
+
{"question": "Who created ChatGPT?", "options": ["Google", "Meta", "OpenAI", "Amazon"], "answer": "OpenAI"},
|
| 27 |
+
{"question": "ChatGPT learns from?", "options": ["Internet Data", "Photos", "TV Shows", "Music"], "answer": "Internet Data"},
|
| 28 |
+
{"question": "What can ChatGPT NOT do?", "options": ["Talk to you", "Predict future", "Write articles", "Translate text"], "answer": "Predict future"},
|
| 29 |
+
{"question": "ChatGPT gives answers based on?", "options": ["Magic", "Guess", "Trained data", "Surprise"], "answer": "Trained data"},
|
| 30 |
+
]
|
| 31 |
+
},
|
| 32 |
+
"π§ Types of AI": {
|
| 33 |
+
"intro": "There are three types of AI: Narrow AI (used in one task), General AI (like a human brain), and Super AI (stronger than humans β still in the future).",
|
| 34 |
+
"quiz": [
|
| 35 |
+
{"question": "Which AI is used in Siri or Alexa?", "options": ["Super AI", "General AI", "Narrow AI", "No AI"], "answer": "Narrow AI"},
|
| 36 |
+
{"question": "Which AI doesn't exist yet?", "options": ["Narrow AI", "Super AI", "ChatGPT", "Machine Learning"], "answer": "Super AI"},
|
| 37 |
+
{"question": "Which AI is as smart as humans?", "options": ["Super AI", "General AI", "Narrow AI", "Simple AI"], "answer": "General AI"},
|
| 38 |
+
{"question": "ChatGPT is an example of?", "options": ["Super AI", "Narrow AI", "General AI", "Real Brain"], "answer": "Narrow AI"},
|
| 39 |
+
{"question": "Which is used today in real life?", "options": ["General AI", "Super AI", "Narrow AI", "None"], "answer": "Narrow AI"},
|
| 40 |
+
]
|
| 41 |
+
},
|
| 42 |
+
"π AI in Daily Life": {
|
| 43 |
+
"intro": "AI helps us every day β in phones (face unlock), YouTube (video suggestions), hospitals (disease detection), farming (smart irrigation), and more.",
|
| 44 |
+
"quiz": [
|
| 45 |
+
{"question": "AI is used in which app?", "options": ["Clock", "YouTube", "Flashlight", "Calculator"], "answer": "YouTube"},
|
| 46 |
+
{"question": "Face unlock uses which tech?", "options": ["AI", "Password", "Fingerprint", "QR code"], "answer": "AI"},
|
| 47 |
+
{"question": "AI helps doctors by?", "options": ["Playing music", "Writing books", "Detecting diseases", "Making beds"], "answer": "Detecting diseases"},
|
| 48 |
+
{"question": "Which field uses AI for crops?", "options": ["Medicine", "Farming", "Sports", "Cooking"], "answer": "Farming"},
|
| 49 |
+
{"question": "AI helps in?", "options": ["Sleeping", "Decision Making", "Singing", "Jumping"], "answer": "Decision Making"},
|
| 50 |
+
]
|
| 51 |
+
},
|
| 52 |
+
"π§ ML vs DL": {
|
| 53 |
+
"intro": "Machine Learning (ML) means teaching computers to learn from data. Deep Learning (DL) is a special kind of ML that uses layers like the human brain to solve harder problems.",
|
| 54 |
+
"quiz": [
|
| 55 |
+
{"question": "What does ML stand for?", "options": ["Manual Learning", "Machine Learning", "Mobile Learning", "Mind Learning"], "answer": "Machine Learning"},
|
| 56 |
+
{"question": "Deep Learning is a part of?", "options": ["Cooking", "Manual Work", "Machine Learning", "Google Search"], "answer": "Machine Learning"},
|
| 57 |
+
{"question": "Which uses brain-like layers?", "options": ["Spreadsheet", "Deep Learning", "Wi-Fi", "TV"], "answer": "Deep Learning"},
|
| 58 |
+
{"question": "Which can recognize images better?", "options": ["ML", "DL", "Fan", "Clock"], "answer": "DL"},
|
| 59 |
+
{"question": "Which needs more data to work?", "options": ["Deep Learning", "Manual Typing", "Fan", "Wi-Fi"], "answer": "Deep Learning"},
|
| 60 |
+
]
|
| 61 |
+
},
|
| 62 |
+
"π Deepfakes & Misinformation": {
|
| 63 |
+
"intro": "Deepfakes are fake videos made by AI to look real. They can trick people. Always check information before believing or sharing it.",
|
| 64 |
+
"quiz": [
|
| 65 |
+
{"question": "What is a deepfake?", "options": ["Real video", "Fake video by AI", "Game", "News channel"], "answer": "Fake video by AI"},
|
| 66 |
+
{"question": "Deepfakes can be used to?", "options": ["Trick people", "Cook food", "Clean house", "Drive car"], "answer": "Trick people"},
|
| 67 |
+
{"question": "How to avoid fake news?", "options": ["Trust all", "Check source", "Believe WhatsApp", "Guess it"], "answer": "Check source"},
|
| 68 |
+
{"question": "Deepfake danger is?", "options": ["Confusion", "Truth", "Help", "Fun"], "answer": "Confusion"},
|
| 69 |
+
{"question": "AI can create fake?", "options": ["Videos", "Trees", "Rivers", "Mountains"], "answer": "Videos"},
|
| 70 |
+
]
|
| 71 |
+
},
|
| 72 |
+
"π‘οΈ Data Privacy Basics": {
|
| 73 |
+
"intro": "Data privacy means keeping your personal info like name, photos, and location safe. Be careful what apps you use and what info you share.",
|
| 74 |
+
"quiz": [
|
| 75 |
+
{"question": "What is data privacy?", "options": ["Hiding phone", "Protecting personal data", "Making calls", "Buying things"], "answer": "Protecting personal data"},
|
| 76 |
+
{"question": "Which is personal data?", "options": ["Your name", "Weather", "Public park", "Clouds"], "answer": "Your name"},
|
| 77 |
+
{"question": "You should not share?", "options": ["Passwords", "Jokes", "Games", "Songs"], "answer": "Passwords"},
|
| 78 |
+
{"question": "Which app is risky?", "options": ["Unknown apps", "Calculator", "Camera", "Clock"], "answer": "Unknown apps"},
|
| 79 |
+
{"question": "Privacy keeps you?", "options": ["Safe", "Famous", "Hungry", "Busy"], "answer": "Safe"},
|
| 80 |
+
]
|
| 81 |
+
},
|
| 82 |
+
"π§ Ethics in AI": {
|
| 83 |
+
"intro": "Ethics in AI means using technology in a fair, safe, and kind way. AI should not hurt anyone or spread lies.",
|
| 84 |
+
"quiz": [
|
| 85 |
+
{"question": "What is AI ethics?", "options": ["Rules for using AI", "Games", "Coding", "Downloads"], "answer": "Rules for using AI"},
|
| 86 |
+
{"question": "AI should be?", "options": ["Fair", "Biased", "Mean", "Secret"], "answer": "Fair"},
|
| 87 |
+
{"question": "Bad AI use can?", "options": ["Hurt people", "Help friends", "Cook food", "Clean room"], "answer": "Hurt people"},
|
| 88 |
+
{"question": "Ethics help us to?", "options": ["Do right", "Sleep more", "Eat fast", "Buy apps"], "answer": "Do right"},
|
| 89 |
+
{"question": "AI must be checked for?", "options": ["Bias", "Fun", "Color", "Music"], "answer": "Bias"},
|
| 90 |
+
]
|
| 91 |
+
}
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
# ------------------------------
|
| 95 |
+
# Helper Functions
|
| 96 |
+
# ------------------------------
|
| 97 |
+
def show_intro_and_quiz(topic):
|
| 98 |
+
module = ai_modules[topic]
|
| 99 |
+
st.markdown(f"### π Topic: {topic}")
|
| 100 |
+
st.info(module["intro"])
|
| 101 |
+
st.markdown("---")
|
| 102 |
+
st.markdown("#### π Quiz Time")
|
| 103 |
+
|
| 104 |
+
score = 0
|
| 105 |
+
for i, q in enumerate(module["quiz"]):
|
| 106 |
+
selected = st.radio(f"**Q{i+1}: {q['question']}**", q['options'], key=f"{topic}_q{i}")
|
| 107 |
+
if selected == q['answer']:
|
| 108 |
+
score += 1
|
| 109 |
+
|
| 110 |
+
if st.button("β
Submit Quiz", key=f"submit_{topic}"):
|
| 111 |
+
st.success(f"You scored {score} out of {len(module['quiz'])}!")
|
| 112 |
+
st.markdown("---")
|
| 113 |
+
for i, q in enumerate(module["quiz"]):
|
| 114 |
+
correct = q['answer']
|
| 115 |
+
st.markdown(f"**Q{i+1}: {q['question']}**")
|
| 116 |
+
st.markdown(f"β
Correct Answer: `{correct}`")
|
| 117 |
+
st.markdown("---")
|
| 118 |
+
|
| 119 |
+
# ------------------------------
|
| 120 |
+
# UI Logic
|
| 121 |
+
# ------------------------------
|
| 122 |
+
if "started" not in st.session_state:
|
| 123 |
+
st.session_state.started = False
|
| 124 |
+
|
| 125 |
+
if not st.session_state.started:
|
| 126 |
+
st.markdown("""
|
| 127 |
+
<div style='text-align:center;'>
|
| 128 |
+
<h1 style='font-size:48px;'>π€ AI For Everyone</h1>
|
| 129 |
+
<p style='font-size:22px;'>Learn AI in simple language β made for every person</p>
|
| 130 |
+
</div>
|
| 131 |
+
""", unsafe_allow_html=True)
|
| 132 |
+
|
| 133 |
+
if st.button("π Start Learning Now", key="start_button"):
|
| 134 |
+
st.session_state.started = True
|
| 135 |
+
st.stop()
|
| 136 |
+
|
| 137 |
+
# Main App
|
| 138 |
+
st.sidebar.title("π Topics")
|
| 139 |
+
st.sidebar.markdown("Select any topic to begin.")
|
| 140 |
+
selected_topic = st.selectbox("Choose a topic:", list(ai_modules.keys()))
|
| 141 |
+
|
| 142 |
+
if selected_topic:
|
| 143 |
+
show_intro_and_quiz(selected_topic)
|
| 144 |
+
|
| 145 |
+
st.sidebar.markdown("---")
|
| 146 |
+
st.sidebar.markdown("Built with β€οΈ by **Sabir Ali**")
|