Tbruand
commited on
Commit
·
4d029c2
1
Parent(s):
e4f3f0e
refactor(handler): charge paresseusement le modèle fine-tuné pour éviter les erreurs à l’import
Browse files- app/handler.py +6 -4
app/handler.py
CHANGED
@@ -1,17 +1,19 @@
|
|
1 |
from models.zero_shot import ZeroShotModel
|
2 |
from models.few_shot import FewShotModel
|
3 |
-
from models.fine_tuned import FineTunedModel
|
4 |
|
5 |
zero_shot_model = ZeroShotModel()
|
6 |
few_shot_model = FewShotModel()
|
7 |
-
|
|
|
|
|
|
|
8 |
|
9 |
def predict(text: str, model_type: str = "zero-shot") -> str:
|
10 |
if model_type == "few-shot":
|
11 |
results = few_shot_model.predict(text)
|
12 |
title = "Few-Shot"
|
13 |
elif model_type == "fine-tuned":
|
14 |
-
results =
|
15 |
title = "Fine-Tuned"
|
16 |
else:
|
17 |
results = zero_shot_model.predict(text)
|
@@ -19,5 +21,5 @@ def predict(text: str, model_type: str = "zero-shot") -> str:
|
|
19 |
|
20 |
output = f"### Résultat de la classification ({title}) :\n\n"
|
21 |
for label, score in results:
|
22 |
-
output += f"- **{label}** : {score*100:.1f}%\n"
|
23 |
return output
|
|
|
1 |
from models.zero_shot import ZeroShotModel
|
2 |
from models.few_shot import FewShotModel
|
|
|
3 |
|
4 |
zero_shot_model = ZeroShotModel()
|
5 |
few_shot_model = FewShotModel()
|
6 |
+
|
7 |
+
def get_fine_tuned_model():
|
8 |
+
from models.fine_tuned import FineTunedModel
|
9 |
+
return FineTunedModel()
|
10 |
|
11 |
def predict(text: str, model_type: str = "zero-shot") -> str:
|
12 |
if model_type == "few-shot":
|
13 |
results = few_shot_model.predict(text)
|
14 |
title = "Few-Shot"
|
15 |
elif model_type == "fine-tuned":
|
16 |
+
results = get_fine_tuned_model().predict(text)
|
17 |
title = "Fine-Tuned"
|
18 |
else:
|
19 |
results = zero_shot_model.predict(text)
|
|
|
21 |
|
22 |
output = f"### Résultat de la classification ({title}) :\n\n"
|
23 |
for label, score in results:
|
24 |
+
output += f"- **{label}** : {score * 100:.1f}%\n"
|
25 |
return output
|