|
import streamlit as st |
|
import pandas as pd |
|
from transformers import pipeline |
|
|
|
|
|
translator = pipeline("translation_ru_to_en", model="Helsinki-NLP/opus-mt-ru-en") |
|
summarizer = pipeline("summarization", model="facebook/bart-large-cnn") |
|
|
|
|
|
@st.cache |
|
def load_data(filepath): |
|
return pd.read_csv(filepath) |
|
|
|
|
|
def translate_and_summarize(text): |
|
try: |
|
|
|
translated_text = translator(text)[0]['translation_text'] |
|
|
|
summary = summarizer(translated_text, max_length=140, min_length=110, do_sample=False)[0]['summary_text'] |
|
return summary |
|
except Exception as e: |
|
return f"Error in processing: {str(e)}" |
|
|
|
|
|
def main(): |
|
st.title('Text Summarization Tool') |
|
file_path = st.text_input('Enter the path to your CSV file:', '') |
|
|
|
if file_path: |
|
data = load_data(file_path) |
|
if 'Description' in data.columns: |
|
st.write("Summaries:") |
|
|
|
data['Summary'] = data['Description'].apply(translate_and_summarize) |
|
st.table(data[['ID', 'Title', 'Summary']]) |
|
else: |
|
st.error("The CSV file does not have a 'Description' column.") |
|
|
|
if __name__ == "__main__": |
|
main() |