Soumen commited on
Commit
9d1426d
1 Parent(s): 12bc8bb

Update app.py

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