Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,6 @@ import torch
|
|
5 |
from keybert import KeyBERT
|
6 |
|
7 |
# Initialize your model and tokenizer here
|
8 |
-
# Replace 'your_model_path' and 'your_tokenizer_path' with the actual paths or model identifiers
|
9 |
model_identifier = "karalif/myTestModel"
|
10 |
new_model = AutoModelForSequenceClassification.from_pretrained(model_identifier)
|
11 |
new_tokenizer = AutoTokenizer.from_pretrained(model_identifier)
|
@@ -26,11 +25,13 @@ def get_prediction(text):
|
|
26 |
kw_model = KeyBERT()
|
27 |
keywords = kw_model.extract_keywords(text, keyphrase_ngram_range=(1, 1), stop_words='english', use_maxsum=True, nr_candidates=20, top_n=5)
|
28 |
|
|
|
29 |
response = "MY PREDICTION:<br>"
|
30 |
labels = ['Politeness', 'Toxicity', 'Sentiment', 'Formality']
|
|
|
31 |
|
32 |
for i, label in enumerate(labels):
|
33 |
-
response += f"{label}
|
34 |
|
35 |
response += "<br>INFLUENTIAL KEYWORDS:<br>"
|
36 |
for keyword, score in keywords:
|
@@ -72,4 +73,4 @@ demo = gr.Interface(
|
|
72 |
theme=gr.themes.Default(primary_hue="red", secondary_hue="pink")
|
73 |
)
|
74 |
|
75 |
-
demo.launch()
|
|
|
5 |
from keybert import KeyBERT
|
6 |
|
7 |
# Initialize your model and tokenizer here
|
|
|
8 |
model_identifier = "karalif/myTestModel"
|
9 |
new_model = AutoModelForSequenceClassification.from_pretrained(model_identifier)
|
10 |
new_tokenizer = AutoTokenizer.from_pretrained(model_identifier)
|
|
|
25 |
kw_model = KeyBERT()
|
26 |
keywords = kw_model.extract_keywords(text, keyphrase_ngram_range=(1, 1), stop_words='english', use_maxsum=True, nr_candidates=20, top_n=5)
|
27 |
|
28 |
+
# Modify this part to include HTML span with background color
|
29 |
response = "MY PREDICTION:<br>"
|
30 |
labels = ['Politeness', 'Toxicity', 'Sentiment', 'Formality']
|
31 |
+
colors = ['#b8e994', '#f8d7da', '#fff3cd', '#bee5eb'] # Corresponding colors for labels
|
32 |
|
33 |
for i, label in enumerate(labels):
|
34 |
+
response += f"<span style='background-color:{colors[i]}; color:black;'>{label}</span>: {probs[i]*100:.1f}%<br>"
|
35 |
|
36 |
response += "<br>INFLUENTIAL KEYWORDS:<br>"
|
37 |
for keyword, score in keywords:
|
|
|
73 |
theme=gr.themes.Default(primary_hue="red", secondary_hue="pink")
|
74 |
)
|
75 |
|
76 |
+
demo.launch()
|