Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -113,8 +113,21 @@ def summarize_text(text):
|
|
| 113 |
Returns:
|
| 114 |
Summarized text.
|
| 115 |
"""
|
| 116 |
-
|
| 117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
return summary
|
| 119 |
|
| 120 |
# 6. Code Generation
|
|
|
|
| 113 |
Returns:
|
| 114 |
Summarized text.
|
| 115 |
"""
|
| 116 |
+
# Load the summarization model
|
| 117 |
+
model_name = 'facebook/bart-large-cnn'
|
| 118 |
+
try:
|
| 119 |
+
summarizer = pipeline('summarization', model=model_name)
|
| 120 |
+
except EnvironmentError as e:
|
| 121 |
+
return f'Error loading model: {e}'
|
| 122 |
+
|
| 123 |
+
# Truncate input text to avoid exceeding the model's maximum length
|
| 124 |
+
max_input_length = 1024
|
| 125 |
+
inputs = text
|
| 126 |
+
if len(text) > max_input_length:
|
| 127 |
+
inputs = text[:max_input_length]
|
| 128 |
+
|
| 129 |
+
# Generate summary
|
| 130 |
+
summary = summarizer(inputs, max_length=100, min_length=30, do_sample=False)[0]['summary_text']
|
| 131 |
return summary
|
| 132 |
|
| 133 |
# 6. Code Generation
|