Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
# ============================================================================
|
| 2 |
-
# 📦 INCLUSIVEEDU -
|
| 3 |
# Compatible with Hugging Face Spaces + External API Access
|
| 4 |
# ============================================================================
|
| 5 |
|
|
@@ -660,13 +660,26 @@ def initialize_global_instances():
|
|
| 660 |
# ============================================================================
|
| 661 |
|
| 662 |
if FASTAPI_AVAILABLE:
|
| 663 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 664 |
api = FastAPI(
|
| 665 |
title="🧠 InclusiveEdu API",
|
| 666 |
description="API REST para adaptação de conteúdo educacional neurodiverso",
|
| 667 |
version="2.0.0",
|
| 668 |
docs_url="/docs",
|
| 669 |
-
redoc_url="/redoc"
|
|
|
|
| 670 |
)
|
| 671 |
|
| 672 |
# CORS middleware
|
|
@@ -678,13 +691,6 @@ if FASTAPI_AVAILABLE:
|
|
| 678 |
allow_headers=["*"],
|
| 679 |
)
|
| 680 |
|
| 681 |
-
@api.on_event("startup")
|
| 682 |
-
async def startup_event():
|
| 683 |
-
"""Initialize API on startup"""
|
| 684 |
-
print("🚀 Starting InclusiveEdu API...")
|
| 685 |
-
initialize_global_instances()
|
| 686 |
-
print("✅ API ready for requests!")
|
| 687 |
-
|
| 688 |
@api.get("/", response_model=dict)
|
| 689 |
async def root():
|
| 690 |
"""API root endpoint"""
|
|
@@ -1420,15 +1426,24 @@ def main():
|
|
| 1420 |
demo = create_gradio_interface()
|
| 1421 |
print("🎉 InclusiveEdu ready to launch!")
|
| 1422 |
|
| 1423 |
-
# Launch configuration
|
| 1424 |
launch_kwargs = {
|
| 1425 |
"server_name": "0.0.0.0",
|
| 1426 |
"server_port": 7860,
|
| 1427 |
"show_error": True,
|
| 1428 |
-
"show_tips": True,
|
| 1429 |
"enable_queue": True
|
| 1430 |
}
|
| 1431 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1432 |
if not is_spaces:
|
| 1433 |
launch_kwargs["share"] = False
|
| 1434 |
launch_kwargs["inbrowser"] = True
|
|
@@ -1492,12 +1507,18 @@ def main():
|
|
| 1492 |
print("🔌 API: http://localhost:8000")
|
| 1493 |
print("📚 API Docs: http://localhost:8000/docs")
|
| 1494 |
|
| 1495 |
-
|
| 1496 |
-
|
| 1497 |
-
|
| 1498 |
-
|
| 1499 |
-
|
| 1500 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1501 |
|
| 1502 |
if __name__ == "__main__":
|
| 1503 |
main()
|
|
|
|
| 1 |
# ============================================================================
|
| 2 |
+
# 📦 INCLUSIVEEDU - FULL VERSION WITH GRADIO + INTEGRATED API
|
| 3 |
# Compatible with Hugging Face Spaces + External API Access
|
| 4 |
# ============================================================================
|
| 5 |
|
|
|
|
| 660 |
# ============================================================================
|
| 661 |
|
| 662 |
if FASTAPI_AVAILABLE:
|
| 663 |
+
from contextlib import asynccontextmanager
|
| 664 |
+
|
| 665 |
+
@asynccontextmanager
|
| 666 |
+
async def lifespan(app: FastAPI):
|
| 667 |
+
# Startup
|
| 668 |
+
print("🚀 Starting InclusiveEdu API...")
|
| 669 |
+
initialize_global_instances()
|
| 670 |
+
print("✅ API ready for requests!")
|
| 671 |
+
yield
|
| 672 |
+
# Shutdown (if needed)
|
| 673 |
+
print("👋 InclusiveEdu API shutting down...")
|
| 674 |
+
|
| 675 |
+
# Create FastAPI instance with lifespan
|
| 676 |
api = FastAPI(
|
| 677 |
title="🧠 InclusiveEdu API",
|
| 678 |
description="API REST para adaptação de conteúdo educacional neurodiverso",
|
| 679 |
version="2.0.0",
|
| 680 |
docs_url="/docs",
|
| 681 |
+
redoc_url="/redoc",
|
| 682 |
+
lifespan=lifespan
|
| 683 |
)
|
| 684 |
|
| 685 |
# CORS middleware
|
|
|
|
| 691 |
allow_headers=["*"],
|
| 692 |
)
|
| 693 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 694 |
@api.get("/", response_model=dict)
|
| 695 |
async def root():
|
| 696 |
"""API root endpoint"""
|
|
|
|
| 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
|
|
|
|
| 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()
|