Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,12 @@ import torch
|
|
5 |
# Load the text-to-text generation pipeline
|
6 |
pipe = pipeline("text2text-generation", model="samanjoy2/bnpunct_banglat5_seq2seq_finetuned", device='cpu')
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
st.title("Bangla Punctutation Restoration 🔨")
|
9 |
st.header("Input in Bengali text and get corrected output with proper punctuation marks [। , ?]")
|
10 |
|
@@ -17,9 +23,9 @@ if st.button("Restore Punctuations"):
|
|
17 |
input_text = input_text.replace('।', '').replace(',', '').replace('?', '')
|
18 |
# Generate text using the pipeline
|
19 |
generated_text = pipe(input_text, max_length=512, batch_size=1)[0]['generated_text']
|
20 |
-
|
21 |
# Display the generated text
|
22 |
st.subheader("Restored Text:")
|
23 |
-
st.write(generated_text)
|
24 |
else:
|
25 |
st.warning("Please enter text for restoration.")
|
|
|
5 |
# Load the text-to-text generation pipeline
|
6 |
pipe = pipeline("text2text-generation", model="samanjoy2/bnpunct_banglat5_seq2seq_finetuned", device='cpu')
|
7 |
|
8 |
+
|
9 |
+
def highlight_punctuation(text, punctuation_marks):
|
10 |
+
punctuation_pattern = '|'.join(map(re.escape, punctuation_marks))
|
11 |
+
highlighted_text = re.sub(f'({punctuation_pattern})', r'<span style="color: green;">\1</span>', text)
|
12 |
+
return highlighted_text
|
13 |
+
|
14 |
st.title("Bangla Punctutation Restoration 🔨")
|
15 |
st.header("Input in Bengali text and get corrected output with proper punctuation marks [। , ?]")
|
16 |
|
|
|
23 |
input_text = input_text.replace('।', '').replace(',', '').replace('?', '')
|
24 |
# Generate text using the pipeline
|
25 |
generated_text = pipe(input_text, max_length=512, batch_size=1)[0]['generated_text']
|
26 |
+
generated_text = highlight_punctuation(generated_text, ["।", ",", "?"])
|
27 |
# Display the generated text
|
28 |
st.subheader("Restored Text:")
|
29 |
+
st.write(generated_text, unsafe_allow_html=True)
|
30 |
else:
|
31 |
st.warning("Please enter text for restoration.")
|