Spaces:
Running
Running
File size: 1,835 Bytes
e2e57a3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
import gradio as gr
#from docx import Document
import re
def find_sequential_vowels (text):
"""
TODO: add nasalized vowels
"""
pattern = r'\b\w*([aeiou])(?!\1)([aeiou])\w*\b'
return re.findall(pattern, text, re.IGNORECASE)
def create_docx_and_html(text, docx_path, html_path):
words_to_bold = [word[0]+word[1] for word in find_sequential_vowels(text)]
doc = Document()
paragraph = doc.add_paragraph()
html_content = "<html><body><p>"
words = text.split()
for word in words:
if any(bold_word in word for bold_word in words_to_bold):
paragraph.add_run(word + " ").bold = True
html_content += "<b>" + word + "</b> "
else:
paragraph.add_run(word + " ")
html_content += word + " "
html_content += "</p></body></html>"
doc.save(docx_path)
with open(html_path, 'w') as html_file:
html_file.write(html_content)
return docx_path, html_path
def format_text(text):
words_to_bold = [word[0]+word[1] for word in find_sequential_vowels(text)]
words = text.split()
formatted_text = ""
for word in words:
if any(bold_word in word for bold_word in words_to_bold):
formatted_text += f"<b>{word}</b> "
else:
formatted_text += f"{word} "
return formatted_text
with gr.Blocks() as app:
gr.Markdown("## Sequential Vowels Highlighter")
with gr.Row():
text_input = gr.Textbox(lines=2, placeholder="Enter text here...")
submit_button = gr.Button("Put words with sequential vowels in bold")
output_html = gr.HTML()
submit_button.click(
fn=format_text,
inputs=text_input,
outputs=output_html
)
app.launch()
|