Update app.py
Browse files
app.py
CHANGED
@@ -2,40 +2,36 @@ import streamlit as st
|
|
2 |
import pandas as pd
|
3 |
from transformers import pipeline
|
4 |
|
5 |
-
#
|
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 |
-
#
|
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 |
-
|
17 |
-
|
18 |
-
|
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(
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
-
|
31 |
-
data = load_data(file_path)
|
32 |
if 'Description' in data.columns:
|
33 |
-
|
34 |
-
# Create a new column for summaries
|
35 |
data['Summary'] = data['Description'].apply(translate_and_summarize)
|
36 |
-
|
|
|
|
|
|
|
37 |
else:
|
38 |
-
st.error("
|
39 |
|
40 |
if __name__ == "__main__":
|
41 |
-
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 |
def translate_and_summarize(text):
|
11 |
+
translated_text = translator(text)[0]['translation_text']
|
12 |
+
summary = summarizer(translated_text, max_length=140, min_length=110, do_sample=False)[0]['summary_text']
|
13 |
+
return summary
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
# Streamlit interface
|
16 |
def main():
|
17 |
+
st.title("CSV Translator and Summarizer")
|
18 |
+
|
19 |
+
# File uploader
|
20 |
+
uploaded_file = st.file_uploader("Choose a CSV file", type="csv")
|
21 |
+
if uploaded_file is not None:
|
22 |
+
# Read data
|
23 |
+
data = pd.read_csv(uploaded_file)
|
24 |
|
25 |
+
# Check if 'Description' column exists
|
|
|
26 |
if 'Description' in data.columns:
|
27 |
+
# Apply translation and summarization
|
|
|
28 |
data['Summary'] = data['Description'].apply(translate_and_summarize)
|
29 |
+
|
30 |
+
# Display data in a table
|
31 |
+
st.write(data[['ID', 'Title', 'Summary']])
|
32 |
+
|
33 |
else:
|
34 |
+
st.error("Uploaded CSV does not contain 'Description' column.")
|
35 |
|
36 |
if __name__ == "__main__":
|
37 |
+
main()
|