File size: 1,392 Bytes
88c381a 91dd84e 240b689 e2f5e33 ec5e298 e2f5e33 88c381a e2f5e33 ec5e298 88c381a e2f5e33 88c381a e2f5e33 225ca46 88c381a fbd0c91 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import streamlit as st
import pandas as pd
from transformers import pipeline
# Initialize the translation and summarization pipelines
translator = pipeline("translation_ru_to_en", model="Helsinki-NLP/opus-mt-ru-en")
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
# Load your CSV file
@st.cache
def load_data(filepath):
return pd.read_csv(filepath)
# Translate and summarize text
def translate_and_summarize(text):
try:
# Translate the text
translated_text = translator(text)[0]['translation_text']
# Summarize the translated 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)}"
# Streamlit interface
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:")
# Create a new column for 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() |