Spaces:
Sleeping
Sleeping
change fn
Browse files
app.py
CHANGED
|
@@ -1,38 +1,27 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
def
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 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
|
| 21 |
|
| 22 |
with gr.Row():
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
placeholder="Enter position (0-based index)",
|
| 26 |
-
value=0)
|
| 27 |
|
| 28 |
with gr.Row():
|
| 29 |
-
|
| 30 |
-
|
| 31 |
|
| 32 |
-
|
| 33 |
-
fn=
|
| 34 |
-
inputs=[
|
| 35 |
-
outputs=
|
| 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()
|