big input handle
Browse files
app.py
CHANGED
@@ -1,17 +1,19 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import pipeline
|
3 |
import pandas as pd
|
4 |
|
5 |
@st.cache_resource()
|
6 |
def load_model():
|
7 |
-
|
8 |
"text-classification",
|
9 |
model="alxvlsv/rubert-emotions",
|
10 |
tokenizer="alxvlsv/rubert-emotions",
|
11 |
top_k=None
|
12 |
)
|
|
|
|
|
13 |
|
14 |
-
model = load_model()
|
15 |
|
16 |
label_map = {
|
17 |
"LABEL_0": "admiration",
|
@@ -81,7 +83,9 @@ st.write("Введите текст на русском, и мы покажем,
|
|
81 |
text_input = st.text_area("Введите текст здесь:")
|
82 |
|
83 |
if text_input:
|
84 |
-
|
|
|
|
|
85 |
|
86 |
# Нормализуем вероятности до 100%
|
87 |
total_score = sum(r["score"] for r in results)
|
@@ -114,4 +118,4 @@ if text_input:
|
|
114 |
label_raw = item["label"]
|
115 |
label = label_map.get(label_raw, label_raw)
|
116 |
ru_label, emoji = emotion_labels.get(label, (label, "❓"))
|
117 |
-
st.markdown(f"{ru_label.capitalize()} {emoji} — {item['score']:.2%}")
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import pipeline, AutoTokenizer
|
3 |
import pandas as pd
|
4 |
|
5 |
@st.cache_resource()
|
6 |
def load_model():
|
7 |
+
pipe = pipeline(
|
8 |
"text-classification",
|
9 |
model="alxvlsv/rubert-emotions",
|
10 |
tokenizer="alxvlsv/rubert-emotions",
|
11 |
top_k=None
|
12 |
)
|
13 |
+
tokenizer = AutoTokenizer.from_pretrained("alxvlsv/rubert-emotions")
|
14 |
+
return pipe, tokenizer
|
15 |
|
16 |
+
model, tokenizer = load_model()
|
17 |
|
18 |
label_map = {
|
19 |
"LABEL_0": "admiration",
|
|
|
83 |
text_input = st.text_area("Введите текст здесь:")
|
84 |
|
85 |
if text_input:
|
86 |
+
# Ограничиваем до 256 токенов
|
87 |
+
encoded = tokenizer(text_input, truncation=True, max_length=256, return_tensors="pt")
|
88 |
+
results = model(encoded)[0]
|
89 |
|
90 |
# Нормализуем вероятности до 100%
|
91 |
total_score = sum(r["score"] for r in results)
|
|
|
118 |
label_raw = item["label"]
|
119 |
label = label_map.get(label_raw, label_raw)
|
120 |
ru_label, emoji = emotion_labels.get(label, (label, "❓"))
|
121 |
+
st.markdown(f"{ru_label.capitalize()} {emoji} — {item['score']:.2%}")
|