Soumen commited on
Commit
0e1cb76
·
1 Parent(s): 1e3fbe3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -72
app.py CHANGED
@@ -39,7 +39,7 @@ API_URL1 = "https://api-inference.huggingface.co/models/Michael-Vptn/text-summar
39
  headers1 = {"Authorization": "Bearer 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"}
40
  API_URL2 = "https://api-inference.huggingface.co/models/gpt2"
41
  headers2 = {"Authorization": "Bearer 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"}
42
-
43
  def read_pdf(file):
44
  # images=pdf2image.convert_from_path(file)
45
  # # print(type(images))
@@ -93,76 +93,77 @@ def change_photo_state():
93
  message = st.text_input("Type your text here!")
94
  uploaded_photo = st.file_uploader("Upload your Images/PDF",type=['jpg','png','jpeg','pdf'], on_change=change_photo_state)
95
  camera_photo = st.camera_input("Capture a photo to summarize: ", 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
- 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
 
 
39
  headers1 = {"Authorization": "Bearer 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"}
40
  API_URL2 = "https://api-inference.huggingface.co/models/gpt2"
41
  headers2 = {"Authorization": "Bearer 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"}
42
+ #@st.cache
43
  def read_pdf(file):
44
  # images=pdf2image.convert_from_path(file)
45
  # # print(type(images))
 
93
  message = st.text_input("Type your text here!")
94
  uploaded_photo = st.file_uploader("Upload your Images/PDF",type=['jpg','png','jpeg','pdf'], on_change=change_photo_state)
95
  camera_photo = st.camera_input("Capture a photo to summarize: ", on_change=change_photo_state)
96
+ if st.checkbox("Summarization"):
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