preprocessing / app.py
akki2825's picture
change fn
15a3e70 verified
raw
history blame
891 Bytes
import gradio as gr
def split_into_sentences(text, remove_whitespace):
sentences = text.split('\n')
if remove_whitespace:
sentences = [s.strip() for s in sentences if s.strip() != '']
return sentences
def main():
with gr.Blocks() as demo:
gr.Markdown("# Text to Sentences Splitter")
with gr.Row():
text_input = gr.Textbox(label="Enter or paste your text", lines=5)
whitespace_checkbox = gr.Checkbox(label="Remove extra whitespace", value=True)
with gr.Row():
split_button = gr.Button("Split into Sentences")
sentences_output = gr.Textbox(label="Sentences", lines=5)
split_button.click(
fn=split_into_sentences,
inputs=[text_input, whitespace_checkbox],
outputs=sentences_output
)
demo.launch()
if __name__ == "__main__":
main()