akki2825 commited on
Commit
15a3e70
·
verified ·
1 Parent(s): 522fb71
Files changed (1) hide show
  1. app.py +14 -25
app.py CHANGED
@@ -1,38 +1,27 @@
1
  import gradio as gr
2
 
3
- def add_line_breaks(file, position):
4
- try:
5
- # Read the text from the uploaded file
6
- text = file.read()
7
-
8
- # Ensure position is within valid range
9
- position = max(0, min(position, len(text)))
10
-
11
- # Insert \n at the specified position
12
- modified_text = text[:position] + "\n" + text[position:]
13
-
14
- return modified_text
15
- except Exception as e:
16
- return f"Error: {str(e)}"
17
 
18
  def main():
19
  with gr.Blocks() as demo:
20
- gr.Markdown("# Text Line Break Adder")
21
 
22
  with gr.Row():
23
- file_input = gr.File(label="Upload Text File", placeholder="Select a .txt file")
24
- position_input = gr.Number(label="Position to Insert Line Break",
25
- placeholder="Enter position (0-based index)",
26
- value=0)
27
 
28
  with gr.Row():
29
- add_button = gr.Button("Add Line Break")
30
- text_output = gr.Textbox(label="Modified Text", lines=10)
31
 
32
- add_button.click(
33
- fn=add_line_breaks,
34
- inputs=[file_input, position_input],
35
- outputs=text_output
36
  )
37
 
38
  demo.launch()
 
1
  import gradio as gr
2
 
3
+ def split_into_sentences(text, remove_whitespace):
4
+ sentences = text.split('\n')
5
+ if remove_whitespace:
6
+ sentences = [s.strip() for s in sentences if s.strip() != '']
7
+ return sentences
 
 
 
 
 
 
 
 
 
8
 
9
  def main():
10
  with gr.Blocks() as demo:
11
+ gr.Markdown("# Text to Sentences Splitter")
12
 
13
  with gr.Row():
14
+ text_input = gr.Textbox(label="Enter or paste your text", lines=5)
15
+ whitespace_checkbox = gr.Checkbox(label="Remove extra whitespace", value=True)
 
 
16
 
17
  with gr.Row():
18
+ split_button = gr.Button("Split into Sentences")
19
+ sentences_output = gr.Textbox(label="Sentences", lines=5)
20
 
21
+ split_button.click(
22
+ fn=split_into_sentences,
23
+ inputs=[text_input, whitespace_checkbox],
24
+ outputs=sentences_output
25
  )
26
 
27
  demo.launch()