Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,11 +4,10 @@ from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
4 |
import json
|
5 |
import logging
|
6 |
import os
|
7 |
-
import asyncio
|
8 |
|
9 |
# Set up logging to both stdout and a file
|
10 |
logging.basicConfig(
|
11 |
-
level=logging.
|
12 |
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
13 |
handlers=[
|
14 |
logging.StreamHandler(), # Log to stdout
|
@@ -58,11 +57,17 @@ async def load_model_background():
|
|
58 |
# Startup event to initiate model loading in the background
|
59 |
@app.on_event("startup")
|
60 |
async def startup_event(background_tasks: BackgroundTasks):
|
61 |
-
logger.
|
62 |
background_tasks.add_task(load_model_background)
|
63 |
|
|
|
|
|
|
|
|
|
|
|
64 |
@app.get("/health")
|
65 |
async def health_check():
|
|
|
66 |
return {
|
67 |
"status": "healthy" if model_load_status in ["local_model_loaded", "fallback_model_loaded"] else "starting",
|
68 |
"model_load_status": model_load_status
|
@@ -70,9 +75,16 @@ async def health_check():
|
|
70 |
|
71 |
@app.post("/generate_coaching")
|
72 |
async def generate_coaching(data: CoachingInput):
|
|
|
73 |
if model is None or tokenizer is None:
|
74 |
-
logger.
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
try:
|
78 |
# Prepare input text
|
|
|
4 |
import json
|
5 |
import logging
|
6 |
import os
|
|
|
7 |
|
8 |
# Set up logging to both stdout and a file
|
9 |
logging.basicConfig(
|
10 |
+
level=logging.DEBUG,
|
11 |
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
12 |
handlers=[
|
13 |
logging.StreamHandler(), # Log to stdout
|
|
|
57 |
# Startup event to initiate model loading in the background
|
58 |
@app.on_event("startup")
|
59 |
async def startup_event(background_tasks: BackgroundTasks):
|
60 |
+
logger.debug("FastAPI application started")
|
61 |
background_tasks.add_task(load_model_background)
|
62 |
|
63 |
+
@app.get("/")
|
64 |
+
async def root():
|
65 |
+
logger.debug("Root endpoint accessed")
|
66 |
+
return {"message": "Supervisor AI Coach is running"}
|
67 |
+
|
68 |
@app.get("/health")
|
69 |
async def health_check():
|
70 |
+
logger.debug("Health endpoint accessed")
|
71 |
return {
|
72 |
"status": "healthy" if model_load_status in ["local_model_loaded", "fallback_model_loaded"] else "starting",
|
73 |
"model_load_status": model_load_status
|
|
|
75 |
|
76 |
@app.post("/generate_coaching")
|
77 |
async def generate_coaching(data: CoachingInput):
|
78 |
+
logger.debug("Generate coaching endpoint accessed")
|
79 |
if model is None or tokenizer is None:
|
80 |
+
logger.warning("Model or tokenizer not loaded")
|
81 |
+
# Return a static response if the model isn't loaded yet
|
82 |
+
response_json = {
|
83 |
+
"checklist": ["Inspect safety equipment", "Review milestone progress"],
|
84 |
+
"tips": ["Prioritize team communication", "Check weather updates"],
|
85 |
+
"quote": "Every step forward counts!"
|
86 |
+
}
|
87 |
+
return response_json
|
88 |
|
89 |
try:
|
90 |
# Prepare input text
|