Update app.py
Browse files
app.py
CHANGED
@@ -82,89 +82,87 @@ def bansum(text):
|
|
82 |
text_output = out[0]["summary_text"]
|
83 |
st.success(text_output)
|
84 |
|
85 |
-
st.title("Bangla and English Summarizer:")
|
86 |
#st.subheader("Input texts to summarize: ")
|
87 |
#@st.cache_resource(experimental_allow_widgets=True)
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
if
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
|
169 |
-
if __name__ == '__main__':
|
170 |
-
main()
|
|
|
82 |
text_output = out[0]["summary_text"]
|
83 |
st.success(text_output)
|
84 |
|
85 |
+
st.title("Bangla and English Summarizer: Upload Images/Pdf or input texts to summarize!")
|
86 |
#st.subheader("Input texts to summarize: ")
|
87 |
#@st.cache_resource(experimental_allow_widgets=True)
|
88 |
+
""" NLP Based Application with Streamlit """
|
89 |
+
def change_photo_state():
|
90 |
+
st.session_state["photo"]="done"
|
91 |
+
message = st.sidebar.text_input("Type your text here!")
|
92 |
+
uploaded_photo = st.sidebar.file_uploader("Upload your Images/PDF",type=['jpg','png','jpeg','pdf'], on_change=change_photo_state)
|
93 |
+
camera_photo = st.sidebar.camera_input("Capture a photo to summarize: ", on_change=change_photo_state)
|
94 |
+
if "photo" not in st.session_state:
|
95 |
+
st.session_state["photo"]="not done"
|
96 |
+
if st.session_state["photo"]=="done" or message:
|
97 |
+
if uploaded_photo and uploaded_photo.type=='application/pdf':
|
98 |
+
tet = read_pdf(uploaded_photo)
|
99 |
+
# with tempfile.NamedTemporaryFile(delete=False) as temp_file:
|
100 |
+
# temp_file.write(uploaded_photo.read())
|
101 |
+
# temp_file_path = temp_file.name
|
102 |
+
|
103 |
+
# loader = PyPDFLoader(temp_file_path)
|
104 |
+
# if loader:
|
105 |
+
# text.extend(loader.load())
|
106 |
+
# os.remove(temp_file_path)
|
107 |
+
# text_splitter = CharacterTextSplitter(separator="\n", chunk_size=1000, chunk_overlap=100, length_function=len)
|
108 |
+
# text_chunks = text_splitter.split_documents(text)
|
109 |
+
values = st.slider('Select a approximate number of lines to see and summarize',value=[0, len(tet)//(7*100)])
|
110 |
+
text = tet[values[0]*7*10:values[1]*10*100] if values[0]!=len(tet)//(10*100) else tet[len(tet)//(10*100):]
|
111 |
+
#st.success(type(text_chunks))
|
112 |
+
if st.button("English Pdf Summarize"):
|
113 |
+
st.subheader("Selected text for summarize: ")
|
114 |
+
st.success(text)
|
115 |
+
st.subheader("Summarized Text: ")
|
116 |
+
engsum(text)
|
117 |
+
|
118 |
+
elif uploaded_photo and uploaded_photo.type !='application/pdf':
|
119 |
+
text=None
|
120 |
+
img = Image.open(uploaded_photo)
|
121 |
+
img = img.save("img.png")
|
122 |
+
img = cv2.imread("img.png")
|
123 |
+
st.text("Select the summarization type:")
|
124 |
+
if st.button("BENGALI"):
|
125 |
+
text = pytesseract.image_to_string(img, lang="ben")
|
126 |
+
st.subheader("সারাংশ/সারমর্ম")
|
127 |
+
bansum(text)
|
128 |
+
if st.button("ENGLISH"):
|
129 |
+
text=pytesseract.image_to_string(img)
|
130 |
+
st.subheader("Summarized Text")
|
131 |
+
engsum(text)
|
132 |
+
#st.success(text)
|
133 |
+
elif camera_photo:
|
134 |
+
text=None
|
135 |
+
img = Image.open(camera_photo)
|
136 |
+
img = img.save("img.png")
|
137 |
+
img = cv2.imread("img.png")
|
138 |
+
#text = pytesseract.image_to_string(img) if st.checkbox("Bangla") else pytesseract.image_to_string(img, lang="ben")
|
139 |
+
st.text("Select the summarization type:")
|
140 |
+
if st.button("Bangla"):
|
141 |
+
text = pytesseract.image_to_string(img, lang="ben")
|
142 |
+
st.subheader("সারাংশ/সারমর্ম")
|
143 |
+
bansum(text)
|
144 |
+
if st.button("English"):
|
145 |
+
text=pytesseract.image_to_string(img)
|
146 |
+
st.subheader("Summarized Text")
|
147 |
+
engsum(text)
|
148 |
+
else:
|
149 |
+
text=None
|
150 |
+
text = message
|
151 |
+
if st.button("Bangla"):
|
152 |
+
bansum(text)
|
153 |
+
if st.button("English"):
|
154 |
+
engsum(text)
|
155 |
+
# if st.button("English Text Generation"):
|
156 |
+
# def query(payload):
|
157 |
+
# response = requests.post(API_URL2, headers=headers2, json=payload)
|
158 |
+
# return response.json()
|
159 |
+
|
160 |
+
# out = query({
|
161 |
+
# "inputs": text,
|
162 |
+
# })
|
163 |
+
# if isinstance(out, list) and out[0].get("generated_text"):
|
164 |
+
# text_output = out[0]["generated_text"]
|
165 |
+
# st.success(text_output)
|
166 |
+
# #text=text_output
|
167 |
+
|
168 |
|
|
|
|