maria355 commited on
Commit
b3d49bc
·
verified ·
1 Parent(s): a85c088

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +119 -111
app.py CHANGED
@@ -1130,66 +1130,42 @@ def add_agentic_ai_info():
1130
 
1131
  def create_chatbot():
1132
  """Create the Gradio interface for the chatbot"""
 
1133
  session_id = str(uuid.uuid4())
1134
-
 
1135
  primary_color = "#4a6fa5"
1136
  secondary_color = "#6c757d"
1137
  success_color = "#28a745"
1138
  light_color = "#f8f9fa"
1139
  dark_color = "#343a40"
1140
-
1141
  custom_css = f"""
1142
  :root {{
1143
  --primary-color: {primary_color};
1144
  --secondary-color: {secondary_color};
1145
  --success-color: {success_color};
1146
- --light-bg: {light_color};
1147
- --dark-bg: {dark_color};
1148
- --text-light: #212529;
1149
- --text-dark: #f1f1f1;
1150
- }}
1151
-
1152
- .gradio-container {{
1153
- background-color: var(--light-bg);
1154
- color: var(--text-light);
1155
- font-family: 'Inter', 'Segoe UI', sans-serif;
1156
- }}
1157
-
1158
- .gr-markdown-output, .gr-textbox textarea {{
1159
- color: var(--text-light);
1160
- background-color: white;
1161
  }}
1162
-
1163
- @media (prefers-color-scheme: dark) {{
1164
- .gradio-container {{
1165
- background-color: var(--dark-bg);
1166
- color: var(--text-dark);
1167
- }}
1168
- .gr-markdown-output, .gr-textbox textarea {{
1169
- color: var(--text-dark);
1170
- background-color: #1e1e1e;
1171
- }}
1172
- .card {{
1173
- background-color: #2c2c2c;
1174
- }}
1175
  }}
1176
-
1177
- #title {{
1178
- font-size: 32px;
1179
- font-weight: bold;
1180
- text-align: center;
1181
- padding-top: 20px;
1182
  color: var(--primary-color);
1183
  margin-bottom: 0;
1184
  }}
1185
-
1186
- #subtitle {{
1187
- font-size: 18px;
1188
- text-align: center;
1189
- margin-bottom: 20px;
1190
- color: var(--secondary-color);
1191
  }}
1192
-
1193
  .card {{
1194
  background-color: white;
1195
  padding: 20px;
@@ -1197,23 +1173,18 @@ def create_chatbot():
1197
  box-shadow: 0 4px 10px rgba(0,0,0,0.08);
1198
  margin-bottom: 20px;
1199
  }}
1200
-
1201
  .tabs {{
1202
  margin-top: 20px;
1203
  }}
1204
-
1205
- .gr-button-primary {{
1206
- background-color: var(--primary-color) !important;
1207
  }}
1208
-
1209
- .gr-button-secondary {{
1210
- background-color: var(--secondary-color) !important;
1211
  }}
1212
-
1213
- .gr-button-success {{
1214
- background-color: var(--success-color) !important;
1215
  }}
1216
-
1217
  .footer {{
1218
  text-align: center;
1219
  margin-top: 30px;
@@ -1221,18 +1192,15 @@ def create_chatbot():
1221
  font-size: 14px;
1222
  color: var(--secondary-color);
1223
  }}
1224
-
1225
  .progress-module {{
1226
  padding: 10px;
1227
  margin: 5px 0;
1228
  border-radius: 5px;
1229
  background-color: #e9ecef;
1230
  }}
1231
-
1232
  .progress-module.completed {{
1233
  background-color: #d4edda;
1234
  }}
1235
-
1236
  .info-box {{
1237
  background-color: #e7f5fe;
1238
  border-left: 4px solid var(--primary-color);
@@ -1241,38 +1209,44 @@ def create_chatbot():
1241
  border-radius: 4px;
1242
  }}
1243
  """
1244
-
1245
  with gr.Blocks(css=custom_css, theme=gr.themes.Soft(primary_hue="blue")) as demo:
1246
  gr.HTML("<div id='title'>🎓 AI Teaching Assistant</div>")
1247
  gr.HTML("<div id='subtitle'>Your personalized learning companion for Python, Data Science & AI</div>")
1248
-
1249
- with gr.Tabs(elem_classes=["tabs"]):
 
 
1250
  with gr.Tab("Profile & Goals"):
1251
  with gr.Column(elem_classes=["card"]):
1252
  gr.HTML("<h3>Complete Your Learning Profile</h3>")
1253
-
1254
  with gr.Row():
1255
  with gr.Column(scale=1):
1256
- age_input = gr.Textbox(label="Age", placeholder="e.g. 20", lines=1)
 
 
 
 
1257
  with gr.Column(scale=2):
1258
  knowledge_level_input = gr.Dropdown(
1259
  choices=["Beginner", "Intermediate", "Advanced", "Expert"],
1260
  label="Knowledge Level",
1261
  value="Beginner"
1262
  )
1263
-
1264
  goals_input = gr.Textbox(
1265
- label="Learning Goals",
1266
- placeholder="e.g. I want to become a data scientist...",
1267
  lines=2
1268
  )
1269
-
1270
  interests_input = gr.Textbox(
1271
- label="Specific Interests",
1272
- placeholder="e.g. Python, data visualization...",
1273
  lines=2
1274
  )
1275
-
1276
  with gr.Row():
1277
  with gr.Column(scale=1):
1278
  study_time_input = gr.Dropdown(
@@ -1282,17 +1256,15 @@ def create_chatbot():
1282
  )
1283
  with gr.Column(scale=2):
1284
  learning_style_input = gr.Dropdown(
1285
- choices=[
1286
- "Visual", "Reading/Writing", "Hands-on Projects",
1287
- "Video Tutorials", "Interactive Exercises", "Combination"
1288
- ],
1289
  label="Preferred Learning Style",
1290
  value="Combination"
1291
  )
1292
-
1293
  profile_submit_btn = gr.Button("Save Profile & Generate Recommendations", variant="primary")
1294
  profile_output = gr.Markdown(label="Personalized Recommendations")
1295
-
 
1296
  with gr.Tab("Learning Assistant"):
1297
  with gr.Row():
1298
  with gr.Column(elem_classes=["card"]):
@@ -1301,74 +1273,110 @@ def create_chatbot():
1301
  placeholder="Ask anything about Python, Data Science, AI...",
1302
  lines=3
1303
  )
 
1304
  with gr.Row():
1305
  chat_submit_btn = gr.Button("Send Message", variant="primary")
1306
  chat_clear_btn = gr.Button("Clear Chat", variant="secondary")
 
1307
  chat_output = gr.Markdown(label="Assistant Response")
1308
-
 
1309
  with gr.Tab("Resources & Recommendations"):
1310
  with gr.Column(elem_classes=["card"]):
1311
  gr.HTML("<h3>Your Learning Resources</h3>")
1312
  refresh_recommendations_btn = gr.Button("Refresh Recommendations", variant="primary")
1313
  recommendations_output = gr.Markdown(label="Personalized Recommendations")
1314
-
 
1315
  with gr.Tab("Practice & Assessment"):
1316
  with gr.Column(elem_classes=["card"]):
1317
  gr.HTML("<h3>Generate a Quiz</h3>")
 
1318
  with gr.Row():
1319
- quiz_topic_input = gr.Textbox(label="Quiz Topic", placeholder="e.g. Python Lists")
 
 
 
 
1320
  quiz_difficulty_input = gr.Dropdown(
1321
  choices=["Beginner", "Intermediate", "Advanced"],
1322
  label="Difficulty Level",
1323
  value="Beginner"
1324
  )
 
1325
  generate_quiz_btn = gr.Button("Generate Quiz", variant="primary")
1326
  quiz_output = gr.Markdown(label="Quiz")
1327
-
 
1328
  with gr.Tab("Study Plan"):
1329
  with gr.Column(elem_classes=["card"]):
1330
  gr.HTML("<h3>Generate a Personalized Study Plan</h3>")
 
1331
  with gr.Row():
1332
- plan_topic_input = gr.Textbox(label="Study Topic", placeholder="e.g. Data Science")
 
 
 
 
1333
  plan_time_input = gr.Dropdown(
1334
  choices=["1-3", "4-6", "7-10", "10+"],
1335
  label="Hours Available Weekly",
1336
  value="4-6"
1337
  )
 
1338
  generate_plan_btn = gr.Button("Generate Study Plan", variant="primary")
1339
  plan_output = gr.Markdown(label="Personalized Study Plan")
1340
-
1341
- gr.HTML("""<div class="footer">AI Teaching Assistant | Version 2.0 | © 2025 | Powered by Groq AI</div>""")
1342
-
 
 
1343
  # Event handlers
1344
- profile_submit_btn.click(user_onboarding,
1345
- inputs=[
1346
- gr.State(session_id), age_input, goals_input,
1347
- knowledge_level_input, interests_input,
1348
- study_time_input, learning_style_input
1349
- ],
1350
- outputs=profile_output)
1351
-
1352
- chat_submit_btn.click(chatbot_interface,
1353
- inputs=[gr.State(session_id), chat_input],
1354
- outputs=chat_output)
1355
-
1356
- chat_clear_btn.click(lambda: "", inputs=[], outputs=[chat_output, chat_input])
1357
-
1358
- refresh_recommendations_btn.click(generate_recommendations,
1359
- inputs=[gr.State(session_id)],
1360
- outputs=recommendations_output)
1361
-
1362
- generate_quiz_btn.click(handle_quiz_request,
1363
- inputs=[gr.State(session_id), quiz_topic_input, quiz_difficulty_input],
1364
- outputs=quiz_output)
1365
-
1366
- generate_plan_btn.click(handle_study_plan_request,
1367
- inputs=[gr.State(session_id), plan_topic_input, plan_time_input],
1368
- outputs=plan_output)
1369
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1370
  return demo
1371
-
1372
  if __name__ == "__main__":
1373
  app = create_chatbot()
1374
- app.launch()
 
1130
 
1131
  def create_chatbot():
1132
  """Create the Gradio interface for the chatbot"""
1133
+ # Generate a random session ID for the user
1134
  session_id = str(uuid.uuid4())
1135
+
1136
+ # Define theme colors and styling
1137
  primary_color = "#4a6fa5"
1138
  secondary_color = "#6c757d"
1139
  success_color = "#28a745"
1140
  light_color = "#f8f9fa"
1141
  dark_color = "#343a40"
1142
+
1143
  custom_css = f"""
1144
  :root {{
1145
  --primary-color: {primary_color};
1146
  --secondary-color: {secondary_color};
1147
  --success-color: {success_color};
1148
+ --light-color: {light_color};
1149
+ --dark-color: {dark_color};
 
 
 
 
 
 
 
 
 
 
 
 
 
1150
  }}
1151
+ .gradio-container {{
1152
+ background-color: var(--light-color);
1153
+ font-family: 'Inter', 'Segoe UI', sans-serif;
 
 
 
 
 
 
 
 
 
 
1154
  }}
1155
+ #title {{
1156
+ font-size: 32px;
1157
+ font-wedef create_chatbot()ight: bold;
1158
+ text-align: center;
1159
+ padding-top: 20px;
 
1160
  color: var(--primary-color);
1161
  margin-bottom: 0;
1162
  }}
1163
+ #subtitle {{
1164
+ font-size: 18px;
1165
+ text-align: center;
1166
+ margin-bottom: 20px;
1167
+ color: var(--secondary-color);
 
1168
  }}
 
1169
  .card {{
1170
  background-color: white;
1171
  padding: 20px;
 
1173
  box-shadow: 0 4px 10px rgba(0,0,0,0.08);
1174
  margin-bottom: 20px;
1175
  }}
 
1176
  .tabs {{
1177
  margin-top: 20px;
1178
  }}
1179
+ .gr-button-primary {{
1180
+ background-color: var(--primary-color) !important;
 
1181
  }}
1182
+ .gr-button-secondary {{
1183
+ background-color: var(--secondary-color) !important;
 
1184
  }}
1185
+ .gr-button-success {{
1186
+ background-color: var(--success-color) !important;
 
1187
  }}
 
1188
  .footer {{
1189
  text-align: center;
1190
  margin-top: 30px;
 
1192
  font-size: 14px;
1193
  color: var(--secondary-color);
1194
  }}
 
1195
  .progress-module {{
1196
  padding: 10px;
1197
  margin: 5px 0;
1198
  border-radius: 5px;
1199
  background-color: #e9ecef;
1200
  }}
 
1201
  .progress-module.completed {{
1202
  background-color: #d4edda;
1203
  }}
 
1204
  .info-box {{
1205
  background-color: #e7f5fe;
1206
  border-left: 4px solid var(--primary-color);
 
1209
  border-radius: 4px;
1210
  }}
1211
  """
1212
+
1213
  with gr.Blocks(css=custom_css, theme=gr.themes.Soft(primary_hue="blue")) as demo:
1214
  gr.HTML("<div id='title'>🎓 AI Teaching Assistant</div>")
1215
  gr.HTML("<div id='subtitle'>Your personalized learning companion for Python, Data Science & AI</div>")
1216
+
1217
+ # Tabs for different sections
1218
+ with gr.Tabs(elem_classes=["tabs"]) as tabs:
1219
+ # Profile Tab
1220
  with gr.Tab("Profile & Goals"):
1221
  with gr.Column(elem_classes=["card"]):
1222
  gr.HTML("<h3>Complete Your Learning Profile</h3>")
1223
+
1224
  with gr.Row():
1225
  with gr.Column(scale=1):
1226
+ age_input = gr.Textbox(
1227
+ label="Age",
1228
+ placeholder="e.g. 20",
1229
+ lines=1
1230
+ )
1231
  with gr.Column(scale=2):
1232
  knowledge_level_input = gr.Dropdown(
1233
  choices=["Beginner", "Intermediate", "Advanced", "Expert"],
1234
  label="Knowledge Level",
1235
  value="Beginner"
1236
  )
1237
+
1238
  goals_input = gr.Textbox(
1239
+ label="Learning Goals",
1240
+ placeholder="e.g. I want to become a data scientist and work with machine learning models",
1241
  lines=2
1242
  )
1243
+
1244
  interests_input = gr.Textbox(
1245
+ label="Specific Interests",
1246
+ placeholder="e.g. Python, data visualization, neural networks",
1247
  lines=2
1248
  )
1249
+
1250
  with gr.Row():
1251
  with gr.Column(scale=1):
1252
  study_time_input = gr.Dropdown(
 
1256
  )
1257
  with gr.Column(scale=2):
1258
  learning_style_input = gr.Dropdown(
1259
+ choices=["Visual", "Reading/Writing", "Hands-on Projects", "Video Tutorials", "Interactive Exercises", "Combination"],
 
 
 
1260
  label="Preferred Learning Style",
1261
  value="Combination"
1262
  )
1263
+
1264
  profile_submit_btn = gr.Button("Save Profile & Generate Recommendations", variant="primary")
1265
  profile_output = gr.Markdown(label="Personalized Recommendations")
1266
+
1267
+ # Chat Tab
1268
  with gr.Tab("Learning Assistant"):
1269
  with gr.Row():
1270
  with gr.Column(elem_classes=["card"]):
 
1273
  placeholder="Ask anything about Python, Data Science, AI...",
1274
  lines=3
1275
  )
1276
+
1277
  with gr.Row():
1278
  chat_submit_btn = gr.Button("Send Message", variant="primary")
1279
  chat_clear_btn = gr.Button("Clear Chat", variant="secondary")
1280
+
1281
  chat_output = gr.Markdown(label="Assistant Response")
1282
+
1283
+ # Resources Tab
1284
  with gr.Tab("Resources & Recommendations"):
1285
  with gr.Column(elem_classes=["card"]):
1286
  gr.HTML("<h3>Your Learning Resources</h3>")
1287
  refresh_recommendations_btn = gr.Button("Refresh Recommendations", variant="primary")
1288
  recommendations_output = gr.Markdown(label="Personalized Recommendations")
1289
+
1290
+ # Practice Tab
1291
  with gr.Tab("Practice & Assessment"):
1292
  with gr.Column(elem_classes=["card"]):
1293
  gr.HTML("<h3>Generate a Quiz</h3>")
1294
+
1295
  with gr.Row():
1296
+ quiz_topic_input = gr.Textbox(
1297
+ label="Quiz Topic",
1298
+ placeholder="e.g. Python Lists",
1299
+ lines=1
1300
+ )
1301
  quiz_difficulty_input = gr.Dropdown(
1302
  choices=["Beginner", "Intermediate", "Advanced"],
1303
  label="Difficulty Level",
1304
  value="Beginner"
1305
  )
1306
+
1307
  generate_quiz_btn = gr.Button("Generate Quiz", variant="primary")
1308
  quiz_output = gr.Markdown(label="Quiz")
1309
+
1310
+ # Study Plan Tab
1311
  with gr.Tab("Study Plan"):
1312
  with gr.Column(elem_classes=["card"]):
1313
  gr.HTML("<h3>Generate a Personalized Study Plan</h3>")
1314
+
1315
  with gr.Row():
1316
+ plan_topic_input = gr.Textbox(
1317
+ label="Study Topic",
1318
+ placeholder="e.g. Data Science",
1319
+ lines=1
1320
+ )
1321
  plan_time_input = gr.Dropdown(
1322
  choices=["1-3", "4-6", "7-10", "10+"],
1323
  label="Hours Available Weekly",
1324
  value="4-6"
1325
  )
1326
+
1327
  generate_plan_btn = gr.Button("Generate Study Plan", variant="primary")
1328
  plan_output = gr.Markdown(label="Personalized Study Plan")
1329
+
1330
+ gr.HTML("""<div class="footer">
1331
+ AI Teaching Assistant | Version 2.0 | © 2025 | Powered by Groq AI
1332
+ </div>""")
1333
+
1334
  # Event handlers
1335
+ profile_submit_btn.click(
1336
+ user_onboarding,
1337
+ inputs=[
1338
+ gr.State(session_id),
1339
+ age_input,
1340
+ goals_input,
1341
+ knowledge_level_input,
1342
+ interests_input,
1343
+ study_time_input,
1344
+ learning_style_input
1345
+ ],
1346
+ outputs=profile_output
1347
+ )
1348
+
1349
+ chat_submit_btn.click(
1350
+ chatbot_interface,
1351
+ inputs=[gr.State(session_id), chat_input],
1352
+ outputs=chat_output
1353
+ )
1354
+
1355
+ chat_clear_btn.click(
1356
+ lambda: "",
1357
+ inputs=[],
1358
+ outputs=[chat_output, chat_input]
1359
+ )
1360
+
1361
+ refresh_recommendations_btn.click(
1362
+ generate_recommendations,
1363
+ inputs=[gr.State(session_id)],
1364
+ outputs=recommendations_output
1365
+ )
1366
+
1367
+ generate_quiz_btn.click(
1368
+ handle_quiz_request,
1369
+ inputs=[gr.State(session_id), quiz_topic_input, quiz_difficulty_input],
1370
+ outputs=quiz_output
1371
+ )
1372
+
1373
+ generate_plan_btn.click(
1374
+ handle_study_plan_request,
1375
+ inputs=[gr.State(session_id), plan_topic_input, plan_time_input],
1376
+ outputs=plan_output
1377
+ )
1378
+
1379
  return demo
 
1380
  if __name__ == "__main__":
1381
  app = create_chatbot()
1382
+ app.launch()