cnmoro commited on
Commit
117007f
1 Parent(s): f04bdab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -3
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()) > 700:
97
- return "Text is too long for this demo. Please provide a text with less than 700 words."
 
 
 
98
 
99
- compressed = semantic_compress_text(text, word_reduction_factor = 1 - word_reduction_factor)
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}%"