sarahai commited on
Commit
0bd64d6
1 Parent(s): ecc0067

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -19
app.py CHANGED
@@ -2,30 +2,23 @@ import streamlit as st
2
  import torch
3
  from transformers import T5Tokenizer, T5ForConditionalGeneration
4
 
5
- # Load the pre-trained model and tokenizer
6
- model_name = "sarahai/ruT5-base-summarizer" # Adjust if using a different model
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
- # Preprocess the input text
22
  input_ids = tokenizer(text, return_tensors="pt", padding="max_length").input_ids
23
 
24
- # Generate summary
25
  outputs = model.generate(
26
  input_ids,
27
- max_length=100,
28
- min_length=50,
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"Error: {str(e)}"
39
 
40
- st.title("Hugging Face T5 Summarizer")
41
- st.write("Enter the text you want to summarize (in Russian):")
42
 
43
  user_input = st.text_area("", height=200)
44
 
45
- if st.button("Summarize"):
46
  if user_input:
47
  summary = summarize(user_input)
48
- st.success(f"Summary:\n{summary}")
49
  else:
50
- st.warning("Please enter some text to summarize.")
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