Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
|
@@ -25,12 +25,8 @@ def get_db():
|
|
| 25 |
finally:
|
| 26 |
db.close()
|
| 27 |
|
| 28 |
-
@app.post("/analyze_sentiment"
|
| 29 |
-
def create_sentiment_result(
|
| 30 |
-
sentiment_result: schemas.SentimentResultCreate,
|
| 31 |
-
text_input: str,
|
| 32 |
-
db: Session = Depends(get_db)
|
| 33 |
-
):
|
| 34 |
try:
|
| 35 |
# Perform input validation
|
| 36 |
if not isinstance(text_input, str) or not text_input.strip():
|
|
@@ -53,9 +49,17 @@ def create_sentiment_result(
|
|
| 53 |
db.add(new_sentiment_result)
|
| 54 |
db.commit()
|
| 55 |
db.refresh(new_sentiment_result)
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
except Exception as e:
|
| 61 |
raise HTTPException(
|
|
|
|
| 25 |
finally:
|
| 26 |
db.close()
|
| 27 |
|
| 28 |
+
@app.post("/analyze_sentiment")
|
| 29 |
+
def create_sentiment_result(sentiment_result: schemas.SentimentResultCreate,text_input: str,db: Session = Depends(get_db))->JSONResponse:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
try:
|
| 31 |
# Perform input validation
|
| 32 |
if not isinstance(text_input, str) or not text_input.strip():
|
|
|
|
| 49 |
db.add(new_sentiment_result)
|
| 50 |
db.commit()
|
| 51 |
db.refresh(new_sentiment_result)
|
| 52 |
+
# Convert datetime objects to strings
|
| 53 |
+
created_at_str = new_sentiment_result.createdAt.strftime("%Y-%m-%dT%H:%M:%SZ")
|
| 54 |
+
textinput_dict = {
|
| 55 |
+
"id": new_user.id,
|
| 56 |
+
"text_input": new_sentiment_result.text_input,
|
| 57 |
+
"score": new_sentiment_result.score,
|
| 58 |
+
"label": new_sentiment_result.label,
|
| 59 |
+
"createdAt": created_at_str,
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
return JSONResponse(content=text_input_dict, status_code=status.HTTP_201_CREATED)
|
| 63 |
|
| 64 |
except Exception as e:
|
| 65 |
raise HTTPException(
|