Deploy model_router.py to backend/ directory
Browse files- backend/model_router.py +29 -4
backend/model_router.py
CHANGED
|
@@ -332,14 +332,29 @@ class ModelRouter:
|
|
| 332 |
|
| 333 |
# Format output based on task type
|
| 334 |
if "summarization" in model_key:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
return {
|
| 336 |
-
"summary":
|
| 337 |
"model": task['model_name'],
|
| 338 |
"confidence": 0.85
|
| 339 |
}
|
| 340 |
|
| 341 |
elif "ner" in model_key:
|
| 342 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 343 |
return {
|
| 344 |
"entities": self._format_ner_output(entities),
|
| 345 |
"model": task['model_name'],
|
|
@@ -347,9 +362,19 @@ class ModelRouter:
|
|
| 347 |
}
|
| 348 |
|
| 349 |
elif "qa" in model_key:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 350 |
return {
|
| 351 |
-
"answer":
|
| 352 |
-
"score":
|
| 353 |
"model": task['model_name']
|
| 354 |
}
|
| 355 |
|
|
|
|
| 332 |
|
| 333 |
# Format output based on task type
|
| 334 |
if "summarization" in model_key:
|
| 335 |
+
if isinstance(model_output, list) and model_output:
|
| 336 |
+
summary_text = model_output[0].get("summary_text", "") or model_output[0].get("generated_text", "")
|
| 337 |
+
if not summary_text:
|
| 338 |
+
summary_text = str(model_output[0])
|
| 339 |
+
elif isinstance(model_output, dict):
|
| 340 |
+
summary_text = model_output.get("summary_text", "") or model_output.get("generated_text", "")
|
| 341 |
+
else:
|
| 342 |
+
summary_text = str(model_output)
|
| 343 |
+
|
| 344 |
return {
|
| 345 |
+
"summary": summary_text[:500] if summary_text else "Summary generated",
|
| 346 |
"model": task['model_name'],
|
| 347 |
"confidence": 0.85
|
| 348 |
}
|
| 349 |
|
| 350 |
elif "ner" in model_key:
|
| 351 |
+
if isinstance(model_output, list):
|
| 352 |
+
entities = model_output
|
| 353 |
+
elif isinstance(model_output, dict) and "entities" in model_output:
|
| 354 |
+
entities = model_output["entities"]
|
| 355 |
+
else:
|
| 356 |
+
entities = []
|
| 357 |
+
|
| 358 |
return {
|
| 359 |
"entities": self._format_ner_output(entities),
|
| 360 |
"model": task['model_name'],
|
|
|
|
| 362 |
}
|
| 363 |
|
| 364 |
elif "qa" in model_key:
|
| 365 |
+
if isinstance(model_output, list) and model_output:
|
| 366 |
+
answer = model_output[0].get("answer", "") or str(model_output[0])
|
| 367 |
+
score = model_output[0].get("score", 0.75)
|
| 368 |
+
elif isinstance(model_output, dict):
|
| 369 |
+
answer = model_output.get("answer", "Analysis completed")
|
| 370 |
+
score = model_output.get("score", 0.75)
|
| 371 |
+
else:
|
| 372 |
+
answer = str(model_output)
|
| 373 |
+
score = 0.75
|
| 374 |
+
|
| 375 |
return {
|
| 376 |
+
"answer": answer[:500],
|
| 377 |
+
"score": score,
|
| 378 |
"model": task['model_name']
|
| 379 |
}
|
| 380 |
|