Update api.py
Browse files
api.py
CHANGED
@@ -28,16 +28,13 @@ except ImportError as e:
|
|
28 |
import google.generativeai as genai
|
29 |
|
30 |
try:
|
31 |
-
from scoring.specificity import load_model
|
32 |
except ImportError as e:
|
33 |
print(f"Error importing scoring component: {e}")
|
34 |
print("Please ensure scoring is in your Python path or installed.")
|
35 |
# You might want to exit or raise a clearer error if imports fail
|
36 |
raise
|
37 |
|
38 |
-
status = load_model()
|
39 |
-
print(status)
|
40 |
-
|
41 |
# Configure logging for the API
|
42 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
43 |
logger = logging.getLogger(__name__)
|
@@ -146,6 +143,21 @@ async def lifespan(app: FastAPI):
|
|
146 |
logger.error(f"Failed to configure Gemini client: {e}", exc_info=True)
|
147 |
else:
|
148 |
logger.warning("Gemini library not imported. Endpoints requiring Gemini will not work.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
|
150 |
yield # API runs here
|
151 |
|
|
|
28 |
import google.generativeai as genai
|
29 |
|
30 |
try:
|
31 |
+
from scoring.specificity import load_model as load_specificity_model
|
32 |
except ImportError as e:
|
33 |
print(f"Error importing scoring component: {e}")
|
34 |
print("Please ensure scoring is in your Python path or installed.")
|
35 |
# You might want to exit or raise a clearer error if imports fail
|
36 |
raise
|
37 |
|
|
|
|
|
|
|
38 |
# Configure logging for the API
|
39 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
40 |
logger = logging.getLogger(__name__)
|
|
|
143 |
logger.error(f"Failed to configure Gemini client: {e}", exc_info=True)
|
144 |
else:
|
145 |
logger.warning("Gemini library not imported. Endpoints requiring Gemini will not work.")
|
146 |
+
|
147 |
+
# Initialize fine-tuned model for specificity evaluation
|
148 |
+
logger.info("Loading specificity model...")
|
149 |
+
try:
|
150 |
+
from scoring.specificity import load_model as load_specificity_model # Alias pour éviter confusion
|
151 |
+
model_status = load_specificity_model()
|
152 |
+
if model_status:
|
153 |
+
logger.info("Specificity model loaded successfully.")
|
154 |
+
else:
|
155 |
+
logger.error("Failed to load specificity model during startup.")
|
156 |
+
# Décidez si l'application doit échouer au démarrage
|
157 |
+
# raise RuntimeError("Failed to load specificity model.")
|
158 |
+
except Exception as e:
|
159 |
+
logger.error(f"Error loading specificity model during startup: {e}", exc_info=True)
|
160 |
+
# raise RuntimeError("Failed to load specificity model.") from e
|
161 |
|
162 |
yield # API runs here
|
163 |
|