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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +147 -195
app.py CHANGED
@@ -1130,163 +1130,149 @@ def add_agentic_ai_info():
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
-
1152
- .gradio-container {{
1153
- background-color: var(--light-color);
1154
- color: #212529;
1155
- font-family: 'Inter', 'Segoe UI', sans-serif;
1156
- }}
1157
-
1158
- /* Dark mode support */
1159
- @media (prefers-color-scheme: dark) {{
1160
  .gradio-container {{
1161
- background-color: #1e1e1e;
1162
- color: #f1f1f1;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1163
  }}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1164
  .card {{
1165
- background-color: #2c2c2c;
1166
- color: #f1f1f1;
 
 
 
1167
  }}
1168
- .info-box {{
1169
- background-color: #1a1f24;
1170
- border-left-color: #5daeff;
 
 
 
 
1171
  }}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1172
  .progress-module {{
1173
- background-color: #2d2d2d;
 
 
 
1174
  }}
 
1175
  .progress-module.completed {{
1176
- background-color: #224422;
1177
  }}
1178
- .footer {{
1179
- color: #aaaaaa;
 
 
 
 
 
1180
  }}
1181
- }}
1182
-
1183
- #title {{
1184
- font-size: 32px;
1185
- font-weight: bold;
1186
- text-align: center;
1187
- padding-top: 20px;
1188
- color: var(--primary-color);
1189
- margin-bottom: 0;
1190
- }}
1191
-
1192
- #subtitle {{
1193
- font-size: 18px;
1194
- text-align: center;
1195
- margin-bottom: 20px;
1196
- color: var(--secondary-color);
1197
- }}
1198
-
1199
- .card {{
1200
- background-color: white;
1201
- padding: 20px;
1202
- border-radius: 12px;
1203
- box-shadow: 0 4px 10px rgba(0,0,0,0.08);
1204
- margin-bottom: 20px;
1205
- }}
1206
-
1207
- .tabs {{
1208
- margin-top: 20px;
1209
- }}
1210
-
1211
- .gr-button-primary {{
1212
- background-color: var(--primary-color) !important;
1213
- color: white !important;
1214
- }}
1215
-
1216
- .gr-button-secondary {{
1217
- background-color: var(--secondary-color) !important;
1218
- color: white !important;
1219
- }}
1220
-
1221
- .gr-button-success {{
1222
- background-color: var(--success-color) !important;
1223
- color: white !important;
1224
- }}
1225
-
1226
- .footer {{
1227
- text-align: center;
1228
- margin-top: 30px;
1229
- padding: 10px;
1230
- font-size: 14px;
1231
- color: var(--secondary-color);
1232
- }}
1233
-
1234
- .progress-module {{
1235
- padding: 10px;
1236
- margin: 5px 0;
1237
- border-radius: 5px;
1238
- background-color: #e9ecef;
1239
- }}
1240
-
1241
- .progress-module.completed {{
1242
- background-color: #d4edda;
1243
- }}
1244
-
1245
- .info-box {{
1246
- background-color: #e7f5fe;
1247
- border-left: 4px solid var(--primary-color);
1248
- padding: 15px;
1249
- margin: 15px 0;
1250
- border-radius: 4px;
1251
- }}
1252
  """
 
1253
  with gr.Blocks(css=custom_css, theme=gr.themes.Soft(primary_hue="blue")) as demo:
1254
  gr.HTML("<div id='title'>🎓 AI Teaching Assistant</div>")
1255
  gr.HTML("<div id='subtitle'>Your personalized learning companion for Python, Data Science & AI</div>")
1256
-
1257
- # Tabs for different sections
1258
- with gr.Tabs(elem_classes=["tabs"]) as tabs:
1259
- # Profile Tab
1260
  with gr.Tab("Profile & Goals"):
1261
  with gr.Column(elem_classes=["card"]):
1262
  gr.HTML("<h3>Complete Your Learning Profile</h3>")
1263
-
1264
  with gr.Row():
1265
  with gr.Column(scale=1):
1266
- age_input = gr.Textbox(
1267
- label="Age",
1268
- placeholder="e.g. 20",
1269
- lines=1
1270
- )
1271
  with gr.Column(scale=2):
1272
  knowledge_level_input = gr.Dropdown(
1273
  choices=["Beginner", "Intermediate", "Advanced", "Expert"],
1274
  label="Knowledge Level",
1275
  value="Beginner"
1276
  )
1277
-
1278
  goals_input = gr.Textbox(
1279
- label="Learning Goals",
1280
- placeholder="e.g. I want to become a data scientist and work with machine learning models",
1281
  lines=2
1282
  )
1283
-
1284
  interests_input = gr.Textbox(
1285
- label="Specific Interests",
1286
- placeholder="e.g. Python, data visualization, neural networks",
1287
  lines=2
1288
  )
1289
-
1290
  with gr.Row():
1291
  with gr.Column(scale=1):
1292
  study_time_input = gr.Dropdown(
@@ -1296,15 +1282,17 @@ def create_chatbot():
1296
  )
1297
  with gr.Column(scale=2):
1298
  learning_style_input = gr.Dropdown(
1299
- choices=["Visual", "Reading/Writing", "Hands-on Projects", "Video Tutorials", "Interactive Exercises", "Combination"],
 
 
 
1300
  label="Preferred Learning Style",
1301
  value="Combination"
1302
  )
1303
-
1304
  profile_submit_btn = gr.Button("Save Profile & Generate Recommendations", variant="primary")
1305
  profile_output = gr.Markdown(label="Personalized Recommendations")
1306
-
1307
- # Chat Tab
1308
  with gr.Tab("Learning Assistant"):
1309
  with gr.Row():
1310
  with gr.Column(elem_classes=["card"]):
@@ -1313,110 +1301,74 @@ def create_chatbot():
1313
  placeholder="Ask anything about Python, Data Science, AI...",
1314
  lines=3
1315
  )
1316
-
1317
  with gr.Row():
1318
  chat_submit_btn = gr.Button("Send Message", variant="primary")
1319
  chat_clear_btn = gr.Button("Clear Chat", variant="secondary")
1320
-
1321
  chat_output = gr.Markdown(label="Assistant Response")
1322
-
1323
- # Resources Tab
1324
  with gr.Tab("Resources & Recommendations"):
1325
  with gr.Column(elem_classes=["card"]):
1326
  gr.HTML("<h3>Your Learning Resources</h3>")
1327
  refresh_recommendations_btn = gr.Button("Refresh Recommendations", variant="primary")
1328
  recommendations_output = gr.Markdown(label="Personalized Recommendations")
1329
-
1330
- # Practice Tab
1331
  with gr.Tab("Practice & Assessment"):
1332
  with gr.Column(elem_classes=["card"]):
1333
  gr.HTML("<h3>Generate a Quiz</h3>")
1334
-
1335
  with gr.Row():
1336
- quiz_topic_input = gr.Textbox(
1337
- label="Quiz Topic",
1338
- placeholder="e.g. Python Lists",
1339
- lines=1
1340
- )
1341
  quiz_difficulty_input = gr.Dropdown(
1342
  choices=["Beginner", "Intermediate", "Advanced"],
1343
  label="Difficulty Level",
1344
  value="Beginner"
1345
  )
1346
-
1347
  generate_quiz_btn = gr.Button("Generate Quiz", variant="primary")
1348
  quiz_output = gr.Markdown(label="Quiz")
1349
-
1350
- # Study Plan Tab
1351
  with gr.Tab("Study Plan"):
1352
  with gr.Column(elem_classes=["card"]):
1353
  gr.HTML("<h3>Generate a Personalized Study Plan</h3>")
1354
-
1355
  with gr.Row():
1356
- plan_topic_input = gr.Textbox(
1357
- label="Study Topic",
1358
- placeholder="e.g. Data Science",
1359
- lines=1
1360
- )
1361
  plan_time_input = gr.Dropdown(
1362
  choices=["1-3", "4-6", "7-10", "10+"],
1363
  label="Hours Available Weekly",
1364
  value="4-6"
1365
  )
1366
-
1367
  generate_plan_btn = gr.Button("Generate Study Plan", variant="primary")
1368
  plan_output = gr.Markdown(label="Personalized Study Plan")
1369
-
1370
- gr.HTML("""<div class="footer">
1371
- AI Teaching Assistant | Version 2.0 | © 2025 | Powered by Groq AI
1372
- </div>""")
1373
-
1374
  # Event handlers
1375
- profile_submit_btn.click(
1376
- user_onboarding,
1377
- inputs=[
1378
- gr.State(session_id),
1379
- age_input,
1380
- goals_input,
1381
- knowledge_level_input,
1382
- interests_input,
1383
- study_time_input,
1384
- learning_style_input
1385
- ],
1386
- outputs=profile_output
1387
- )
1388
-
1389
- chat_submit_btn.click(
1390
- chatbot_interface,
1391
- inputs=[gr.State(session_id), chat_input],
1392
- outputs=chat_output
1393
- )
1394
-
1395
- chat_clear_btn.click(
1396
- lambda: "",
1397
- inputs=[],
1398
- outputs=[chat_output, chat_input]
1399
- )
1400
-
1401
- refresh_recommendations_btn.click(
1402
- generate_recommendations,
1403
- inputs=[gr.State(session_id)],
1404
- outputs=recommendations_output
1405
- )
1406
-
1407
- generate_quiz_btn.click(
1408
- handle_quiz_request,
1409
- inputs=[gr.State(session_id), quiz_topic_input, quiz_difficulty_input],
1410
- outputs=quiz_output
1411
- )
1412
-
1413
- generate_plan_btn.click(
1414
- handle_study_plan_request,
1415
- inputs=[gr.State(session_id), plan_topic_input, plan_time_input],
1416
- outputs=plan_output
1417
- )
1418
-
1419
  return demo
 
1420
  if __name__ == "__main__":
1421
  app = create_chatbot()
1422
- app.launch()
 
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;
1196
+ border-radius: 12px;
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;
1220
+ padding: 10px;
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);
1239
+ padding: 15px;
1240
+ margin: 15px 0;
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
  )
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
  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()