jonathanjordan21 commited on
Commit
ea8b4a5
1 Parent(s): 76e625c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -1,10 +1,14 @@
1
- from fastapi import FastAPI
2
  from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
3
  import torch
 
4
 
5
  app = FastAPI()
6
 
7
 
 
 
 
8
 
9
  model_name = "cardiffnlp/twitter-xlm-roberta-base-sentiment"
10
  sentiment_model = AutoModelForSequenceClassification.from_pretrained(model_name)
@@ -17,7 +21,8 @@ def greet_json():
17
 
18
 
19
  @app.post("/sentiment_score")
20
- async def sentiment_score(text: str):
 
21
  inputs = sentiment_tokenizer(text[:2500], return_tensors='pt')
22
 
23
  with torch.no_grad():
 
1
+ from fastapi import FastAPI, Request
2
  from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
3
  import torch
4
+ from pydantic import BaseModel
5
 
6
  app = FastAPI()
7
 
8
 
9
+ class InputText(BaseModel):
10
+ text : str
11
+
12
 
13
  model_name = "cardiffnlp/twitter-xlm-roberta-base-sentiment"
14
  sentiment_model = AutoModelForSequenceClassification.from_pretrained(model_name)
 
21
 
22
 
23
  @app.post("/sentiment_score")
24
+ async def sentiment_score(inp: InputText):
25
+ text = inp.text
26
  inputs = sentiment_tokenizer(text[:2500], return_tensors='pt')
27
 
28
  with torch.no_grad():