Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,8 +7,13 @@ device = 0 if torch.cuda.is_available() else -1
|
|
| 7 |
text_summary = pipeline("summarization", model="Falconsai/text_summarization", device=device, torch_dtype=torch.bfloat16)
|
| 8 |
|
| 9 |
def summary(input):
|
| 10 |
-
#
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
return output[0]['summary_text']
|
| 13 |
|
| 14 |
gr.close_all()
|
|
@@ -24,3 +29,4 @@ demo = gr.Interface(
|
|
| 24 |
|
| 25 |
demo.launch()
|
| 26 |
|
|
|
|
|
|
| 7 |
text_summary = pipeline("summarization", model="Falconsai/text_summarization", device=device, torch_dtype=torch.bfloat16)
|
| 8 |
|
| 9 |
def summary(input):
|
| 10 |
+
# Calculate the number of tokens based on input length
|
| 11 |
+
input_length = len(input.split())
|
| 12 |
+
max_output_tokens = max(20, input_length // 2) # Ensure output is less than half of the input
|
| 13 |
+
min_output_tokens = max(10, input_length // 4) # Ensure a meaningful summary
|
| 14 |
+
|
| 15 |
+
# Generate summary with dynamic token limits
|
| 16 |
+
output = text_summary(input, max_length=max_output_tokens, min_length=min_output_tokens, truncation=True)
|
| 17 |
return output[0]['summary_text']
|
| 18 |
|
| 19 |
gr.close_all()
|
|
|
|
| 29 |
|
| 30 |
demo.launch()
|
| 31 |
|
| 32 |
+
|