Spaces:
Sleeping
Sleeping
Commit ·
80743f2
1
Parent(s): dbe2dd0
enhanced training route to always use Prefect Cloud if connected, improved error handling, and updated response messages
Browse files
app.py
CHANGED
|
@@ -75,20 +75,29 @@ async def training_route():
|
|
| 75 |
try:
|
| 76 |
logging.info("Starting training pipeline...")
|
| 77 |
|
| 78 |
-
#
|
| 79 |
if ENABLE_PREFECT:
|
| 80 |
try:
|
| 81 |
logging.info("Triggering training via Prefect Cloud...")
|
|
|
|
|
|
|
| 82 |
from prefect_flows.training_flow import training_flow
|
|
|
|
|
|
|
| 83 |
result = training_flow()
|
| 84 |
-
|
|
|
|
|
|
|
| 85 |
except Exception as prefect_error:
|
| 86 |
-
logging.
|
|
|
|
| 87 |
|
| 88 |
-
# Fallback: Direct training
|
|
|
|
| 89 |
training_pipeline = Trainingpipeline()
|
| 90 |
training_pipeline.run_pipeline()
|
| 91 |
return Response("Training completed successfully (direct mode)")
|
|
|
|
| 92 |
except Exception as e:
|
| 93 |
raise NetworkSecurityException(e, sys)
|
| 94 |
|
|
|
|
| 75 |
try:
|
| 76 |
logging.info("Starting training pipeline...")
|
| 77 |
|
| 78 |
+
# Always use Prefect Cloud if connected
|
| 79 |
if ENABLE_PREFECT:
|
| 80 |
try:
|
| 81 |
logging.info("Triggering training via Prefect Cloud...")
|
| 82 |
+
import sys
|
| 83 |
+
sys.path.append('/app')
|
| 84 |
from prefect_flows.training_flow import training_flow
|
| 85 |
+
|
| 86 |
+
# Run the flow synchronously
|
| 87 |
result = training_flow()
|
| 88 |
+
logging.info(f"Training flow completed: {result}")
|
| 89 |
+
|
| 90 |
+
return Response(f"✅ Training completed via Prefect Cloud!\n\nCheck dashboard: https://app.prefect.cloud/account/{os.getenv('PREFECT_WORKSPACE', 'kshitij/default')}/flow-runs")
|
| 91 |
except Exception as prefect_error:
|
| 92 |
+
logging.error(f"Prefect training failed: {str(prefect_error)}", exc_info=True)
|
| 93 |
+
return Response(f"❌ Prefect training failed: {str(prefect_error)}\n\nFalling back to direct training...")
|
| 94 |
|
| 95 |
+
# Fallback: Direct training (only if Prefect not enabled)
|
| 96 |
+
logging.info("Running direct training (Prefect not enabled)")
|
| 97 |
training_pipeline = Trainingpipeline()
|
| 98 |
training_pipeline.run_pipeline()
|
| 99 |
return Response("Training completed successfully (direct mode)")
|
| 100 |
+
return Response("Training completed successfully (direct mode)")
|
| 101 |
except Exception as e:
|
| 102 |
raise NetworkSecurityException(e, sys)
|
| 103 |
|