-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
61 lines (50 loc) · 1.96 KB
/
app.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import streamlit as st
from txtai.pipeline import Summary, Textractor
from PyPDF2 import PdfReader
st.set_page_config(layout="wide")
@st.cache_resource
def text_summary(text, maxlength=None):
#create summary instance
summary = Summary()
text = (text)
result = summary(text)
return result
def extract_text_from_pdf(file_path):
# Open the PDF file using PyPDF2
with open(file_path, "rb") as f:
reader = PdfReader(f)
page = reader.pages[0]
text = page.extract_text()
return text
choice = st.sidebar.selectbox("Select your choice", ["Simplify Document", "Simplify Text"])
if choice == "Simplify Document":
st.subheader("Summarize Your Legal Documents")
input_file = st.file_uploader("Upload your document here", type=['pdf'])
if input_file is not None:
if st.button("Summarize"):
with open("doc_file.pdf", "wb") as f:
f.write(input_file.getbuffer())
col1, col2 = st.columns([1,1])
with col1:
st.info("File uploaded successfully")
extracted_text = extract_text_from_pdf("doc_file.pdf")
st.markdown("**Extracted Text is Below:**")
st.info(extracted_text)
with col2:
st.markdown("**Summary Result**")
text = extract_text_from_pdf("doc_file.pdf")
doc_summary = text_summary(text)
st.success(doc_summary)
elif choice == "Simplify Text":
st.subheader("Enter Judgement to be simplified.")
input_text = st.text_area("Enter your text here")
if input_text is not None:
if st.button("Simplify"):
col1, col2 = st.columns([1,1])
with col1:
st.markdown("**Your Input Text**")
st.info(input_text)
with col2:
st.markdown("**Summary Result**")
result = text_summary(input_text)
st.success(result)