|
import requests |
|
import streamlit as st |
|
import PyPDF2 |
|
import torch |
|
from transformers import AutoTokenizer, LEDForConditionalGeneration |
|
st.set_page_config(page_title="Summarization", page_icon="📈",layout="wide") |
|
hide_streamlit_style = """ |
|
<style> |
|
#MainMenu {visibility: hidden;} |
|
footer { |
|
visibility: hidden; |
|
|
|
} |
|
footer:after { |
|
content:'©2023 Sravathi AI Technology. All rights reserved.'; |
|
visibility: visible; |
|
display: block; |
|
position: relative; |
|
#background-color: red; |
|
padding: 5px; |
|
top: 2px; |
|
} |
|
</style> |
|
""" |
|
st.markdown(hide_streamlit_style, unsafe_allow_html=True) |
|
import pandas as pd |
|
import time |
|
import sys |
|
import pickle |
|
|
|
import base64 |
|
|
|
|
|
import numpy as np |
|
import json |
|
import os |
|
import re |
|
import nltk |
|
from nltk.corpus import words |
|
nltk.download('words') |
|
|
|
|
|
|
|
|
|
def add_bg_from_local(image_file): |
|
with open(image_file, "rb") as image_file: |
|
encoded_string = base64.b64encode(image_file.read()) |
|
st.markdown( |
|
f""" |
|
<style> |
|
.stApp {{ |
|
background-image: url(data:image/{"jpg"};base64,{encoded_string.decode()}); |
|
background-size: cover |
|
}} |
|
</style> |
|
""", |
|
unsafe_allow_html=True |
|
) |
|
|
|
|
|
|
|
st.header('Summarization') |
|
def convert_df(df): |
|
|
|
return df.to_csv(index=False).encode('utf-8') |
|
col1, col2 = st.columns([4,1]) |
|
result_csv_batch_sql = result_csv_batch_fail=result_csv_batch=result_csv4=result_csv3=result_csv1=result_csv2=0 |
|
|
|
with col1: |
|
models = st.selectbox( |
|
'Select the option', |
|
('model1', )) |
|
|
|
if models == 'model1': |
|
st.markdown("") |
|
else: |
|
st.markdown("") |
|
with st.form("form1"): |
|
hide_label = """ |
|
<style> |
|
.css-9ycgxx { |
|
display: none; |
|
} |
|
</style> |
|
""" |
|
text_data = st.text_input('Enter the text') |
|
print(text_data) |
|
st.markdown(hide_label, unsafe_allow_html=True) |
|
submitted = st.form_submit_button("Submit") |
|
if submitted: |
|
|
|
tokenizer = AutoTokenizer.from_pretrained('allenai/PRIMERA-multinews') |
|
model = LEDForConditionalGeneration.from_pretrained('allenai/PRIMERA-multinews') |
|
|
|
device = "cpu" |
|
model.to(device) |
|
documents = text_data |
|
|
|
|
|
inputs = tokenizer(documents, return_tensors='pt', padding=True, truncation=True,max_length=1000000) |
|
|
|
|
|
inputs = inputs.to(device) |
|
|
|
|
|
outputs = model.generate(**inputs,max_length=1000000) |
|
|
|
|
|
st.write(tokenizer.batch_decode(outputs, skip_special_tokens=True)) |
|
st.success('Prediction done successfully!', icon="✅") |
|
_=''' |
|
except Exception as e: |
|
if 'NoneType' or 'not defined' in str(e): |
|
st.warning('Enter the required inputs', icon="⚠️") |
|
else: |
|
st.warning(str(e), icon="⚠️") |
|
''' |
|
|
|
for i in range(30): |
|
st.markdown('##') |