Fred808 commited on
Commit
ee61763
·
verified ·
1 Parent(s): cf5a888

Update download_api.py

Browse files
Files changed (1) hide show
  1. download_api.py +0 -171
download_api.py CHANGED
@@ -18,7 +18,6 @@ import torch
18
  from vision_analyzer import (
19
  main_processing_loop,
20
  processing_status,
21
- ANALYSIS_OUTPUT_FOLDER, # Changed from CURSOR_TRACKING_OUTPUT_FOLDER
22
  log_message,
23
  FRAMES_OUTPUT_FOLDER # Add this import for frames directory
24
  )
@@ -70,8 +69,6 @@ async def root():
70
  "status": "running",
71
  "endpoints": {
72
  "/status": "Get processing status",
73
- "/analysis-data": "List available analysis files",
74
- "/analysis-data/{filename}": "Get specific analysis data",
75
  "/courses": "List all available course folders",
76
  "/images/{course_folder}": "List images in a course folder",
77
  "/images/{course_folder}/{frame_filename}": "Get specific frame image",
@@ -85,9 +82,7 @@ async def get_status():
85
  """Get current processing status"""
86
  return {
87
  "processing_status": processing_status,
88
- "analysis_folder": ANALYSIS_OUTPUT_FOLDER,
89
  "frames_folder": FRAMES_OUTPUT_FOLDER,
90
- "analysis_folder_exists": os.path.exists(ANALYSIS_OUTPUT_FOLDER),
91
  "frames_folder_exists": os.path.exists(FRAMES_OUTPUT_FOLDER)
92
  }
93
 
@@ -175,171 +170,6 @@ async def list_all_courses():
175
  "courses": courses
176
  }
177
 
178
- # ===== EXISTING ANALYSIS ENDPOINTS =====
179
-
180
- @app.get("/analysis-data")
181
- async def list_analysis_data():
182
- """List all available analysis JSON files"""
183
- if not os.path.exists(ANALYSIS_OUTPUT_FOLDER):
184
- return {"files": [], "message": "Analysis output folder does not exist yet"}
185
-
186
- json_files = []
187
- for file in os.listdir(ANALYSIS_OUTPUT_FOLDER):
188
- if file.endswith(".json"):
189
- file_path = os.path.join(ANALYSIS_OUTPUT_FOLDER, file)
190
- file_stats = os.stat(file_path)
191
- json_files.append({
192
- "filename": file,
193
- "size_bytes": file_stats.st_size,
194
- "modified_time": time.ctime(file_stats.st_mtime),
195
- "download_url": f"/analysis-data/{file}"
196
- })
197
-
198
- return {
199
- "files": json_files,
200
- "total_files": len(json_files),
201
- "folder_path": ANALYSIS_OUTPUT_FOLDER
202
- }
203
-
204
- @app.get("/analysis-data/{filename}")
205
- async def get_analysis_data(filename: str):
206
- """Get specific analysis data by filename"""
207
- if not filename.endswith(".json"):
208
- raise HTTPException(status_code=400, detail="File must be a JSON file")
209
-
210
- file_path = os.path.join(ANALYSIS_OUTPUT_FOLDER, filename)
211
-
212
- if not os.path.exists(file_path):
213
- raise HTTPException(status_code=404, detail=f"File {filename} not found")
214
-
215
- try:
216
- with open(file_path, "r") as f:
217
- data = json.load(f)
218
-
219
- # Add metadata
220
- file_stats = os.stat(file_path)
221
-
222
- # Extract summary information
223
- frame_analyses = data.get("frame_analyses", [])
224
- summary = data.get("summary", {})
225
-
226
- response_data = {
227
- "filename": filename,
228
- "file_size_bytes": file_stats.st_size,
229
- "modified_time": time.ctime(file_stats.st_mtime),
230
- "total_frames": len(frame_analyses),
231
- "summary": summary,
232
- "frame_samples": frame_analyses[:5] # Return first 5 frames as samples
233
- }
234
-
235
- return response_data
236
-
237
- except json.JSONDecodeError:
238
- raise HTTPException(status_code=500, detail=f"Invalid JSON in file {filename}")
239
- except Exception as e:
240
- raise HTTPException(status_code=500, detail=f"Error reading file {filename}: {str(e)}")
241
-
242
- @app.get("/analysis-data/{filename}/full")
243
- async def get_full_analysis_data(filename: str):
244
- """Get the complete analysis data including all frames"""
245
- if not filename.endswith(".json"):
246
- raise HTTPException(status_code=400, detail="File must be a JSON file")
247
-
248
- file_path = os.path.join(ANALYSIS_OUTPUT_FOLDER, filename)
249
-
250
- if not os.path.exists(file_path):
251
- raise HTTPException(status_code=404, detail=f"File {filename} not found")
252
-
253
- try:
254
- with open(file_path, "r") as f:
255
- data = json.load(f)
256
-
257
- # Add metadata
258
- file_stats = os.stat(file_path)
259
- data["metadata"] = {
260
- "filename": filename,
261
- "file_size_bytes": file_stats.st_size,
262
- "modified_time": time.ctime(file_stats.st_mtime)
263
- }
264
-
265
- return data
266
-
267
- except json.JSONDecodeError:
268
- raise HTTPException(status_code=500, detail=f"Invalid JSON in file {filename}")
269
- except Exception as e:
270
- raise HTTPException(status_code=500, detail=f"Error reading file {filename}: {str(e)}")
271
-
272
- @app.post("/start-processing")
273
- async def start_processing(background_tasks: BackgroundTasks, start_index: int = 0):
274
- """Start the processing pipeline in the background"""
275
- global processing_thread
276
-
277
- if processing_thread and processing_thread.is_alive():
278
- return {"message": "Processing is already running", "status": "already_running"}
279
-
280
- if processing_status["is_running"]:
281
- return {"message": "Processing is already running", "status": "already_running"}
282
-
283
- # Start processing in a background thread
284
- processing_thread = threading.Thread(target=main_processing_loop, args=(start_index,))
285
- processing_thread.daemon = True
286
- processing_thread.start()
287
-
288
- return {"message": f"Processing started in background from index {start_index}", "status": "started"}
289
-
290
- @app.post("/stop-processing")
291
- async def stop_processing():
292
- """Stop the processing pipeline"""
293
- global processing_thread
294
-
295
- if not processing_status["is_running"] and (not processing_thread or not processing_thread.is_alive()):
296
- return {"message": "No processing is currently running", "status": "not_running"}
297
-
298
- # Note: This is a graceful stop request
299
- processing_status["is_running"] = False
300
-
301
- return {"message": "Stop signal sent to processing pipeline", "status": "stop_requested"}
302
-
303
- @app.get("/analysis-data/{filename}/summary")
304
- async def get_analysis_summary(filename: str):
305
- """Get a summary of the analysis data"""
306
- if not filename.endswith(".json"):
307
- raise HTTPException(status_code=400, detail="File must be a JSON file")
308
-
309
- file_path = os.path.join(ANALYSIS_OUTPUT_FOLDER, filename)
310
-
311
- if not os.path.exists(file_path):
312
- raise HTTPException(status_code=404, detail=f"File {filename} not found")
313
-
314
- try:
315
- with open(file_path, "r") as f:
316
- data = json.load(f)
317
-
318
- # Get basic statistics
319
- frame_analyses = data.get("frame_analyses", [])
320
- summary = data.get("summary", {})
321
-
322
- # Count frames with descriptions
323
- frames_with_descriptions = len([f for f in frame_analyses if f.get("description")])
324
-
325
- file_stats = os.stat(file_path)
326
-
327
- return {
328
- "filename": filename,
329
- "file_size_bytes": file_stats.st_size,
330
- "modified_time": time.ctime(file_stats.st_mtime),
331
- "total_frames": len(frame_analyses),
332
- "frames_with_descriptions": frames_with_descriptions,
333
- "summary": summary,
334
- "steps": summary.get("steps", []),
335
- "high_level_goal": summary.get("high_level_goal", ""),
336
- "final_goal": summary.get("final_goal", "")
337
- }
338
-
339
- except json.JSONDecodeError:
340
- raise HTTPException(status_code=500, detail=f"Invalid JSON in file {filename}")
341
- except Exception as e:
342
- raise HTTPException(status_code=500, detail=f"Error reading file {filename}: {str(e)}")
343
 
344
  if __name__ == "__main__":
345
  # Start the FastAPI server
@@ -348,7 +178,6 @@ if __name__ == "__main__":
348
  print("API Root endpoint: http://localhost:8000/")
349
 
350
  # Ensure the analysis output folder exists
351
- os.makedirs(ANALYSIS_OUTPUT_FOLDER, exist_ok=True)
352
  os.makedirs(FRAMES_OUTPUT_FOLDER, exist_ok=True)
353
 
354
  uvicorn.run(
 
18
  from vision_analyzer import (
19
  main_processing_loop,
20
  processing_status,
 
21
  log_message,
22
  FRAMES_OUTPUT_FOLDER # Add this import for frames directory
23
  )
 
69
  "status": "running",
70
  "endpoints": {
71
  "/status": "Get processing status",
 
 
72
  "/courses": "List all available course folders",
73
  "/images/{course_folder}": "List images in a course folder",
74
  "/images/{course_folder}/{frame_filename}": "Get specific frame image",
 
82
  """Get current processing status"""
83
  return {
84
  "processing_status": processing_status,
 
85
  "frames_folder": FRAMES_OUTPUT_FOLDER,
 
86
  "frames_folder_exists": os.path.exists(FRAMES_OUTPUT_FOLDER)
87
  }
88
 
 
170
  "courses": courses
171
  }
172
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
 
174
  if __name__ == "__main__":
175
  # Start the FastAPI server
 
178
  print("API Root endpoint: http://localhost:8000/")
179
 
180
  # Ensure the analysis output folder exists
 
181
  os.makedirs(FRAMES_OUTPUT_FOLDER, exist_ok=True)
182
 
183
  uvicorn.run(