Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -2,6 +2,7 @@ from fastapi import FastAPI
|
|
| 2 |
from pydantic import BaseModel
|
| 3 |
from fastapi.staticfiles import StaticFiles
|
| 4 |
from fastapi.responses import FileResponse
|
|
|
|
| 5 |
|
| 6 |
app = FastAPI()
|
| 7 |
|
|
@@ -13,7 +14,19 @@ class TextRatingRequest(BaseModel):
|
|
| 13 |
def read_root(text_rating: TextRatingRequest):
|
| 14 |
text = text_rating.text
|
| 15 |
rating = text_rating.rating
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
| 19 |
|
|
|
|
| 2 |
from pydantic import BaseModel
|
| 3 |
from fastapi.staticfiles import StaticFiles
|
| 4 |
from fastapi.responses import FileResponse
|
| 5 |
+
from ml_service import MlProcessing
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
|
|
|
|
| 14 |
def read_root(text_rating: TextRatingRequest):
|
| 15 |
text = text_rating.text
|
| 16 |
rating = text_rating.rating
|
| 17 |
+
raw_data = {"text": text, "star_rating": rating, "skip": skip}
|
| 18 |
+
# processed_data = get_review_sentiment(raw_data)
|
| 19 |
+
ml = MlProcessing(comment_dict=raw_data)
|
| 20 |
+
processed_data = ml.main()
|
| 21 |
+
spans = processed_data.get('spans', list())
|
| 22 |
+
has_sentiments = True
|
| 23 |
+
if not any(spans):
|
| 24 |
+
spans = [{'label': plain_text, 'color': '', 'value': '', 'sentiment': '', 'score': ''}]
|
| 25 |
+
has_sentiments = False
|
| 26 |
+
processed_data['spans'] = spans
|
| 27 |
+
print(f"Processed data : {processed_data}")
|
| 28 |
+
print(f"Has sentiments : {has_sentiments}")
|
| 29 |
+
return {"processed_data": processed_data, "has_sentiments":has_sentiments}
|
| 30 |
|
| 31 |
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
| 32 |
|