rahul7star commited on
Commit
a7d17c9
·
verified ·
1 Parent(s): 2b24924

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py CHANGED
@@ -38,6 +38,22 @@ import json
38
  import yaml
39
  from slugify import slugify
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  sys.path.insert(0, "ai-toolkit")
42
  from toolkit.job import get_job
43
 
@@ -77,6 +93,24 @@ app.add_middleware(
77
  def health_check():
78
  return {"status": "✅ FastAPI running on Hugging Face Spaces!"}
79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  REPO_ID = "rahul7star/ohamlab"
81
  FOLDER = "demo"
82
  BASE_URL = f"https://huggingface.co/{REPO_ID}/resolve/main/"
 
38
  import yaml
39
  from slugify import slugify
40
 
41
+ from collections import deque
42
+
43
+ log_buffer = deque(maxlen=1000)
44
+
45
+ class InMemoryLogHandler(logging.Handler):
46
+ def emit(self, record):
47
+ msg = self.format(record)
48
+ log_buffer.append(msg)
49
+
50
+ # Setup logging to buffer
51
+ handler = InMemoryLogHandler()
52
+ handler.setFormatter(logging.Formatter("%(asctime)s | %(levelname)s | %(message)s"))
53
+ logging.getLogger().addHandler(handler)
54
+
55
+
56
+
57
  sys.path.insert(0, "ai-toolkit")
58
  from toolkit.job import get_job
59
 
 
93
  def health_check():
94
  return {"status": "✅ FastAPI running on Hugging Face Spaces!"}
95
 
96
+
97
+
98
+
99
+
100
+ @app.get("/jobs")
101
+ def all_jobs():
102
+ return list(JOB_QUEUE.values())
103
+
104
+
105
+ @app.get("/logs")
106
+ def get_logs(limit: int = 50):
107
+ return list(log_buffer)[-limit:]
108
+
109
+ @app.get("/jobs/running")
110
+ def running_jobs():
111
+ return [job for job in JOB_QUEUE.values() if job.status in ("pending", "running")]
112
+
113
+
114
  REPO_ID = "rahul7star/ohamlab"
115
  FOLDER = "demo"
116
  BASE_URL = f"https://huggingface.co/{REPO_ID}/resolve/main/"