Spaces:
Runtime error
Runtime error
Commit
·
0c7b69f
1
Parent(s):
f0e0409
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
@@ -81,13 +81,6 @@ class Utility(object):
|
|
81 |
repo_type="space")
|
82 |
return
|
83 |
|
84 |
-
# Hugging face : Login to Hugging face
|
85 |
-
def _login_hface(self):
|
86 |
-
huggingface_hub.login(self._decrypt_it(self._huggingface_key),
|
87 |
-
add_to_git_credential=True) # non-blocking login
|
88 |
-
self._ph()
|
89 |
-
return
|
90 |
-
|
91 |
# System Info : Fetch available CPU and RAM of the system
|
92 |
def fetch_system_info(self):
|
93 |
s=''
|
@@ -157,6 +150,14 @@ class Utility(object):
|
|
157 |
y = f.encrypt(p)
|
158 |
return y
|
159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
# Add method to class
|
161 |
def add_method(cls):
|
162 |
def decorator(func):
|
@@ -170,7 +171,7 @@ def add_method(cls):
|
|
170 |
""" This file contains multiple Python classes and responssible to provide Emotions based on the given user input
|
171 |
Currently it supports emotions like Anger, Joy, Optimism and Sadness"""
|
172 |
|
173 |
-
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
174 |
from matplotlib.colors import LinearSegmentedColormap
|
175 |
import scipy
|
176 |
import scipy.special
|
@@ -217,10 +218,12 @@ def _predict_sentiment(p):
|
|
217 |
inputs = sentiment.tokenizer(p, return_tensors="pt")
|
218 |
# Pass inputs through model
|
219 |
outputs = sentiment.model(**inputs)
|
|
|
220 |
out_data = outputs[0][0]
|
221 |
scores = out_data.detach().numpy()
|
|
|
222 |
scores = scipy.special.softmax(scores)
|
223 |
-
sentiment_map =
|
224 |
df_out = pandas.DataFrame([scores], columns=sentiment_map)
|
225 |
df_out = df_out[['Love' , 'Joy', 'Surprise' , 'Fear', 'Sadness', 'Anger']]
|
226 |
return df_out
|
@@ -255,7 +258,7 @@ exp = [
|
|
255 |
['I am feeling very bad today.'],
|
256 |
['I hate to swim early morning.']
|
257 |
]
|
258 |
-
arti= "<b>DistilBERT is 27 times faster than OpenAI, making it the clear winner for speed-sensitive applications.</b>\nWe did a comparision of OpenAI vs DestilBert model (which we are currently using in this space) by running 31 sentences in a loop and found DestilBert is 27 times faster than OpenAI."
|
259 |
|
260 |
gradio.Interface(fn=predict_sentiment,
|
261 |
inputs=in_box,
|
|
|
81 |
repo_type="space")
|
82 |
return
|
83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
# System Info : Fetch available CPU and RAM of the system
|
85 |
def fetch_system_info(self):
|
86 |
s=''
|
|
|
150 |
y = f.encrypt(p)
|
151 |
return y
|
152 |
|
153 |
+
# Capitalize : Capitalizes the first letter of each word in a list.
|
154 |
+
def capitalize_first_letter(self, list_of_words):
|
155 |
+
capitalized_words = []
|
156 |
+
for word in list_of_words:
|
157 |
+
capitalized_word = word[0].upper() + word[1:]
|
158 |
+
capitalized_words.append(capitalized_word)
|
159 |
+
return capitalized_words
|
160 |
+
|
161 |
# Add method to class
|
162 |
def add_method(cls):
|
163 |
def decorator(func):
|
|
|
171 |
""" This file contains multiple Python classes and responssible to provide Emotions based on the given user input
|
172 |
Currently it supports emotions like Anger, Joy, Optimism and Sadness"""
|
173 |
|
174 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
175 |
from matplotlib.colors import LinearSegmentedColormap
|
176 |
import scipy
|
177 |
import scipy.special
|
|
|
218 |
inputs = sentiment.tokenizer(p, return_tensors="pt")
|
219 |
# Pass inputs through model
|
220 |
outputs = sentiment.model(**inputs)
|
221 |
+
print(outputs)
|
222 |
out_data = outputs[0][0]
|
223 |
scores = out_data.detach().numpy()
|
224 |
+
print(out_data)
|
225 |
scores = scipy.special.softmax(scores)
|
226 |
+
sentiment_map = sentiment.utility.capitalize_first_letter(sentiment.model.config.label2id.keys())
|
227 |
df_out = pandas.DataFrame([scores], columns=sentiment_map)
|
228 |
df_out = df_out[['Love' , 'Joy', 'Surprise' , 'Fear', 'Sadness', 'Anger']]
|
229 |
return df_out
|
|
|
258 |
['I am feeling very bad today.'],
|
259 |
['I hate to swim early morning.']
|
260 |
]
|
261 |
+
arti= "<b>DistilBERT is 27 times faster than OpenAI, making it the clear winner for speed-sensitive applications.</b>\n\nWe did a comparision of OpenAI vs DestilBert model (which we are currently using in this space) by running 31 sentences in a loop and found DestilBert is 27 times faster than OpenAI."
|
262 |
|
263 |
gradio.Interface(fn=predict_sentiment,
|
264 |
inputs=in_box,
|