Fralet commited on
Commit
e2f5e33
1 Parent(s): fbd0c91

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -24
app.py CHANGED
@@ -2,35 +2,42 @@ import streamlit as st
2
  import pandas as pd
3
  from transformers import pipeline
4
 
5
- # Load translation and summarization pipelines
6
  translator = pipeline("translation_ru_to_en", model="Helsinki-NLP/opus-mt-ru-en")
7
- # Function to translate and summarize text
 
 
 
 
 
 
 
 
 
8
  def translate_and_summarize(text):
9
- translated_text = translator(text)[0]['translation_text']
10
- summary = summarizer(translated_text, max_length=140, min_length=110, do_sample=False)[0]['summary_text']
11
- return summary
 
 
 
 
 
12
 
13
  # Streamlit interface
14
- # Read data
15
- data = pd.read_csv(uploaded_file)
16
-
17
- # Check necessary columns
18
- required_columns = {'Description', 'Published'}
19
- if not required_columns.issubset(data.columns):
20
- missing_cols = required_columns - set(data.columns)
21
- st.error(f"Uploaded CSV is missing the following required column(s): {', '.join(missing_cols)}")
22
- return
23
-
24
- # Filter rows where 'Published' is unchecked (assuming False or equivalent)
25
- data_filtered = data['Published']
26
-
27
- # Apply translation and summarization
28
- if not data_filtered.empty:
29
- data_filtered['Summary'] = data_filtered['Description'].apply(translate_and_summarize)
30
- # Display data in a table
31
- st.write(data_filtered[['ID', 'Title', 'Summary']])
32
  else:
33
- st.write("No unpublished descriptions to process.")
34
 
35
  if __name__ == "__main__":
36
  main()
 
2
  import pandas as pd
3
  from transformers import pipeline
4
 
5
+ # Initialize the translation and summarization pipelines
6
  translator = pipeline("translation_ru_to_en", model="Helsinki-NLP/opus-mt-ru-en")
7
+
8
+
9
+ summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
10
+
11
+ # Load your CSV file
12
+ @st.cache
13
+ def load_data(filepath):
14
+ return pd.read_csv(filepath)
15
+
16
+ # Translate and summarize text
17
  def translate_and_summarize(text):
18
+ try:
19
+ # Translate the text
20
+ translated_text = translator(text)[0]['translation_text']
21
+ # Summarize the translated text
22
+ summary = summarizer(translated_text, max_length=140, min_length=110, do_sample=False)[0]['summary_text']
23
+ return summary
24
+ except Exception as e:
25
+ return f"Error in processing: {str(e)}"
26
 
27
  # Streamlit interface
28
+ def main():
29
+ st.title('Text Summarization Tool')
30
+ file_path = st.text_input('Enter the path to your CSV file:', '')
31
+
32
+ if file_path:
33
+ data = load_data(file_path)
34
+ if 'Description' in data.columns:
35
+ st.write("Summaries:")
36
+ # Create a new column for summaries
37
+ data['Summary'] = data['Description'].apply(translate_and_summarize)
38
+ st.table(data[['ID', 'Title', 'Summary']])
 
 
 
 
 
 
 
39
  else:
40
+ st.error("The CSV file does not have a 'Description' column.")
41
 
42
  if __name__ == "__main__":
43
  main()