Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1091,6 +1091,85 @@ async def reset_session(session_id: str):
|
|
1091 |
"removed_systems": removed_systems
|
1092 |
}
|
1093 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1094 |
# API info endpoint
|
1095 |
@app.get("/api")
|
1096 |
async def api_info():
|
|
|
1091 |
"removed_systems": removed_systems
|
1092 |
}
|
1093 |
|
1094 |
+
#verifikasi model loading
|
1095 |
+
@app.get("/verify-models")
|
1096 |
+
async def verify_all_models():
|
1097 |
+
"""Verify all 11 models can be loaded"""
|
1098 |
+
verification_results = {}
|
1099 |
+
total_models = len(MODELS)
|
1100 |
+
successful_loads = 0
|
1101 |
+
|
1102 |
+
for model_id, model_config in MODELS.items():
|
1103 |
+
try:
|
1104 |
+
print(f"π Verifying {model_config['name']}...")
|
1105 |
+
|
1106 |
+
if model_id not in app.state.pipelines:
|
1107 |
+
pipeline_kwargs = {
|
1108 |
+
"task": model_config["task"],
|
1109 |
+
"model": model_config["model_path"],
|
1110 |
+
"device": -1,
|
1111 |
+
"torch_dtype": torch.float32,
|
1112 |
+
"model_kwargs": {
|
1113 |
+
"torchscript": False,
|
1114 |
+
"low_cpu_mem_usage": True
|
1115 |
+
}
|
1116 |
+
}
|
1117 |
+
|
1118 |
+
app.state.pipelines[model_id] = pipeline(**pipeline_kwargs)
|
1119 |
+
gc.collect()
|
1120 |
+
|
1121 |
+
# Test with simple input
|
1122 |
+
if model_config["task"] == "text-generation":
|
1123 |
+
test_result = app.state.pipelines[model_id](
|
1124 |
+
"Hello",
|
1125 |
+
max_length=10,
|
1126 |
+
do_sample=False,
|
1127 |
+
pad_token_id=app.state.pipelines[model_id].tokenizer.eos_token_id
|
1128 |
+
)
|
1129 |
+
verification_results[model_id] = {
|
1130 |
+
"status": "β
SUCCESS",
|
1131 |
+
"name": model_config["name"],
|
1132 |
+
"task": model_config["task"],
|
1133 |
+
"test_output_length": len(test_result[0]['generated_text'])
|
1134 |
+
}
|
1135 |
+
elif model_config["task"] == "text-classification":
|
1136 |
+
test_result = app.state.pipelines[model_id]("Hello test", truncation=True)
|
1137 |
+
verification_results[model_id] = {
|
1138 |
+
"status": "β
SUCCESS",
|
1139 |
+
"name": model_config["name"],
|
1140 |
+
"task": model_config["task"],
|
1141 |
+
"test_score": test_result[0]['score']
|
1142 |
+
}
|
1143 |
+
elif model_config["task"] == "text2text-generation":
|
1144 |
+
test_result = app.state.pipelines[model_id]("translate: Hello", max_length=10)
|
1145 |
+
verification_results[model_id] = {
|
1146 |
+
"status": "β
SUCCESS",
|
1147 |
+
"name": model_config["name"],
|
1148 |
+
"task": model_config["task"],
|
1149 |
+
"test_output": test_result[0]['generated_text']
|
1150 |
+
}
|
1151 |
+
|
1152 |
+
successful_loads += 1
|
1153 |
+
print(f"β
{model_config['name']} verified successfully")
|
1154 |
+
|
1155 |
+
except Exception as e:
|
1156 |
+
verification_results[model_id] = {
|
1157 |
+
"status": "β FAILED",
|
1158 |
+
"name": model_config["name"],
|
1159 |
+
"task": model_config["task"],
|
1160 |
+
"error": str(e)
|
1161 |
+
}
|
1162 |
+
print(f"β {model_config['name']} failed: {e}")
|
1163 |
+
|
1164 |
+
return {
|
1165 |
+
"total_models": total_models,
|
1166 |
+
"successful_loads": successful_loads,
|
1167 |
+
"success_rate": f"{(successful_loads/total_models)*100:.1f}%",
|
1168 |
+
"results": verification_results,
|
1169 |
+
"memory_usage": f"{torch.cuda.memory_allocated() / 1024**2:.1f}MB" if torch.cuda.is_available() else "CPU Mode",
|
1170 |
+
"loaded_pipelines": len(app.state.pipelines)
|
1171 |
+
}
|
1172 |
+
|
1173 |
# API info endpoint
|
1174 |
@app.get("/api")
|
1175 |
async def api_info():
|