Commit
·
df3e017
1
Parent(s):
c0ee674
feat: Added application file
Browse files- config/config.ini +2 -2
- src/api.py +1 -26
- src/data_loader.py +1 -1
config/config.ini
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
[data]
|
| 2 |
-
data_dir =
|
| 3 |
-
possible_labels_dir =
|
| 4 |
|
| 5 |
[model]
|
| 6 |
name = facebook/bart-large-mnli
|
|
|
|
| 1 |
[data]
|
| 2 |
+
data_dir = https://huggingface.co/spaces/kubrabuzlu/SentimentAndIntentionAnalysis/blob/main/data
|
| 3 |
+
possible_labels_dir = https://huggingface.co/spaces/kubrabuzlu/SentimentAndIntentionAnalysis/blob/main/data/possible_labels.json
|
| 4 |
|
| 5 |
[model]
|
| 6 |
name = facebook/bart-large-mnli
|
src/api.py
CHANGED
|
@@ -2,33 +2,8 @@ import configparser
|
|
| 2 |
|
| 3 |
from fastapi import FastAPI
|
| 4 |
from pydantic import BaseModel
|
|
|
|
| 5 |
from .data_loader import *
|
| 6 |
-
from transformers import pipeline, BartTokenizer, BartForSequenceClassification
|
| 7 |
-
class ZeroShotClassifier:
|
| 8 |
-
|
| 9 |
-
def __init__(self, model_name, sentiment_labels, intention_labels):
|
| 10 |
-
self.model = self.create_model(model_name)
|
| 11 |
-
self.model_name = model_name
|
| 12 |
-
self.sentiment_labels = sentiment_labels
|
| 13 |
-
self.intention_labels = intention_labels
|
| 14 |
-
|
| 15 |
-
def create_model(self, model_name):
|
| 16 |
-
# Create Model
|
| 17 |
-
tokenizer = BartTokenizer.from_pretrained(model_name)
|
| 18 |
-
model = BartForSequenceClassification.from_pretrained(model_name)
|
| 19 |
-
classifier = pipeline("zero-shot-classification", model=model, tokenizer=tokenizer)
|
| 20 |
-
return classifier
|
| 21 |
-
|
| 22 |
-
def analyze_text(self, text):
|
| 23 |
-
# Sentiment analysis
|
| 24 |
-
sentiment_result = self.model(text, self.sentiment_labels)
|
| 25 |
-
sentiment = sentiment_result["labels"][0]
|
| 26 |
-
|
| 27 |
-
# Intention analysis
|
| 28 |
-
intention_result = self.model(text, self.intention_labels)
|
| 29 |
-
intention = intention_result["labels"][0]
|
| 30 |
-
|
| 31 |
-
return {"sentiment": sentiment, "intention": intention}
|
| 32 |
|
| 33 |
# Initialize FastAPI app
|
| 34 |
app = FastAPI()
|
|
|
|
| 2 |
|
| 3 |
from fastapi import FastAPI
|
| 4 |
from pydantic import BaseModel
|
| 5 |
+
from .SentimentAndIntentionAnalysis import ZeroShotClassifier
|
| 6 |
from .data_loader import *
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Initialize FastAPI app
|
| 9 |
app = FastAPI()
|
src/data_loader.py
CHANGED
|
@@ -3,7 +3,7 @@ import json
|
|
| 3 |
def get_config():
|
| 4 |
# Read config
|
| 5 |
config = configparser.ConfigParser()
|
| 6 |
-
config.read(r"
|
| 7 |
|
| 8 |
# Get model_name
|
| 9 |
model_name = config["model"]["name"]
|
|
|
|
| 3 |
def get_config():
|
| 4 |
# Read config
|
| 5 |
config = configparser.ConfigParser()
|
| 6 |
+
config.read(r"https://huggingface.co/spaces/kubrabuzlu/SentimentAndIntentionAnalysis/tree/main/config/config.ini")
|
| 7 |
|
| 8 |
# Get model_name
|
| 9 |
model_name = config["model"]["name"]
|