Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,11 @@
|
|
| 1 |
-
|
| 2 |
|
| 3 |
from fastapi import FastAPI, HTTPException, UploadFile, File, Form
|
| 4 |
-
from fastapi.responses import JSONResponse
|
| 5 |
from pydantic import BaseModel
|
| 6 |
from pathlib import Path
|
| 7 |
import shutil
|
| 8 |
import logging
|
| 9 |
import uvicorn
|
| 10 |
-
import asyncio
|
| 11 |
from typing import Optional
|
| 12 |
|
| 13 |
from configs import ModelConfig, InferenceConfig
|
|
@@ -66,14 +64,14 @@ async def inference_endpoint(
|
|
| 66 |
elif model_name == "sl_gcn":
|
| 67 |
model_config = ModelConfig(arch="sl_gcn", pretrained="vsltranslation/sl_gcn_joint_v3_0")
|
| 68 |
elif model_name == "dsta_slr":
|
| 69 |
-
model_config = ModelConfig(arch="dsta_slr", pretrained="
|
| 70 |
else:
|
| 71 |
raise ValueError("Unsupported model name.")
|
| 72 |
|
| 73 |
inference_config = InferenceConfig(
|
| 74 |
source=str(video_path),
|
| 75 |
output_dir=str(output_path),
|
| 76 |
-
use_onnx=False,
|
| 77 |
device="cpu", # Bạn có thể thay đổi thành "cuda" nếu sử dụng GPU
|
| 78 |
cache_dir="models/huggingface",
|
| 79 |
visualize=False,
|
|
@@ -93,19 +91,11 @@ async def inference_endpoint(
|
|
| 93 |
logger.info("Pipeline loaded successfully.")
|
| 94 |
|
| 95 |
# Chạy inference
|
| 96 |
-
run_inference(model_config, inference_config, pipeline)
|
| 97 |
logger.info("Inference completed successfully.")
|
| 98 |
|
| 99 |
-
#
|
| 100 |
-
|
| 101 |
-
if results_csv.exists():
|
| 102 |
-
import pandas as pd
|
| 103 |
-
df = pd.read_csv(results_csv)
|
| 104 |
-
predictions = df.to_dict(orient="records")
|
| 105 |
-
else:
|
| 106 |
-
predictions = []
|
| 107 |
-
|
| 108 |
-
return InferenceResponse(status="success", predictions=predictions)
|
| 109 |
|
| 110 |
except Exception as e:
|
| 111 |
logger.exception("Error during inference.")
|
|
|
|
| 1 |
+
# api/main.py
|
| 2 |
|
| 3 |
from fastapi import FastAPI, HTTPException, UploadFile, File, Form
|
|
|
|
| 4 |
from pydantic import BaseModel
|
| 5 |
from pathlib import Path
|
| 6 |
import shutil
|
| 7 |
import logging
|
| 8 |
import uvicorn
|
|
|
|
| 9 |
from typing import Optional
|
| 10 |
|
| 11 |
from configs import ModelConfig, InferenceConfig
|
|
|
|
| 64 |
elif model_name == "sl_gcn":
|
| 65 |
model_config = ModelConfig(arch="sl_gcn", pretrained="vsltranslation/sl_gcn_joint_v3_0")
|
| 66 |
elif model_name == "dsta_slr":
|
| 67 |
+
model_config = ModelConfig(arch="dsta_slr", pretrained="models/dsta_slr_joint_motion_v3_0.onnx")
|
| 68 |
else:
|
| 69 |
raise ValueError("Unsupported model name.")
|
| 70 |
|
| 71 |
inference_config = InferenceConfig(
|
| 72 |
source=str(video_path),
|
| 73 |
output_dir=str(output_path),
|
| 74 |
+
use_onnx=True if model_config.pretrained.endswith(".onnx") else False,
|
| 75 |
device="cpu", # Bạn có thể thay đổi thành "cuda" nếu sử dụng GPU
|
| 76 |
cache_dir="models/huggingface",
|
| 77 |
visualize=False,
|
|
|
|
| 91 |
logger.info("Pipeline loaded successfully.")
|
| 92 |
|
| 93 |
# Chạy inference
|
| 94 |
+
result = run_inference(model_config, inference_config, pipeline)
|
| 95 |
logger.info("Inference completed successfully.")
|
| 96 |
|
| 97 |
+
# Trả về kết quả
|
| 98 |
+
return InferenceResponse(status="success", predictions=result.get("results", []))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
except Exception as e:
|
| 101 |
logger.exception("Error during inference.")
|