Update app.py
Browse files
app.py
CHANGED
@@ -113,6 +113,39 @@ def features(sentence, index):
|
|
113 |
}
|
114 |
|
115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
# Define the function for processing user input
|
117 |
def process_text(text_input):
|
118 |
if text_input:
|
@@ -141,7 +174,7 @@ def process_text(text_input):
|
|
141 |
return "Please enter some text."
|
142 |
|
143 |
def main():
|
144 |
-
st.title("Model Output with Streamlit")
|
145 |
|
146 |
# Text input
|
147 |
input_text = st.text_input("Enter your text:")
|
@@ -149,8 +182,14 @@ def main():
|
|
149 |
# Process the text when a button is clicked
|
150 |
if st.button("Process"):
|
151 |
output = process_text(input_text)
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
st.write("Model Output:")
|
153 |
-
st.write(
|
154 |
|
155 |
if __name__ == "__main__":
|
156 |
main()
|
|
|
113 |
}
|
114 |
|
115 |
|
116 |
+
def prepare_text(text):
|
117 |
+
# Define regular expression pattern to match symbols and punctuation from any language
|
118 |
+
symbol_pattern = r'([^\w\s\d])' # Capture non-word, non-space, non-digit characters
|
119 |
+
prepared_text = re.sub(symbol_pattern, r' \1 ', text)
|
120 |
+
prepared_text = re.sub(r'\s+', ' ', prepared_text)
|
121 |
+
|
122 |
+
return prepared_text.strip() # Remove leading and trailing spaces
|
123 |
+
|
124 |
+
|
125 |
+
|
126 |
+
def rebuildxx(ww, xres):
|
127 |
+
numprfx = xres.count('p')
|
128 |
+
numsufx = xres.count('f')
|
129 |
+
resfinal = ''
|
130 |
+
if numprfx != 0 and numsufx != 0 :
|
131 |
+
resfinal = "{}+{}+{}".format(ww[:numprfx] , ww[numprfx:-numsufx] , ww[-numsufx:] )
|
132 |
+
if numprfx == 0 and numsufx == 0 :
|
133 |
+
#resfinal = "{}+{}+{}".format("", ww , "" )
|
134 |
+
resfinal = "{}".format(ww )
|
135 |
+
|
136 |
+
if numprfx == 0 and numsufx != 0 :
|
137 |
+
#resfinal = "{}+{}+{}".format("" , ww[:-numsufx], ww[-numsufx:] )
|
138 |
+
resfinal = "{}+{}".format(ww[:-numsufx], ww[-numsufx:] )
|
139 |
+
|
140 |
+
if numprfx != 0 and numsufx == 0 :
|
141 |
+
#resfinal = "{}+{}+{}".format(ww[:numprfx] , ww[numprfx:], "")
|
142 |
+
resfinal = "{}+{}".format(ww[:numprfx] , ww[numprfx:])
|
143 |
+
|
144 |
+
return resfinal
|
145 |
+
|
146 |
+
|
147 |
+
|
148 |
+
|
149 |
# Define the function for processing user input
|
150 |
def process_text(text_input):
|
151 |
if text_input:
|
|
|
174 |
return "Please enter some text."
|
175 |
|
176 |
def main():
|
177 |
+
st.title("Arabic segmintation Model Output with Streamlit")
|
178 |
|
179 |
# Text input
|
180 |
input_text = st.text_input("Enter your text:")
|
|
|
182 |
# Process the text when a button is clicked
|
183 |
if st.button("Process"):
|
184 |
output = process_text(input_text)
|
185 |
+
gg = word_tokenize(prepare_text(input_text)))
|
186 |
+
cc = ""
|
187 |
+
for x, y in zip(gg, output):
|
188 |
+
cc += rebuildxx(x, y) + " "
|
189 |
+
|
190 |
+
#print(cc)
|
191 |
st.write("Model Output:")
|
192 |
+
st.write(cc)
|
193 |
|
194 |
if __name__ == "__main__":
|
195 |
main()
|