Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,9 +2,8 @@ import streamlit as st
|
|
2 |
import PyPDF2
|
3 |
import io
|
4 |
import os
|
5 |
-
import re
|
6 |
|
7 |
-
|
8 |
unicodeatoz = ["ब", "द", "अ", "म", "भ", "ा", "न", "ज", "ष्", "व", "प", "ि", "फ", "ल", "य", "उ", "त्र", "च", "क", "त", "ग", "ख", "ध", "ह", "थ", "श"]
|
9 |
unicodeAtoZ = ["ब्", "ध", "ऋ", "म्", "भ्", "ँ", "न्", "ज्", "क्ष्", "व्", "प्", "ी", "ः", "ल्", "इ", "ए", "त्त", "च्", "क्", "त्", "ग्", "ख्", "ध्", "ह्", "थ्", "श्"]
|
10 |
unicode0to9 = ["ण्", "ज्ञ", "द्द", "घ", "द्ध", "छ", "ट", "ठ", "ड", "ढ"]
|
@@ -47,25 +46,40 @@ symbolsDict = {
|
|
47 |
"÷": "/"
|
48 |
}
|
49 |
|
50 |
-
# Add normalization to handle conjunct consonants
|
51 |
def normalizePreeti(preetitxt):
|
52 |
-
|
53 |
-
|
54 |
-
preetitxt =
|
55 |
-
preetitxt =
|
56 |
-
preetitxt =
|
57 |
-
preetitxt =
|
58 |
-
preetitxt =
|
59 |
-
preetitxt =
|
60 |
-
preetitxt =
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
def convert(preeti):
|
71 |
converted = ''
|
@@ -87,13 +101,10 @@ def convert(preeti):
|
|
87 |
|
88 |
def extract_text_from_pdf(pdf_file):
|
89 |
text = ''
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
text += page.extract_text()
|
95 |
-
except Exception as e:
|
96 |
-
text = f"Error extracting text: {e}"
|
97 |
return text
|
98 |
|
99 |
def process_file(inputfile):
|
@@ -101,12 +112,12 @@ def process_file(inputfile):
|
|
101 |
if ext == '.pdf':
|
102 |
preeti = extract_text_from_pdf(inputfile)
|
103 |
else:
|
104 |
-
with open(inputfile, "r"
|
105 |
preeti = fp.read()
|
106 |
return convert(preeti)
|
107 |
|
108 |
def main():
|
109 |
-
st.title("
|
110 |
|
111 |
uploaded_file = st.file_uploader("Choose a PDF or TXT file", type=["pdf", "txt"])
|
112 |
|
@@ -138,4 +149,4 @@ def main():
|
|
138 |
)
|
139 |
|
140 |
if __name__ == "__main__":
|
141 |
-
main()
|
|
|
2 |
import PyPDF2
|
3 |
import io
|
4 |
import os
|
|
|
5 |
|
6 |
+
|
7 |
unicodeatoz = ["ब", "द", "अ", "म", "भ", "ा", "न", "ज", "ष्", "व", "प", "ि", "फ", "ल", "य", "उ", "त्र", "च", "क", "त", "ग", "ख", "ध", "ह", "थ", "श"]
|
8 |
unicodeAtoZ = ["ब्", "ध", "ऋ", "म्", "भ्", "ँ", "न्", "ज्", "क्ष्", "व्", "प्", "ी", "ः", "ल्", "इ", "ए", "त्त", "च्", "क्", "त्", "ग्", "ख्", "ध्", "ह्", "थ्", "श्"]
|
9 |
unicode0to9 = ["ण्", "ज्ञ", "द्द", "घ", "द्ध", "छ", "ट", "ठ", "ड", "ढ"]
|
|
|
46 |
"÷": "/"
|
47 |
}
|
48 |
|
|
|
49 |
def normalizePreeti(preetitxt):
|
50 |
+
normalized = ''
|
51 |
+
previoussymbol = ''
|
52 |
+
preetitxt = preetitxt.replace('qm', 's|')
|
53 |
+
preetitxt = preetitxt.replace('f]', 'ो')
|
54 |
+
preetitxt = preetitxt.replace('km', 'फ')
|
55 |
+
preetitxt = preetitxt.replace('0f', 'ण')
|
56 |
+
preetitxt = preetitxt.replace('If', 'क्ष')
|
57 |
+
preetitxt = preetitxt.replace('if', 'ष')
|
58 |
+
preetitxt = preetitxt.replace('cf', 'आ')
|
59 |
+
index = -1
|
60 |
+
while index + 1 < len(preetitxt):
|
61 |
+
index += 1
|
62 |
+
character = preetitxt[index]
|
63 |
+
try:
|
64 |
+
if preetitxt[index + 2] == '{':
|
65 |
+
if preetitxt[index + 1] == 'f' or preetitxt[index + 1] == 'ो':
|
66 |
+
normalized += '{' + character + preetitxt[index + 1]
|
67 |
+
index += 2
|
68 |
+
continue
|
69 |
+
if preetitxt[index + 1] == '{':
|
70 |
+
if character != 'f':
|
71 |
+
normalized += '{' + character
|
72 |
+
index += 1
|
73 |
+
continue
|
74 |
+
except IndexError:
|
75 |
+
pass
|
76 |
+
if character == 'l':
|
77 |
+
previoussymbol = 'l'
|
78 |
+
continue
|
79 |
+
else:
|
80 |
+
normalized += character + previoussymbol
|
81 |
+
previoussymbol = ''
|
82 |
+
return normalized
|
83 |
|
84 |
def convert(preeti):
|
85 |
converted = ''
|
|
|
101 |
|
102 |
def extract_text_from_pdf(pdf_file):
|
103 |
text = ''
|
104 |
+
with open(pdf_file, 'rb') as file:
|
105 |
+
reader = PyPDF2.PdfReader(file)
|
106 |
+
for page in reader.pages:
|
107 |
+
text += page.extract_text()
|
|
|
|
|
|
|
108 |
return text
|
109 |
|
110 |
def process_file(inputfile):
|
|
|
112 |
if ext == '.pdf':
|
113 |
preeti = extract_text_from_pdf(inputfile)
|
114 |
else:
|
115 |
+
with open(inputfile, "r") as fp:
|
116 |
preeti = fp.read()
|
117 |
return convert(preeti)
|
118 |
|
119 |
def main():
|
120 |
+
st.title("PDF/TXT to Unicode Converter")
|
121 |
|
122 |
uploaded_file = st.file_uploader("Choose a PDF or TXT file", type=["pdf", "txt"])
|
123 |
|
|
|
149 |
)
|
150 |
|
151 |
if __name__ == "__main__":
|
152 |
+
main()
|