Fralet commited on
Commit
19dc535
1 Parent(s): e2f5e33

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -23
app.py CHANGED
@@ -2,42 +2,48 @@ import streamlit as st
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()
 
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
+ summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
8
+
9
+ # Function to translate and summarize text
10
+
11
 
12
 
 
13
 
 
 
 
 
14
 
 
15
  def translate_and_summarize(text):
16
+ translated_text = translator(text)[0]['translation_text']
17
+ summary = summarizer(translated_text, max_length=140, min_length=110, do_sample=False)[0]['summary_text']
18
+ return summary
19
+
20
+
21
+
22
+
23
+
24
 
25
  # Streamlit interface
26
  def main():
27
+ st.title("CSV Translator and Summarizer")
28
+
29
+ # File uploader
30
+ uploaded_file = st.file_uploader("Choose a CSV file", type="csv")
31
+ if uploaded_file is not None:
32
+ # Read data
33
+ data = pd.read_csv(uploaded_file)
34
+
35
+ # Check if 'Description' column exists
36
 
 
 
37
  if 'Description' in data.columns:
38
+ # Apply translation and summarization
39
+
40
  data['Summary'] = data['Description'].apply(translate_and_summarize)
41
+
42
+ # Display data in a table
43
+ st.write(data[['ID', 'Title', 'Summary']])
44
+
45
  else:
46
+ st.error("Uploaded CSV does not contain 'Description' column.")
47
 
48
  if __name__ == "__main__":
49
  main()