Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import os
|
| 2 |
from fastapi import FastAPI
|
| 3 |
from pydantic import BaseModel
|
| 4 |
-
from transformers import pipeline, AutoTokenizer
|
| 5 |
from langdetect import detect, DetectorFactory
|
| 6 |
|
| 7 |
# Ensure consistent language detection results
|
|
@@ -16,14 +16,14 @@ app = FastAPI()
|
|
| 16 |
# Load the original tokenizer from the base model
|
| 17 |
original_tokenizer = AutoTokenizer.from_pretrained("tabularisai/multilingual-sentiment-analysis")
|
| 18 |
|
| 19 |
-
# Load the fine-tuned model and pass the tokenizer explicitly
|
| 20 |
multilingual_model = pipeline(
|
| 21 |
"sentiment-analysis",
|
| 22 |
-
model="
|
| 23 |
tokenizer=original_tokenizer
|
| 24 |
)
|
| 25 |
|
| 26 |
-
# English model
|
| 27 |
english_model = pipeline("sentiment-analysis", model="siebert/sentiment-roberta-large-english")
|
| 28 |
|
| 29 |
class SentimentRequest(BaseModel):
|
|
|
|
| 1 |
import os
|
| 2 |
from fastapi import FastAPI
|
| 3 |
from pydantic import BaseModel
|
| 4 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
|
| 5 |
from langdetect import detect, DetectorFactory
|
| 6 |
|
| 7 |
# Ensure consistent language detection results
|
|
|
|
| 16 |
# Load the original tokenizer from the base model
|
| 17 |
original_tokenizer = AutoTokenizer.from_pretrained("tabularisai/multilingual-sentiment-analysis")
|
| 18 |
|
| 19 |
+
# Load the fine-tuned model (johndoee/sentiment) and pass the tokenizer explicitly
|
| 20 |
multilingual_model = pipeline(
|
| 21 |
"sentiment-analysis",
|
| 22 |
+
model="johndoee/sentiment",
|
| 23 |
tokenizer=original_tokenizer
|
| 24 |
)
|
| 25 |
|
| 26 |
+
# Load the English sentiment model
|
| 27 |
english_model = pipeline("sentiment-analysis", model="siebert/sentiment-roberta-large-english")
|
| 28 |
|
| 29 |
class SentimentRequest(BaseModel):
|