Spaces:
Runtime error
Runtime error
ok
Browse files
app.py
CHANGED
@@ -9,13 +9,15 @@ from transformers import AutoTokenizer, AutoModelWithLMHead
|
|
9 |
model_name="bhadresh-savani/bert-base-go-emotion"
|
10 |
model = pipeline('text-classification', model_name, truncation=True)
|
11 |
|
|
|
12 |
model_name = "mrm8488/t5-base-finetuned-emotion"
|
13 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
14 |
model_t5 = AutoModelWithLMHead.from_pretrained(model_name)
|
15 |
-
|
16 |
model_path = "cardiffnlp/twitter-xlm-roberta-base-sentiment"
|
17 |
sentiment_task = pipeline("sentiment-analysis", model=model_path, tokenizer=model_path)
|
18 |
|
|
|
19 |
def get_emotion(text):
|
20 |
input_ids = tokenizer.encode(text + '</s>', return_tensors='pt')
|
21 |
output = model_t5.generate(input_ids=input_ids, return_dict_in_generate=True, output_scores=True)
|
@@ -23,7 +25,7 @@ def get_emotion(text):
|
|
23 |
dec = [tokenizer.decode(ids) for ids in output.sequences]
|
24 |
score = transition_scores.min().item()
|
25 |
return f"{dec[0].replace('<pad>','').replace('</s>','').strip()} [{score}]"
|
26 |
-
|
27 |
chat = ChatOpenAI()
|
28 |
conversation = ConversationChain(llm=chat)
|
29 |
#Write a text example of someone angry
|
@@ -40,12 +42,12 @@ with gr.Blocks() as demo:
|
|
40 |
|
41 |
l = model(bot_message)[0]
|
42 |
label_value = f"{l['label']} [{l['score']}]"
|
43 |
-
label_value_t5 = get_emotion(bot_message)
|
44 |
|
45 |
s = sentiment_task(bot_message)[0]
|
46 |
sentiment_value = f"{s['label']} [{s['score']}]"
|
47 |
|
48 |
-
return "", chat_history, f"Emotion
|
49 |
|
50 |
msg.submit(respond, [msg, chatbot], [msg, chatbot, label_text])
|
51 |
|
|
|
9 |
model_name="bhadresh-savani/bert-base-go-emotion"
|
10 |
model = pipeline('text-classification', model_name, truncation=True)
|
11 |
|
12 |
+
"""
|
13 |
model_name = "mrm8488/t5-base-finetuned-emotion"
|
14 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
15 |
model_t5 = AutoModelWithLMHead.from_pretrained(model_name)
|
16 |
+
"""
|
17 |
model_path = "cardiffnlp/twitter-xlm-roberta-base-sentiment"
|
18 |
sentiment_task = pipeline("sentiment-analysis", model=model_path, tokenizer=model_path)
|
19 |
|
20 |
+
"""
|
21 |
def get_emotion(text):
|
22 |
input_ids = tokenizer.encode(text + '</s>', return_tensors='pt')
|
23 |
output = model_t5.generate(input_ids=input_ids, return_dict_in_generate=True, output_scores=True)
|
|
|
25 |
dec = [tokenizer.decode(ids) for ids in output.sequences]
|
26 |
score = transition_scores.min().item()
|
27 |
return f"{dec[0].replace('<pad>','').replace('</s>','').strip()} [{score}]"
|
28 |
+
"""
|
29 |
chat = ChatOpenAI()
|
30 |
conversation = ConversationChain(llm=chat)
|
31 |
#Write a text example of someone angry
|
|
|
42 |
|
43 |
l = model(bot_message)[0]
|
44 |
label_value = f"{l['label']} [{l['score']}]"
|
45 |
+
#label_value_t5 = get_emotion(bot_message)
|
46 |
|
47 |
s = sentiment_task(bot_message)[0]
|
48 |
sentiment_value = f"{s['label']} [{s['score']}]"
|
49 |
|
50 |
+
return "", chat_history, f"Emotion: {label_value} - Sentiment: {sentiment_value}"
|
51 |
|
52 |
msg.submit(respond, [msg, chatbot], [msg, chatbot, label_text])
|
53 |
|