Commit
·
20be358
1
Parent(s):
9500b17
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,17 +12,11 @@ model = st.sidebar.selectbox("Choose a model", models)
|
|
| 12 |
|
| 13 |
uploaded_file = st.file_uploader("Choose a .txt file", type="txt")
|
| 14 |
|
|
|
|
|
|
|
|
|
|
| 15 |
if uploaded_file is not None:
|
| 16 |
user_input = uploaded_file.read().decode('utf-8')
|
| 17 |
-
total_length = len(user_input.split())
|
| 18 |
-
|
| 19 |
-
# Add slider to the sidebar for the scale value
|
| 20 |
-
scale_percentage = st.sidebar.slider('Scale %', min_value=1, max_value=100, value=50)
|
| 21 |
-
min_length_percentage = max(scale_percentage - 10, 1) # Ensure min_length_percentage is not less than 1
|
| 22 |
-
max_length_percentage = min(scale_percentage + 10, 100) # Ensure max_length_percentage is not more than 100
|
| 23 |
-
|
| 24 |
-
st.sidebar.text(f'Minimum Length %: {min_length_percentage}')
|
| 25 |
-
st.sidebar.text(f'Maximum Length %: {max_length_percentage}')
|
| 26 |
|
| 27 |
if st.button('Summarize'):
|
| 28 |
summarizer = pipeline('summarization', model=model)
|
|
@@ -33,8 +27,11 @@ if uploaded_file is not None:
|
|
| 33 |
|
| 34 |
# Summarize each chunk
|
| 35 |
for chunk in chunks:
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
| 38 |
summarized = summarizer(chunk, max_length=max_length, min_length=min_length, do_sample=False)
|
| 39 |
summarized_text += summarized[0]['summary_text'] + " "
|
| 40 |
|
|
|
|
| 12 |
|
| 13 |
uploaded_file = st.file_uploader("Choose a .txt file", type="txt")
|
| 14 |
|
| 15 |
+
# Add slider to the sidebar for the scale value
|
| 16 |
+
scale_percentage = st.sidebar.slider('Scale %', min_value=1, max_value=100, value=50)
|
| 17 |
+
|
| 18 |
if uploaded_file is not None:
|
| 19 |
user_input = uploaded_file.read().decode('utf-8')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
if st.button('Summarize'):
|
| 22 |
summarizer = pipeline('summarization', model=model)
|
|
|
|
| 27 |
|
| 28 |
# Summarize each chunk
|
| 29 |
for chunk in chunks:
|
| 30 |
+
chunk_length = len(chunk.split())
|
| 31 |
+
min_length_percentage = max(scale_percentage - 10, 1) # Ensure min_length_percentage is not less than 1
|
| 32 |
+
max_length_percentage = min(scale_percentage + 10, 100) # Ensure max_length_percentage is not more than 100
|
| 33 |
+
min_length = max(int(chunk_length * min_length_percentage / 100), 1) # Calculate min_length based on the percentage of the chunk length
|
| 34 |
+
max_length = int(chunk_length * max_length_percentage / 100) # Calculate max_length based on the percentage of the chunk length
|
| 35 |
summarized = summarizer(chunk, max_length=max_length, min_length=min_length, do_sample=False)
|
| 36 |
summarized_text += summarized[0]['summary_text'] + " "
|
| 37 |
|