Spaces:
Runtime error
Runtime error
Overthrow4232
commited on
Commit
•
b71a375
1
Parent(s):
f838b34
Update app.py
Browse files
app.py
CHANGED
@@ -17,11 +17,14 @@ def segment_text(input_text, multi_doc_input):
|
|
17 |
results["input_text"] = {"segments": sentences}
|
18 |
|
19 |
if multi_doc_input:
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
25 |
|
26 |
# Create a JSON object with the results
|
27 |
json_output = json.dumps(results, indent=2)
|
@@ -33,16 +36,16 @@ iface = gr.Interface(
|
|
33 |
fn=segment_text,
|
34 |
inputs=[
|
35 |
gr.Textbox(lines=5, label="Input Text (Optional)"),
|
36 |
-
gr.Textbox(lines=10, label="Multiple Documents (Optional,
|
37 |
],
|
38 |
outputs=gr.JSON(label="Segmented Text (JSON)"),
|
39 |
title="Text Segmentation with SaT",
|
40 |
-
description="This app uses the SaT (Segment any Text) model to split input text into sentences and return the result as JSON. You can input text directly or provide multiple documents
|
41 |
examples=[
|
42 |
["This is a test This is another test.", ""],
|
43 |
["Hello this is a test But this is different now Now the next one starts looool", ""],
|
44 |
["The quick brown fox jumps over the lazy dog It was the best of times, it was the worst of times", ""],
|
45 |
-
["", "Document 1 first sentence Document 1 second sentence
|
46 |
]
|
47 |
)
|
48 |
|
|
|
17 |
results["input_text"] = {"segments": sentences}
|
18 |
|
19 |
if multi_doc_input:
|
20 |
+
try:
|
21 |
+
# Parse the JSON input
|
22 |
+
documents = json.loads(multi_doc_input)
|
23 |
+
for key, doc in documents.items():
|
24 |
+
sentences = sat.split(doc)
|
25 |
+
results[f"doc_{key}"] = {"segments": sentences}
|
26 |
+
except json.JSONDecodeError:
|
27 |
+
results["error"] = "Invalid JSON input for multiple documents"
|
28 |
|
29 |
# Create a JSON object with the results
|
30 |
json_output = json.dumps(results, indent=2)
|
|
|
36 |
fn=segment_text,
|
37 |
inputs=[
|
38 |
gr.Textbox(lines=5, label="Input Text (Optional)"),
|
39 |
+
gr.Textbox(lines=10, label="Multiple Documents JSON (Optional)", placeholder='{"1": "Document 1 text", "2": "Document 2 text"}')
|
40 |
],
|
41 |
outputs=gr.JSON(label="Segmented Text (JSON)"),
|
42 |
title="Text Segmentation with SaT",
|
43 |
+
description="This app uses the SaT (Segment any Text) model to split input text into sentences and return the result as JSON. You can input text directly or provide multiple documents as JSON. All credits to the respective author(s). Github: https://github.com/segment-any-text/wtpsplit/tree/main",
|
44 |
examples=[
|
45 |
["This is a test This is another test.", ""],
|
46 |
["Hello this is a test But this is different now Now the next one starts looool", ""],
|
47 |
["The quick brown fox jumps over the lazy dog It was the best of times, it was the worst of times", ""],
|
48 |
+
["", '{"1": "Document 1 first sentence Document 1 second sentence", "2": "Document 2 only sentence", "3": "Document 3 first Document 3 second"}']
|
49 |
]
|
50 |
)
|
51 |
|