Update app.py
Browse files
app.py
CHANGED
@@ -2,30 +2,23 @@ import streamlit as st
|
|
2 |
import torch
|
3 |
from transformers import T5Tokenizer, T5ForConditionalGeneration
|
4 |
|
5 |
-
|
6 |
-
model_name = "sarahai/ruT5-base-summarizer"
|
7 |
tokenizer = T5Tokenizer.from_pretrained(model_name)
|
8 |
model = T5ForConditionalGeneration.from_pretrained(model_name)
|
9 |
|
10 |
def summarize(text):
|
11 |
-
"""Summarizes the input text using the T5 model.
|
12 |
-
|
13 |
-
Args:
|
14 |
-
text (str): The text to be summarized.
|
15 |
|
16 |
-
Returns:
|
17 |
-
str: The generated summary of the input text.
|
18 |
-
"""
|
19 |
|
20 |
try:
|
21 |
-
|
22 |
input_ids = tokenizer(text, return_tensors="pt", padding="max_length").input_ids
|
23 |
|
24 |
-
|
25 |
outputs = model.generate(
|
26 |
input_ids,
|
27 |
-
max_length=
|
28 |
-
min_length=
|
29 |
length_penalty=2.0,
|
30 |
num_beams=4,
|
31 |
early_stopping=True,
|
@@ -35,17 +28,17 @@ def summarize(text):
|
|
35 |
return summary
|
36 |
|
37 |
except Exception as e:
|
38 |
-
return f"
|
39 |
|
40 |
-
st.title("
|
41 |
-
st.write("
|
42 |
|
43 |
user_input = st.text_area("", height=200)
|
44 |
|
45 |
-
if st.button("
|
46 |
if user_input:
|
47 |
summary = summarize(user_input)
|
48 |
-
st.success(f"
|
49 |
else:
|
50 |
-
st.warning("
|
51 |
|
|
|
2 |
import torch
|
3 |
from transformers import T5Tokenizer, T5ForConditionalGeneration
|
4 |
|
5 |
+
|
6 |
+
model_name = "sarahai/ruT5-base-summarizer"
|
7 |
tokenizer = T5Tokenizer.from_pretrained(model_name)
|
8 |
model = T5ForConditionalGeneration.from_pretrained(model_name)
|
9 |
|
10 |
def summarize(text):
|
|
|
|
|
|
|
|
|
11 |
|
|
|
|
|
|
|
12 |
|
13 |
try:
|
14 |
+
|
15 |
input_ids = tokenizer(text, return_tensors="pt", padding="max_length").input_ids
|
16 |
|
17 |
+
|
18 |
outputs = model.generate(
|
19 |
input_ids,
|
20 |
+
max_length=250,
|
21 |
+
min_length=150,
|
22 |
length_penalty=2.0,
|
23 |
num_beams=4,
|
24 |
early_stopping=True,
|
|
|
28 |
return summary
|
29 |
|
30 |
except Exception as e:
|
31 |
+
return f"Ошибка: {str(e)}"
|
32 |
|
33 |
+
st.title("Суммаризатор")
|
34 |
+
st.write("Введите текст :")
|
35 |
|
36 |
user_input = st.text_area("", height=200)
|
37 |
|
38 |
+
if st.button("Суммаризовать"):
|
39 |
if user_input:
|
40 |
summary = summarize(user_input)
|
41 |
+
st.success(f"Результат:\n{summary}")
|
42 |
else:
|
43 |
+
st.warning("Пожалуйста, введите хотя бы маленький текст")
|
44 |
|