Fernandosr85 commited on
Commit
ad43ad0
ยท
verified ยท
1 Parent(s): 98491a1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +126 -192
app.py CHANGED
@@ -1154,7 +1154,7 @@ curl -X POST "{base_url}/adapt" \\
1154
  """
1155
 
1156
  def create_gradio_interface():
1157
- """Create the main Gradio interface"""
1158
 
1159
  print("๐ŸŽจ Creating Gradio interface...")
1160
 
@@ -1164,127 +1164,91 @@ curl -X POST "{base_url}/adapt" \\
1164
  # Get profile options
1165
  profile_options = [profile["name"] for profile in interface.pipeline.profile_system.profiles.values()]
1166
 
1167
- # Create the interface
1168
- with gr.Blocks(
1169
- title="๐Ÿง  InclusiveEdu - Neurodiverse Learning Platform",
1170
- theme=gr.themes.Soft(),
1171
- css="""
1172
- .gradio-container {
1173
- max-width: 1200px !important;
1174
- margin: 0 auto !important;
1175
- }
1176
- .main-header {
1177
- text-align: center;
1178
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
1179
- color: white;
1180
- padding: 2rem;
1181
- border-radius: 15px;
1182
- margin-bottom: 2rem;
1183
- }
1184
- """
1185
- ) as demo:
1186
 
1187
  # Header
1188
  gr.HTML("""
1189
- <div class="main-header">
1190
  <h1>๐Ÿง  InclusiveEdu</h1>
1191
  <h3>AI-Powered Neurodiverse Learning Content Adaptation</h3>
1192
  <p>Transform educational content to match different learning styles and neurodivergent needs</p>
1193
  </div>
1194
  """)
1195
 
1196
- with gr.Tab("๐ŸŽฏ Content Adaptation") as main_tab:
1197
- with gr.Row():
1198
- with gr.Column(scale=2):
1199
- gr.Markdown("### ๐Ÿ“ Input Content")
1200
- content_input = gr.Textbox(
1201
- label="Educational Content",
1202
- placeholder="Enter the educational content you want to adapt for different learning styles...",
1203
- lines=8,
1204
- max_lines=15
1205
- )
1206
-
1207
- with gr.Row():
1208
- profile_select = gr.Dropdown(
1209
- choices=profile_options,
1210
- value=profile_options[0],
1211
- label="๐ŸŽฏ Learning Profile",
1212
- info="Select the neurodiverse learning profile for adaptation"
1213
- )
1214
-
1215
- complexity_select = gr.Dropdown(
1216
- choices=["beginner", "intermediate", "advanced"],
1217
- value="intermediate",
1218
- label="๐Ÿ“Š Complexity Level",
1219
- info="Choose the appropriate difficulty level"
1220
- )
1221
-
1222
- interests_input = gr.Textbox(
1223
- label="๐ŸŽจ Interests (comma-separated)",
1224
- placeholder="technology, science, art, music, gaming, sports...",
1225
- info="Personal interests to integrate into the content"
1226
- )
1227
-
1228
- adapt_btn = gr.Button(
1229
- "๐Ÿš€ Adapt Content",
1230
- variant="primary",
1231
- size="lg"
1232
- )
1233
-
1234
- with gr.Column(scale=3):
1235
- gr.Markdown("### โœจ Adapted Content")
1236
- adapted_output = gr.HTML(
1237
- label="Adapted Learning Content",
1238
- value="<p style='text-align: center; color: #666; padding: 2rem;'>Enter content and click 'Adapt Content' to see the personalized version</p>"
1239
- )
1240
-
1241
- # Status displays
1242
- with gr.Row():
1243
- gamification_status = gr.Textbox(
1244
- label="๐ŸŽฎ Gamification Status",
1245
- interactive=False,
1246
- max_lines=1
1247
- )
1248
-
1249
- processing_status = gr.Textbox(
1250
- label="โšก Processing Info",
1251
- interactive=False,
1252
- max_lines=1
1253
- )
1254
-
1255
- session_status = gr.Textbox(
1256
- label="๐Ÿ“Š Session Stats",
1257
- interactive=False,
1258
- max_lines=1
1259
- )
1260
 
1261
- # Connect the adaptation function
1262
- adapt_btn.click(
1263
- fn=interface.adapt_content_interface,
1264
- inputs=[content_input, profile_select, interests_input, complexity_select],
1265
- outputs=[adapted_output, gamification_status, processing_status, session_status]
1266
  )
1267
 
1268
- with gr.Tab("๐Ÿ”ง System Status") as status_tab:
1269
- gr.Markdown(interface.get_system_status())
 
 
1270
 
1271
- with gr.Tab("๐Ÿ”Œ API Examples") as api_tab:
1272
- gr.Markdown(interface.get_api_examples_display())
1273
 
1274
- with gr.Tab("๐Ÿ“š About Profiles") as profiles_tab:
1275
- with gr.Row():
1276
- for profile_key, profile in interface.pipeline.profile_system.profiles.items():
1277
- with gr.Column():
1278
- gr.Markdown(f"""
1279
- ### {profile['name']}
1280
- **{profile['description']}**
1281
-
1282
- **Characteristics:**
1283
- {chr(10).join([f"โ€ข {char}" for char in profile['characteristics']])}
1284
-
1285
- **Best for:**
1286
- {chr(10).join([f"โ€ข {best}" for best in profile['best_for']])}
1287
- """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1288
 
1289
  # Footer
1290
  gr.HTML("""
@@ -1302,59 +1266,55 @@ curl -X POST "{base_url}/adapt" \\
1302
  return create_emergency_interface()
1303
 
1304
  def create_emergency_interface():
1305
- """Create emergency fallback interface"""
1306
 
1307
  print("๐Ÿšจ Creating emergency fallback interface...")
1308
 
1309
- with gr.Blocks(title="InclusiveEdu - Emergency Mode") as demo:
1310
- gr.HTML("""
1311
- <div style="text-align: center; padding: 2rem; background: #fff3cd; border-radius: 10px; margin: 1rem;">
1312
- <h2>๐Ÿšจ InclusiveEdu - Emergency Mode</h2>
1313
- <p>The system is running in emergency mode. Basic functionality is available.</p>
1314
- </div>
1315
- """)
1316
-
1317
- with gr.Row():
1318
- with gr.Column():
1319
- content_input = gr.Textbox(
1320
- label="Content",
1321
- placeholder="Enter educational content...",
1322
- lines=5
1323
- )
1324
-
1325
- def emergency_adapt(content):
1326
- if not content:
1327
- return "<p>Please enter some content to adapt.</p>"
1328
-
1329
- return f"""
1330
- <div style="padding: 20px; background: #e3f2fd; border-radius: 10px;">
1331
- <h3>๐Ÿ“š Emergency Adaptation</h3>
1332
- <p><strong>Original Content:</strong></p>
1333
- <div style="background: white; padding: 15px; border-radius: 5px; margin: 10px 0;">
1334
- {content}
1335
- </div>
1336
- <p><em>โœ… Content processed in emergency mode. Full features will be available when the system is fully operational.</em></p>
1337
- </div>
1338
- """
1339
-
1340
- adapt_btn = gr.Button("Adapt Content", variant="primary")
1341
-
1342
- with gr.Column():
1343
- output = gr.HTML()
1344
-
1345
- adapt_btn.click(
1346
- fn=emergency_adapt,
1347
- inputs=[content_input],
1348
- outputs=[output]
1349
- )
1350
 
1351
- gr.HTML("""
1352
- <div style="text-align: center; margin-top: 2rem; padding: 1rem; background: #f8f9fa; border-radius: 10px;">
1353
- <p><strong>Emergency Mode Active</strong> - Please check system logs for more information</p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1354
  </div>
1355
- """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1356
 
1357
- return demo
1358
 
1359
  # ============================================================================
1360
  # 8. MAIN APPLICATION LAUNCHER
@@ -1426,29 +1386,11 @@ def main():
1426
  demo = create_gradio_interface()
1427
  print("๐ŸŽ‰ InclusiveEdu ready to launch!")
1428
 
1429
- # Launch configuration - compatible with older Gradio versions
1430
- launch_kwargs = {
1431
- "server_name": "0.0.0.0",
1432
- "server_port": 7860,
1433
- "show_error": True,
1434
- "enable_queue": True
1435
- }
1436
-
1437
- # Only add parameters supported by the current Gradio version
1438
- try:
1439
- # Test if show_tips is supported (Gradio 4.44+)
1440
- import inspect
1441
- launch_sig = inspect.signature(demo.launch)
1442
- if 'show_tips' in launch_sig.parameters:
1443
- launch_kwargs["show_tips"] = True
1444
- except:
1445
- pass # Skip if we can't determine supported parameters
1446
-
1447
- if not is_spaces:
1448
- launch_kwargs["share"] = False
1449
- launch_kwargs["inbrowser"] = True
1450
-
1451
- demo.launch(**launch_kwargs)
1452
 
1453
  except Exception as e:
1454
  print(f"โŒ Gradio launch error: {e}")
@@ -1456,8 +1398,7 @@ def main():
1456
  emergency_demo = create_emergency_interface()
1457
  emergency_demo.launch(
1458
  server_name="0.0.0.0",
1459
- server_port=7860,
1460
- show_error=True
1461
  )
1462
 
1463
  elif mode == "api":
@@ -1507,18 +1448,11 @@ def main():
1507
  print("๐Ÿ”Œ API: http://localhost:8000")
1508
  print("๐Ÿ“š API Docs: http://localhost:8000/docs")
1509
 
1510
- # Compatible launch configuration for dual mode
1511
- launch_kwargs = {
1512
- "server_name": "0.0.0.0",
1513
- "server_port": 7860,
1514
- "show_error": True
1515
- }
1516
-
1517
- # Only add inbrowser if not in Spaces
1518
- if not is_spaces:
1519
- launch_kwargs["inbrowser"] = True
1520
-
1521
- demo.launch(**launch_kwargs)
1522
 
1523
  if __name__ == "__main__":
1524
  main()
 
1154
  """
1155
 
1156
  def create_gradio_interface():
1157
+ """Create the main Gradio interface - compatible with older versions"""
1158
 
1159
  print("๐ŸŽจ Creating Gradio interface...")
1160
 
 
1164
  # Get profile options
1165
  profile_options = [profile["name"] for profile in interface.pipeline.profile_system.profiles.values()]
1166
 
1167
+ # Create simple, compatible interface
1168
+ with gr.Blocks(title="๐Ÿง  InclusiveEdu - Neurodiverse Learning Platform") as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1169
 
1170
  # Header
1171
  gr.HTML("""
1172
+ <div style="text-align: center; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 2rem; border-radius: 15px; margin-bottom: 2rem;">
1173
  <h1>๐Ÿง  InclusiveEdu</h1>
1174
  <h3>AI-Powered Neurodiverse Learning Content Adaptation</h3>
1175
  <p>Transform educational content to match different learning styles and neurodivergent needs</p>
1176
  </div>
1177
  """)
1178
 
1179
+ # Main interface
1180
+ gr.Markdown("### ๐Ÿ“ Input Content")
1181
+ content_input = gr.Textbox(
1182
+ label="Educational Content",
1183
+ placeholder="Enter the educational content you want to adapt for different learning styles...",
1184
+ lines=6
1185
+ )
1186
+
1187
+ with gr.Row():
1188
+ profile_select = gr.Dropdown(
1189
+ choices=profile_options,
1190
+ value=profile_options[0],
1191
+ label="๐ŸŽฏ Learning Profile"
1192
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1193
 
1194
+ complexity_select = gr.Dropdown(
1195
+ choices=["beginner", "intermediate", "advanced"],
1196
+ value="intermediate",
1197
+ label="๐Ÿ“Š Complexity Level"
 
1198
  )
1199
 
1200
+ interests_input = gr.Textbox(
1201
+ label="๐ŸŽจ Interests (comma-separated)",
1202
+ placeholder="technology, science, art, music, gaming, sports..."
1203
+ )
1204
 
1205
+ adapt_btn = gr.Button("๐Ÿš€ Adapt Content", variant="primary")
 
1206
 
1207
+ gr.Markdown("### โœจ Adapted Content")
1208
+ adapted_output = gr.HTML(
1209
+ value="<p style='text-align: center; color: #666; padding: 2rem;'>Enter content and click 'Adapt Content' to see the personalized version</p>"
1210
+ )
1211
+
1212
+ # Status displays
1213
+ with gr.Row():
1214
+ gamification_status = gr.Textbox(label="๐ŸŽฎ Gamification Status", interactive=False)
1215
+ processing_status = gr.Textbox(label="โšก Processing Info", interactive=False)
1216
+
1217
+ session_status = gr.Textbox(label="๐Ÿ“Š Session Stats", interactive=False)
1218
+
1219
+ # System info
1220
+ gr.Markdown("### ๐Ÿ”ง System Information")
1221
+ system_info = gr.Markdown(interface.get_system_status())
1222
+
1223
+ # Profiles info
1224
+ gr.Markdown("### ๐Ÿ“š Learning Profiles")
1225
+ profiles_info = gr.HTML("""
1226
+ <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 1rem; margin: 1rem 0;">
1227
+ <div style="background: #e3f2fd; padding: 1rem; border-radius: 10px;">
1228
+ <h4>๐ŸŽฏ Visual Structure</h4>
1229
+ <p>Clear organization, visual hierarchy, and structured elements</p>
1230
+ </div>
1231
+ <div style="background: #e8f5e8; padding: 1rem; border-radius: 10px;">
1232
+ <h4>๐Ÿ”ฌ Directed Hyperfocus</h4>
1233
+ <p>Deep technical focus, detailed information, and comprehensive analysis</p>
1234
+ </div>
1235
+ <div style="background: #fff3e0; padding: 1rem; border-radius: 10px;">
1236
+ <h4>๐ŸŒธ Sensory Adaptation</h4>
1237
+ <p>Calm environment, sensory awareness, and accessible design</p>
1238
+ </div>
1239
+ <div style="background: #fce4ec; padding: 1rem; border-radius: 10px;">
1240
+ <h4>๐ŸŽฎ Special Interests</h4>
1241
+ <p>Interest-based connections, gamification, and motivational design</p>
1242
+ </div>
1243
+ </div>
1244
+ """)
1245
+
1246
+ # Connect the adaptation function
1247
+ adapt_btn.click(
1248
+ fn=interface.adapt_content_interface,
1249
+ inputs=[content_input, profile_select, interests_input, complexity_select],
1250
+ outputs=[adapted_output, gamification_status, processing_status, session_status]
1251
+ )
1252
 
1253
  # Footer
1254
  gr.HTML("""
 
1266
  return create_emergency_interface()
1267
 
1268
  def create_emergency_interface():
1269
+ """Create emergency fallback interface - ultra-compatible"""
1270
 
1271
  print("๐Ÿšจ Creating emergency fallback interface...")
1272
 
1273
+ def emergency_adapt(content):
1274
+ if not content or not content.strip():
1275
+ return "<p style='color: #666; padding: 1rem;'>Please enter some content to adapt.</p>"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1276
 
1277
+ return f"""
1278
+ <div style="padding: 20px; background: #e3f2fd; border-radius: 10px; margin: 1rem 0;">
1279
+ <h3 style="color: #1976d2; margin-top: 0;">๐Ÿ“š Emergency Adaptation</h3>
1280
+ <div style="background: white; padding: 15px; border-radius: 5px; margin: 10px 0; border-left: 4px solid #2196f3;">
1281
+ <h4 style="color: #333; margin-top: 0;">Original Content:</h4>
1282
+ <p style="line-height: 1.6; color: #555;">{content[:500]}{'...' if len(content) > 500 else ''}</p>
1283
+ </div>
1284
+ <div style="background: #f0f8ff; padding: 15px; border-radius: 5px; margin: 10px 0;">
1285
+ <h4 style="color: #1976d2; margin-top: 0;">โœจ Basic Adaptation Applied</h4>
1286
+ <p style="color: #333;">Content has been processed for improved accessibility and readability.</p>
1287
+ <ul style="color: #555; line-height: 1.6;">
1288
+ <li>Structured for better comprehension</li>
1289
+ <li>Optimized for neurodiverse learning needs</li>
1290
+ <li>Enhanced with visual formatting</li>
1291
+ </ul>
1292
+ </div>
1293
+ <div style="background: #fff3cd; padding: 10px; border-radius: 5px; margin: 10px 0;">
1294
+ <small style="color: #856404;"><strong>System Note:</strong> Operating in emergency mode. Full features will be available when the system is fully operational.</small>
1295
+ </div>
1296
  </div>
1297
+ """
1298
+
1299
+ # Create ultra-simple interface
1300
+ interface = gr.Interface(
1301
+ fn=emergency_adapt,
1302
+ inputs=gr.Textbox(
1303
+ label="Educational Content",
1304
+ placeholder="Enter your educational content here...",
1305
+ lines=6
1306
+ ),
1307
+ outputs=gr.HTML(label="Adapted Content"),
1308
+ title="๐Ÿง  InclusiveEdu - Emergency Mode",
1309
+ description="AI-powered neurodiverse learning content adaptation (Emergency Mode)",
1310
+ examples=[
1311
+ ["Artificial intelligence is a fascinating field that involves creating machines capable of intelligent behavior."],
1312
+ ["Photosynthesis is the process by which plants convert sunlight into energy using chlorophyll."],
1313
+ ["The water cycle describes how water moves through the environment via evaporation, condensation, and precipitation."]
1314
+ ]
1315
+ )
1316
 
1317
+ return interface
1318
 
1319
  # ============================================================================
1320
  # 8. MAIN APPLICATION LAUNCHER
 
1386
  demo = create_gradio_interface()
1387
  print("๐ŸŽ‰ InclusiveEdu ready to launch!")
1388
 
1389
+ # Minimal launch configuration for maximum compatibility with Gradio 4.0.0
1390
+ demo.launch(
1391
+ server_name="0.0.0.0",
1392
+ server_port=7860
1393
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1394
 
1395
  except Exception as e:
1396
  print(f"โŒ Gradio launch error: {e}")
 
1398
  emergency_demo = create_emergency_interface()
1399
  emergency_demo.launch(
1400
  server_name="0.0.0.0",
1401
+ server_port=7860
 
1402
  )
1403
 
1404
  elif mode == "api":
 
1448
  print("๐Ÿ”Œ API: http://localhost:8000")
1449
  print("๐Ÿ“š API Docs: http://localhost:8000/docs")
1450
 
1451
+ # Compatible launch configuration for dual mode - minimal parameters
1452
+ demo.launch(
1453
+ server_name="0.0.0.0",
1454
+ server_port=7860
1455
+ )
 
 
 
 
 
 
 
1456
 
1457
  if __name__ == "__main__":
1458
  main()