Spaces:
Runtime error
Runtime error
Commit
·
d46e3ff
1
Parent(s):
f50d9f5
Update main.py
Browse files
main.py
CHANGED
@@ -1,45 +1,45 @@
|
|
1 |
-
from fastapi import FastAPI, Query, Request, HTTPException
|
2 |
-
import pandas as pd
|
3 |
-
import transformers as pipeline
|
4 |
-
from transformers import AutoTokenizer,AutoModelForSequenceClassification
|
5 |
-
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
|
6 |
|
7 |
|
8 |
-
model_name = "Sonny4Sonnix/twitter-roberta-base-sentimental-analysis-of-covid-tweets"
|
9 |
-
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
10 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
11 |
-
|
12 |
-
sentiment = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
|
13 |
-
|
14 |
-
app = FastAPI()
|
15 |
|
16 |
-
|
17 |
-
async def read_root():
|
18 |
-
return {"message": "Sentiment Analysis API using FastAPI"}
|
19 |
|
20 |
-
|
21 |
-
async def analyze_sentiment(text: str = Query(..., description="Text for sentiment analysis")):
|
22 |
-
result = sentiment(text)
|
23 |
-
sentiment_label = result[0]['label']
|
24 |
-
sentiment_score = result[0]['score']
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
|
38 |
-
|
39 |
|
40 |
-
if _name_ == "_main_":
|
41 |
-
|
42 |
-
|
43 |
|
44 |
|
45 |
# model_name = "Sonny4Sonnix/Movie_Sentiments_Analysis_with_FastAPI" # Replace with the name of the pre-trained model you want to use
|
|
|
1 |
+
# from fastapi import FastAPI, Query, Request, HTTPException
|
2 |
+
# import pandas as pd
|
3 |
+
# import transformers as pipeline
|
4 |
+
# from transformers import AutoTokenizer,AutoModelForSequenceClassification
|
5 |
+
# from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
|
6 |
|
7 |
|
8 |
+
# model_name = "Sonny4Sonnix/twitter-roberta-base-sentimental-analysis-of-covid-tweets"
|
9 |
+
# model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
10 |
+
# tokenizer = AutoTokenizer.from_pretrained(model_name)
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
# sentiment = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
|
|
|
|
|
13 |
|
14 |
+
# app = FastAPI()
|
|
|
|
|
|
|
|
|
15 |
|
16 |
+
# @app.get("/")
|
17 |
+
# async def read_root():
|
18 |
+
# return {"message": "Sentiment Analysis API using FastAPI"}
|
19 |
+
|
20 |
+
# @app.get("/analyze-sentiment/")
|
21 |
+
# async def analyze_sentiment(text: str = Query(..., description="Text for sentiment analysis")):
|
22 |
+
# result = sentiment(text)
|
23 |
+
# sentiment_label = result[0]['label']
|
24 |
+
# sentiment_score = result[0]['score']
|
25 |
+
|
26 |
+
# if sentiment_label == 'LABEL_1':
|
27 |
+
# sentiment_label = "positive"
|
28 |
+
# elif sentiment_label == 'LABEL_0':
|
29 |
+
# sentiment_label = "neutral"
|
30 |
+
# else:
|
31 |
+
# sentiment_label = "negative"
|
32 |
|
33 |
+
# response = {
|
34 |
+
# "sentiment": sentiment_label.capitalize(),
|
35 |
+
# "score": sentiment_score
|
36 |
+
# }
|
37 |
|
38 |
+
# return response
|
39 |
|
40 |
+
# if _name_ == "_main_":
|
41 |
+
# import uvicorn
|
42 |
+
# uvicorn.run(app, host="127.0.0.1", port=7860)
|
43 |
|
44 |
|
45 |
# model_name = "Sonny4Sonnix/Movie_Sentiments_Analysis_with_FastAPI" # Replace with the name of the pre-trained model you want to use
|