Spaces:
Sleeping
Sleeping
HudsonArauj
commited on
Commit
·
4cee7eb
1
Parent(s):
0a789ed
capture error
Browse files- app/main.py +7 -2
app/main.py
CHANGED
|
@@ -1,8 +1,9 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
| 2 |
from app.model.model import predict_language
|
| 3 |
from app.model.model import __version__
|
| 4 |
from app.schemas import Prediction, TextIn
|
| 5 |
|
|
|
|
| 6 |
app = FastAPI()
|
| 7 |
|
| 8 |
|
|
@@ -13,4 +14,8 @@ def home():
|
|
| 13 |
|
| 14 |
@app.post("/predict", response_model=Prediction)
|
| 15 |
def predict(payload: TextIn):
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI,HTTPException
|
| 2 |
from app.model.model import predict_language
|
| 3 |
from app.model.model import __version__
|
| 4 |
from app.schemas import Prediction, TextIn
|
| 5 |
|
| 6 |
+
|
| 7 |
app = FastAPI()
|
| 8 |
|
| 9 |
|
|
|
|
| 14 |
|
| 15 |
@app.post("/predict", response_model=Prediction)
|
| 16 |
def predict(payload: TextIn):
|
| 17 |
+
try:
|
| 18 |
+
language = predict_language(payload.text)
|
| 19 |
+
return {"language": language}
|
| 20 |
+
except Exception as e:
|
| 21 |
+
raise HTTPException(status_code=500, detail="Internal Server Error")
|