Update app.py
Browse files
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.
|
97 |
-
if
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
st.
|
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 |
|
|
|
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 |
|