Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,41 @@
|
|
|
|
|
|
1 |
from transformers import pipeline
|
2 |
|
3 |
-
# Initialize the translation
|
4 |
translator = pipeline("translation_ru_to_en", model="Helsinki-NLP/opus-mt-ru-en")
|
5 |
-
|
6 |
-
# Initialize the summarization pipeline
|
7 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
8 |
|
9 |
-
#
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
#
|
13 |
-
|
14 |
-
|
|
|
15 |
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
-
|
|
|
|
1 |
+
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 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
8 |
|
9 |
+
# Load your CSV file
|
10 |
+
@st.cache
|
11 |
+
def load_data(filepath):
|
12 |
+
return pd.read_csv(filepath)
|
13 |
+
|
14 |
+
# Translate and summarize text
|
15 |
+
def translate_and_summarize(text):
|
16 |
+
try:
|
17 |
+
# Translate the text
|
18 |
+
translated_text = translator(text)[0]['translation_text']
|
19 |
+
# Summarize the translated text
|
20 |
+
summary = summarizer(translated_text, max_length=140, min_length=110, do_sample=False)[0]['summary_text']
|
21 |
+
return summary
|
22 |
+
except Exception as e:
|
23 |
+
return f"Error in processing: {str(e)}"
|
24 |
|
25 |
+
# Streamlit interface
|
26 |
+
def main():
|
27 |
+
st.title('Text Summarization Tool')
|
28 |
+
file_path = st.text_input('Enter the path to your CSV file:', '')
|
29 |
|
30 |
+
if file_path:
|
31 |
+
data = load_data(file_path)
|
32 |
+
if 'Description' in data.columns:
|
33 |
+
st.write("Summaries:")
|
34 |
+
# Create a new column for summaries
|
35 |
+
data['Summary'] = data['Description'].apply(translate_and_summarize)
|
36 |
+
st.table(data[['ID', 'Title', 'Summary']])
|
37 |
+
else:
|
38 |
+
st.error("The CSV file does not have a 'Description' column.")
|
39 |
|
40 |
+
if __name__ == "__main__":
|
41 |
+
main()
|