Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +31 -0
- requirements.txt +1 -0
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from wtpsplit import SaT
|
| 3 |
+
|
| 4 |
+
# Initialize the SaT model
|
| 5 |
+
# We use 'sat-3l-sm' as it's recommended for general sentence segmentation tasks
|
| 6 |
+
# and offers a good balance between speed and performance
|
| 7 |
+
sat = SaT("sat-3l-sm")
|
| 8 |
+
|
| 9 |
+
def segment_text(input_text):
|
| 10 |
+
# Use the SaT model to split the input text into sentences
|
| 11 |
+
sentences = sat.split(input_text)
|
| 12 |
+
|
| 13 |
+
# Join the sentences with newlines for better readability in the output
|
| 14 |
+
return "\n".join(sentences)
|
| 15 |
+
|
| 16 |
+
# Create the Gradio interface
|
| 17 |
+
iface = gr.Interface(
|
| 18 |
+
fn=segment_text,
|
| 19 |
+
inputs=gr.Textbox(lines=5, label="Input Text"),
|
| 20 |
+
outputs=gr.Textbox(lines=10, label="Segmented Text"),
|
| 21 |
+
title="Text Segmentation with SaT",
|
| 22 |
+
description="This app uses the SaT (Segment any Text) model to split input text into sentences.",
|
| 23 |
+
examples=[
|
| 24 |
+
["This is a test This is another test."],
|
| 25 |
+
["Hello this is a test But this is different now Now the next one starts looool"],
|
| 26 |
+
["The quick brown fox jumps over the lazy dog It was the best of times, it was the worst of times"],
|
| 27 |
+
]
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
# Launch the app
|
| 31 |
+
iface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
wtpsplit
|