micahg's picture
file dnd fix; line output fix; vowel handling
e2e57a3
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()