Overthrow4232 commited on
Commit
8dd9a23
1 Parent(s): e3d85f1

Update app.py

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