Update app.py
Browse files
app.py
CHANGED
|
@@ -74,7 +74,6 @@ def bansum(text):
|
|
| 74 |
st.title("NLP APPLICATION")
|
| 75 |
#@st.cache_resource(experimental_allow_widgets=True)
|
| 76 |
def main():
|
| 77 |
-
s=0
|
| 78 |
#global tokenizer, model
|
| 79 |
#tokenizer = AutoTokenizer.from_pretrained('t5-base')
|
| 80 |
#model = AutoModelWithLMHead.from_pretrained('t5-base', return_dict=True)
|
|
@@ -89,7 +88,7 @@ def main():
|
|
| 89 |
st.subheader("Please, feed your pdf/images/text, features/services will appear automatically!")
|
| 90 |
message = st.text_input("Type your text here!")
|
| 91 |
uploaded_photo = st.sidebar.file_uploader("Upload your Images/PDF",type=['jpg','png','jpeg','pdf'], on_change=change_photo_state)
|
| 92 |
-
camera_photo = st.camera_input("Take a photo, Containing English texts", on_change=change_photo_state)
|
| 93 |
if "photo" not in st.session_state:
|
| 94 |
st.session_state["photo"]="not done"
|
| 95 |
if st.session_state["photo"]=="done" or message:
|
|
@@ -102,7 +101,7 @@ def main():
|
|
| 102 |
#tet = pytesseract.image_to_string(img, lang="ben") if st.checkbox("Mark to see Bangla Image's Text") else pytesseract.image_to_string(img)
|
| 103 |
values = st.slider('Select a approximate number of lines to see and summarize',value=[0, len(tet)//(7*100)])
|
| 104 |
text = tet[values[0]*7*10:values[1]*7*10] if values[0]!=len(tet)//(7*10) else tet[len(tet)//(7*100):]
|
| 105 |
-
|
| 106 |
elif uploaded_photo:
|
| 107 |
img = Image.open(uploaded_photo)
|
| 108 |
img = img.save("img.png")
|
|
@@ -110,33 +109,29 @@ def main():
|
|
| 110 |
st.text("Press the content type:")
|
| 111 |
if st.button("Content Type: Bangla"):
|
| 112 |
text = pytesseract.image_to_string(img, lang="ben")
|
| 113 |
-
|
| 114 |
if st.button("Content Type: English"):
|
| 115 |
text=pytesseract.image_to_string(img)
|
| 116 |
-
|
| 117 |
#st.success(text)
|
| 118 |
elif camera_photo:
|
| 119 |
img = Image.open(camera_photo)
|
| 120 |
img = img.save("img.png")
|
| 121 |
img = cv2.imread("img.png")
|
| 122 |
#text = pytesseract.image_to_string(img) if st.checkbox("Bangla") else pytesseract.image_to_string(img, lang="ben")
|
| 123 |
-
st.text("Please select the content type:")
|
| 124 |
if st.button("Content Type: Bangla"):
|
| 125 |
text = pytesseract.image_to_string(img, lang="ben")
|
| 126 |
-
|
| 127 |
if st.button("Content Type: English"):
|
| 128 |
text=pytesseract.image_to_string(img)
|
| 129 |
-
|
| 130 |
-
st.success(text)
|
| 131 |
elif uploaded_photo==None and camera_photo==None:
|
| 132 |
text = message
|
| 133 |
-
|
| 134 |
-
if st.checkbox("Mark for Text Summarization"):
|
| 135 |
-
if s==1:
|
| 136 |
bansum(text)
|
| 137 |
-
|
| 138 |
-
engsum(text)
|
| 139 |
-
|
| 140 |
if st.checkbox("English Text Generation"):
|
| 141 |
def query(payload):
|
| 142 |
response = requests.post(API_URL2, headers=headers2, json=payload)
|
|
@@ -148,8 +143,7 @@ def main():
|
|
| 148 |
if isinstance(out, list) and out[0].get("generated_text"):
|
| 149 |
text_output = out[0]["generated_text"]
|
| 150 |
st.success(text_output)
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
s=0
|
| 154 |
if __name__ == '__main__':
|
| 155 |
main()
|
|
|
|
| 74 |
st.title("NLP APPLICATION")
|
| 75 |
#@st.cache_resource(experimental_allow_widgets=True)
|
| 76 |
def main():
|
|
|
|
| 77 |
#global tokenizer, model
|
| 78 |
#tokenizer = AutoTokenizer.from_pretrained('t5-base')
|
| 79 |
#model = AutoModelWithLMHead.from_pretrained('t5-base', return_dict=True)
|
|
|
|
| 88 |
st.subheader("Please, feed your pdf/images/text, features/services will appear automatically!")
|
| 89 |
message = st.text_input("Type your text here!")
|
| 90 |
uploaded_photo = st.sidebar.file_uploader("Upload your Images/PDF",type=['jpg','png','jpeg','pdf'], on_change=change_photo_state)
|
| 91 |
+
camera_photo = st.sidebar.camera_input("Take a photo, Containing English texts", on_change=change_photo_state)
|
| 92 |
if "photo" not in st.session_state:
|
| 93 |
st.session_state["photo"]="not done"
|
| 94 |
if st.session_state["photo"]=="done" or message:
|
|
|
|
| 101 |
#tet = pytesseract.image_to_string(img, lang="ben") if st.checkbox("Mark to see Bangla Image's Text") else pytesseract.image_to_string(img)
|
| 102 |
values = st.slider('Select a approximate number of lines to see and summarize',value=[0, len(tet)//(7*100)])
|
| 103 |
text = tet[values[0]*7*10:values[1]*7*10] if values[0]!=len(tet)//(7*10) else tet[len(tet)//(7*100):]
|
| 104 |
+
engsum(text)
|
| 105 |
elif uploaded_photo:
|
| 106 |
img = Image.open(uploaded_photo)
|
| 107 |
img = img.save("img.png")
|
|
|
|
| 109 |
st.text("Press the content type:")
|
| 110 |
if st.button("Content Type: Bangla"):
|
| 111 |
text = pytesseract.image_to_string(img, lang="ben")
|
| 112 |
+
bansum(text)
|
| 113 |
if st.button("Content Type: English"):
|
| 114 |
text=pytesseract.image_to_string(img)
|
| 115 |
+
engsum(text)
|
| 116 |
#st.success(text)
|
| 117 |
elif camera_photo:
|
| 118 |
img = Image.open(camera_photo)
|
| 119 |
img = img.save("img.png")
|
| 120 |
img = cv2.imread("img.png")
|
| 121 |
#text = pytesseract.image_to_string(img) if st.checkbox("Bangla") else pytesseract.image_to_string(img, lang="ben")
|
| 122 |
+
st.text("Please select the content type for summarization:")
|
| 123 |
if st.button("Content Type: Bangla"):
|
| 124 |
text = pytesseract.image_to_string(img, lang="ben")
|
| 125 |
+
bansum(text)
|
| 126 |
if st.button("Content Type: English"):
|
| 127 |
text=pytesseract.image_to_string(img)
|
| 128 |
+
engsum(text)
|
|
|
|
| 129 |
elif uploaded_photo==None and camera_photo==None:
|
| 130 |
text = message
|
| 131 |
+
if st.button("Content Type: Bangla"):
|
|
|
|
|
|
|
| 132 |
bansum(text)
|
| 133 |
+
if st.button("Content Type: English"):
|
| 134 |
+
engsum(text)
|
|
|
|
| 135 |
if st.checkbox("English Text Generation"):
|
| 136 |
def query(payload):
|
| 137 |
response = requests.post(API_URL2, headers=headers2, json=payload)
|
|
|
|
| 143 |
if isinstance(out, list) and out[0].get("generated_text"):
|
| 144 |
text_output = out[0]["generated_text"]
|
| 145 |
st.success(text_output)
|
| 146 |
+
#text=text_output
|
| 147 |
+
|
|
|
|
| 148 |
if __name__ == '__main__':
|
| 149 |
main()
|