Soumen commited on
Commit
2dffa73
1 Parent(s): b7bf044

Update app.py

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