Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -93,10 +93,13 @@ def semantic_compress_text(full_text, compression_rate=0.7, num_topics=5):
|
|
93 |
|
94 |
|
95 |
async def predict(text, word_reduction_factor):
|
96 |
-
if len(text.split()) >
|
97 |
-
return "Text is too long for this demo. Please provide a text with less than
|
|
|
|
|
|
|
98 |
|
99 |
-
compressed = semantic_compress_text(text,
|
100 |
perc_reduction = round(100 - (count_tokens_tiktoken(compressed) / count_tokens_tiktoken(text)) * 100, 2)
|
101 |
|
102 |
return f"{compressed}\n\nToken Reduction: {perc_reduction}%"
|
|
|
93 |
|
94 |
|
95 |
async def predict(text, word_reduction_factor):
|
96 |
+
if len(text.split()) > 5000:
|
97 |
+
return "Text is too long for this demo. Please provide a text with less than 5000 words."
|
98 |
+
|
99 |
+
if word_reduction_factor is None:
|
100 |
+
word_reduction_factor = 0.5
|
101 |
|
102 |
+
compressed = semantic_compress_text(text, compression_rate= 1 - word_reduction_factor)
|
103 |
perc_reduction = round(100 - (count_tokens_tiktoken(compressed) / count_tokens_tiktoken(text)) * 100, 2)
|
104 |
|
105 |
return f"{compressed}\n\nToken Reduction: {perc_reduction}%"
|