| """ | |
| my daughter has dyslexia and homework is really hard for her. | |
| i built this to break words into pieces so she can sound them out. | |
| first time using gradio, sorry if this is messy. | |
| """ | |
| import gradio as gr | |
| import pyphen | |
| dic = pyphen.Pyphen(lang="en_US") | |
| def break_it_up(text): | |
| if not text: | |
| return "paste something above" | |
| words = text.split() | |
| result = [] | |
| for word in words: | |
| # get just the letters | |
| clean = ''.join(c for c in word if c.isalpha()) | |
| if not clean: | |
| result.append(word) | |
| continue | |
| # break into syllables | |
| broken = dic.inserted(clean) | |
| # put the punctuation back | |
| if word[-1] in '.,!?;:': | |
| broken += word[-1] | |
| result.append(broken) | |
| return ' '.join(result) | |
| demo = gr.Interface( | |
| fn=break_it_up, | |
| inputs=gr.Textbox(label="paste homework here", lines=5, placeholder="paste the paragraph thats hard to read..."), | |
| outputs=gr.Textbox(label="broken into pieces", lines=5), | |
| title="homework helper", | |
| description="breaks words into syllables so my kid can sound them out. its not fancy but it works.", | |
| examples=[ | |
| ["Photosynthesis is the process by which green plants use sunlight to make food."], | |
| ["The mitochondria is the powerhouse of the cell."], | |
| ], | |
| allow_flagging="never", | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |