Spaces:
Runtime error
Runtime error
ok
Browse files- app.py +9 -2
- requirements.txt +4 -4
app.py
CHANGED
|
@@ -2,15 +2,19 @@ import gradio as gr
|
|
| 2 |
from langchain.chat_models import ChatOpenAI
|
| 3 |
from langchain.chains import ConversationChain
|
| 4 |
from transformers import pipeline
|
|
|
|
|
|
|
| 5 |
|
| 6 |
model_name="nateraw/bert-base-uncased-emotion"
|
| 7 |
model = pipeline('text-classification', model_name, truncation=True)
|
| 8 |
|
| 9 |
-
from transformers import AutoTokenizer, AutoModelWithLMHead
|
| 10 |
model_name = "mrm8488/t5-base-finetuned-emotion"
|
| 11 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 12 |
model_t5 = AutoModelWithLMHead.from_pretrained(model_name)
|
| 13 |
|
|
|
|
|
|
|
|
|
|
| 14 |
def get_emotion(text):
|
| 15 |
input_ids = tokenizer.encode(text + '</s>', return_tensors='pt')
|
| 16 |
output = model_t5.generate(input_ids=input_ids, return_dict_in_generate=True, output_scores=True)
|
|
@@ -37,7 +41,10 @@ with gr.Blocks() as demo:
|
|
| 37 |
label_value = f"{l['label']} [{l['score']}]"
|
| 38 |
label_value_t5 = get_emotion(bot_message)
|
| 39 |
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
msg.submit(respond, [msg, chatbot], [msg, chatbot, label_text])
|
| 43 |
|
|
|
|
| 2 |
from langchain.chat_models import ChatOpenAI
|
| 3 |
from langchain.chains import ConversationChain
|
| 4 |
from transformers import pipeline
|
| 5 |
+
from transformers import AutoTokenizer, AutoModelWithLMHead
|
| 6 |
+
|
| 7 |
|
| 8 |
model_name="nateraw/bert-base-uncased-emotion"
|
| 9 |
model = pipeline('text-classification', model_name, truncation=True)
|
| 10 |
|
|
|
|
| 11 |
model_name = "mrm8488/t5-base-finetuned-emotion"
|
| 12 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 13 |
model_t5 = AutoModelWithLMHead.from_pretrained(model_name)
|
| 14 |
|
| 15 |
+
model_path = "cardiffnlp/twitter-xlm-roberta-base-sentiment"
|
| 16 |
+
sentiment_task = pipeline("sentiment-analysis", model=model_path, tokenizer=model_path)
|
| 17 |
+
|
| 18 |
def get_emotion(text):
|
| 19 |
input_ids = tokenizer.encode(text + '</s>', return_tensors='pt')
|
| 20 |
output = model_t5.generate(input_ids=input_ids, return_dict_in_generate=True, output_scores=True)
|
|
|
|
| 41 |
label_value = f"{l['label']} [{l['score']}]"
|
| 42 |
label_value_t5 = get_emotion(bot_message)
|
| 43 |
|
| 44 |
+
s = sentiment_task(bot_message)
|
| 45 |
+
sentiment_value = f"{s['label']} [{s['score']}]"
|
| 46 |
+
|
| 47 |
+
return "", chat_history, f"Emotion [1]: {label_value_t5} - Emotion [2]: {label_value} - Sentiment : {sentiment_value}"
|
| 48 |
|
| 49 |
msg.submit(respond, [msg, chatbot], [msg, chatbot, label_text])
|
| 50 |
|
requirements.txt
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
-
langchain
|
| 2 |
-
openai
|
| 3 |
-
transformers
|
| 4 |
-
torch
|
| 5 |
sentencepiece
|
|
|
|
| 1 |
+
langchain
|
| 2 |
+
openai
|
| 3 |
+
transformers
|
| 4 |
+
torch
|
| 5 |
sentencepiece
|