File size: 1,398 Bytes
e96bf82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
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()