NarayanaMayya's picture
Update app.py
d3acf2f
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
#from stqdm import stqdm
import base64
#from tensorflow.keras.preprocessing.text import Tokenizer
#from tensorflow.keras.preprocessing.sequence import pad_sequences
import numpy as np
import json
import os
import re
import nltk
from nltk.corpus import words
nltk.download('words')
#from tensorflow.keras.models import load_model
#st.write("API examples - Dermatophagoides, Miconazole, neomycin,Iothalamate")
#background_image = sys.path[1]+"/streamlit_datafile_links/audience-1853662_960_720.jpg" # Path to your background image
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
)
#add_bg_from_local(background_image)
#@st.cache
st.header('Summarization')
def convert_df(df):
# IMPORTANT: Cache the conversion to prevent computation on every rerun
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', ))
#try:
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:
#torch.cuda.set_device(2)
tokenizer = AutoTokenizer.from_pretrained('allenai/PRIMERA-multinews')
model = LEDForConditionalGeneration.from_pretrained('allenai/PRIMERA-multinews')
#device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') # get the device
device = "cpu"
model.to(device) # move the model to the device
documents = text_data
# Tokenize and encode the documents
inputs = tokenizer(documents, return_tensors='pt', padding=True, truncation=True,max_length=1000000)
# Move the inputs to the device
inputs = inputs.to(device)
# Generate summaries
outputs = model.generate(**inputs,max_length=1000000)
# Decode the summaries
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('##')