Kshitijk20 commited on
Commit
eff1d8c
Β·
1 Parent(s): 7f4cb77

refactor training route to streamline Prefect Cloud integration and add command-line trigger for training flow

Browse files
Files changed (2) hide show
  1. app.py +8 -23
  2. trigger_prefect_training.py +14 -0
app.py CHANGED
@@ -75,31 +75,16 @@ async def training_route():
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
-
85
- # Import and run flow directly (will auto-sync to Prefect Cloud)
86
- from prefect_flows.training_flow import training_flow
87
-
88
- # Run the flow - it will automatically log to Prefect Cloud
89
- flow_state = training_flow()
90
- logging.info(f"Training flow completed with state: {flow_state}")
91
-
92
- return Response(f"βœ… Training completed via Prefect Cloud!\n\nCheck dashboard: https://app.prefect.cloud/\n\nFlow State: {flow_state}")
93
- except Exception as prefect_error:
94
- logging.error(f"Prefect training failed: {str(prefect_error)}", exc_info=True)
95
- # Don't fallback - show the error
96
- raise NetworkSecurityException(prefect_error, sys)
97
-
98
- # Direct training if Prefect not enabled
99
- logging.info("Running direct training (Prefect not enabled)")
100
  training_pipeline = Trainingpipeline()
101
  training_pipeline.run_pipeline()
102
- return Response("Training completed successfully (direct mode)")
 
 
 
 
 
 
103
  return Response("Training completed successfully (direct mode)")
104
  except Exception as e:
105
  raise NetworkSecurityException(e, sys)
 
75
  try:
76
  logging.info("Starting training pipeline...")
77
 
78
+ # Run training directly - Prefect Cloud monitoring happens in prefect_flows if needed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  training_pipeline = Trainingpipeline()
80
  training_pipeline.run_pipeline()
81
+
82
+ status_msg = "βœ… Training completed successfully!"
83
+ if ENABLE_PREFECT:
84
+ status_msg += "\n\nπŸ“Š Prefect Cloud connected - Run flows via prefect_flows/ directory"
85
+ status_msg += "\n Dashboard: https://app.prefect.cloud/"
86
+
87
+ return Response(status_msg)
88
  return Response("Training completed successfully (direct mode)")
89
  except Exception as e:
90
  raise NetworkSecurityException(e, sys)
trigger_prefect_training.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Trigger Prefect training flow manually
3
+ Use this to run training through Prefect Cloud from command line
4
+ """
5
+ import sys
6
+ sys.path.append('.')
7
+
8
+ from prefect_flows.training_flow import training_flow
9
+
10
+ if __name__ == "__main__":
11
+ print("πŸš€ Starting training via Prefect Cloud...")
12
+ result = training_flow()
13
+ print(f"βœ… Training completed: {result}")
14
+ print("πŸ“Š Check Prefect Cloud dashboard: https://app.prefect.cloud/")