lyi029 commited on
Commit
20ce931
·
1 Parent(s): 7eb06fd

performance

Browse files
Files changed (1) hide show
  1. app.py +19 -0
app.py CHANGED
@@ -564,6 +564,24 @@ async def predict_malware(files: List[UploadFile] = File(...), original_filename
564
  PERF_STATS["predict_last_ms"] = elapsed * 1000.0
565
  PERF_STATS["predict_last_files"] = len(files)
566
  PERF_STATS["last_updated"] = datetime.datetime.utcnow().isoformat()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
567
 
568
  return result
569
 
@@ -1008,3 +1026,4 @@ if __name__ == "__main__":
1008
  import uvicorn
1009
  port = int(os.getenv("PORT", 7860))
1010
  uvicorn.run(app, host="0.0.0.0", port=port)
 
 
564
  PERF_STATS["predict_last_ms"] = elapsed * 1000.0
565
  PERF_STATS["predict_last_files"] = len(files)
566
  PERF_STATS["last_updated"] = datetime.datetime.utcnow().isoformat()
567
+ if len(files) > 0:
568
+ files_per_sec = len(files) / elapsed
569
+ else:
570
+ files_per_sec = 0.0
571
+
572
+ print("\n===== 🔬 Inference Performance (this request) =====")
573
+ print(f" Files processed : {len(files)}")
574
+ print(f" Elapsed time : {elapsed:.3f} s")
575
+ print(f" Avg per file : {elapsed/len(files):.3f} s/file" if len(files) > 0 else " Avg per file : N/A")
576
+ print(f" Throughput : {files_per_sec:.2f} files/s")
577
+ print(" Global stats :")
578
+ print(f" Total calls : {PERF_STATS['predict_calls']}")
579
+ print(f" Total seconds : {PERF_STATS['predict_total_seconds']:.3f} s")
580
+ if PERF_STATS["predict_calls"] > 0:
581
+ avg = PERF_STATS["predict_total_seconds"] / PERF_STATS["predict_calls"]
582
+ print(f" Avg per call : {avg:.3f} s/call")
583
+ print("===================================================\n")
584
+
585
 
586
  return result
587
 
 
1026
  import uvicorn
1027
  port = int(os.getenv("PORT", 7860))
1028
  uvicorn.run(app, host="0.0.0.0", port=port)
1029
+