Spaces:
Runtime error
Runtime error
Overthrow4232
commited on
Commit
•
8dd9a23
1
Parent(s):
e3d85f1
Update app.py
Browse files
app.py
CHANGED
@@ -1,34 +1,37 @@
|
|
1 |
-
import spaces
|
2 |
-
import gradio as gr
|
3 |
-
from wtpsplit import SaT
|
4 |
-
|
5 |
-
|
6 |
-
#
|
7 |
-
#
|
8 |
-
|
9 |
-
sat
|
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 |
iface.launch()
|
|
|
1 |
+
import spaces
|
2 |
+
import gradio as gr
|
3 |
+
from wtpsplit import SaT
|
4 |
+
import json
|
5 |
+
|
6 |
+
# Initialize the SaT model
|
7 |
+
# We use 'sat-3l-sm' as it's recommended for general sentence segmentation tasks
|
8 |
+
# and offers a good balance between speed and performance
|
9 |
+
sat = SaT("sat-3l-sm")
|
10 |
+
sat.half().to("cuda")
|
11 |
+
|
12 |
+
@spaces.GPU
|
13 |
+
def segment_text(input_text):
|
14 |
+
# Use the SaT model to split the input text into sentences
|
15 |
+
sentences = sat.split(input_text)
|
16 |
+
|
17 |
+
# Create a JSON object where each sentence is a separate item
|
18 |
+
json_output = json.dumps({"segments": sentences}, indent=2)
|
19 |
+
|
20 |
+
return json_output
|
21 |
+
|
22 |
+
# Create the Gradio interface
|
23 |
+
iface = gr.Interface(
|
24 |
+
fn=segment_text,
|
25 |
+
inputs=gr.Textbox(lines=5, label="Input Text"),
|
26 |
+
outputs=gr.JSON(label="Segmented Text (JSON)"),
|
27 |
+
title="Text Segmentation with SaT",
|
28 |
+
description="This app uses the SaT (Segment any Text) model to split input text into sentences and return the result as JSON.",
|
29 |
+
examples=[
|
30 |
+
["This is a test This is another test."],
|
31 |
+
["Hello this is a test But this is different now Now the next one starts looool"],
|
32 |
+
["The quick brown fox jumps over the lazy dog It was the best of times, it was the worst of times"],
|
33 |
+
]
|
34 |
+
)
|
35 |
+
|
36 |
+
# Launch the app
|
37 |
iface.launch()
|