psyrishi commited on
Commit
4292030
·
verified ·
1 Parent(s): 6f2fff4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -10
app.py CHANGED
@@ -3,12 +3,16 @@ import torch
3
  import os
4
  import chardet
5
  import time
6
- from core.summarizer import NarrativeSummarizer # <-- Import the core logic
7
 
8
  # Models available
9
  MODEL_OPTIONS = [
10
  "facebook/bart-large-cnn",
 
 
11
  "google/long-t5-local-base",
 
 
12
  "mistralai/Mistral-7B-v0.1"
13
  ]
14
 
@@ -20,7 +24,7 @@ PROMPT_OPTIONS = [
20
  "Custom Prompt"
21
  ]
22
 
23
- def run_app(file_obj, text_input, model_name, local_model_path, prompt_type, custom_prompt_text, iterations, batch_size, target_word_count, progress=gr.Progress()):
24
  start_time = time.time()
25
 
26
  # Check if custom prompt is selected but not provided
@@ -73,8 +77,7 @@ def run_app(file_obj, text_input, model_name, local_model_path, prompt_type, cus
73
  batch_summaries = summarizer.summarize_batch(
74
  batch,
75
  prompt_type,
76
- custom_prompt_text if prompt_type == "Custom Prompt" else None,
77
- target_word_count
78
  )
79
  batch = batch_summaries
80
  condensed_chunks.extend(batch)
@@ -91,8 +94,7 @@ def run_app(file_obj, text_input, model_name, local_model_path, prompt_type, cus
91
  final_summary = summarizer.summarize_batch(
92
  [combined],
93
  prompt_type,
94
- custom_prompt_text if prompt_type == "Custom Prompt" else None,
95
- target_word_count
96
  )[0]
97
 
98
  end_time = time.time()
@@ -118,7 +120,10 @@ model_tip = gr.Markdown(
118
  """
119
  **Model Selection Tips:**
120
  - **facebook/bart-large-cnn:** Fast, general-purpose summarization for short to medium texts.
 
 
121
  - **google/long-t5-local-base:** Designed for long documents; better context handling.
 
122
  - **mistralai/Mistral-7B-v0.1:** High-quality nuanced summaries; resource-intensive.
123
  - **Custom Local Model:** Specify a path to a downloaded model (e.g., `./models/my-bart-model`).
124
  """
@@ -151,9 +156,6 @@ with gr.Blocks(css="#status-log { overflow-y: scroll; max-height: 200px; }") as
151
  with gr.Row():
152
  iterations_slider = gr.Slider(minimum=1, maximum=5, step=1, label="Summarization Iterations", value=1)
153
  batch_size_slider = gr.Slider(minimum=1, maximum=8, step=1, label="Batch Size (for GPU)", value=4)
154
-
155
- with gr.Row():
156
- target_word_count_slider = gr.Slider(minimum=20, maximum=200, step=10, label="Target Summary Word Count", value=50)
157
 
158
  summarize_button = gr.Button("Summarize")
159
 
@@ -171,7 +173,7 @@ with gr.Blocks(css="#status-log { overflow-y: scroll; max-height: 200px; }") as
171
  outputs=summarize_button
172
  ).then(
173
  fn=run_app,
174
- inputs=[file_input, text_input, model_dropdown, local_model_path_input, prompt_dropdown, custom_prompt_input, iterations_slider, batch_size_slider, target_word_count_slider],
175
  outputs=[output_text, status_log, download_button, summarize_button]
176
  )
177
 
 
3
  import os
4
  import chardet
5
  import time
6
+ from core.summarizer import NarrativeSummarizer
7
 
8
  # Models available
9
  MODEL_OPTIONS = [
10
  "facebook/bart-large-cnn",
11
+ "sshleifer/distilbart-cnn-12-6",
12
+ "google/pegasus-cnn_dailymail",
13
  "google/long-t5-local-base",
14
+ "t5-small",
15
+ "t5-base",
16
  "mistralai/Mistral-7B-v0.1"
17
  ]
18
 
 
24
  "Custom Prompt"
25
  ]
26
 
27
+ def run_app(file_obj, text_input, model_name, local_model_path, prompt_type, custom_prompt_text, iterations, batch_size, progress=gr.Progress()):
28
  start_time = time.time()
29
 
30
  # Check if custom prompt is selected but not provided
 
77
  batch_summaries = summarizer.summarize_batch(
78
  batch,
79
  prompt_type,
80
+ custom_prompt_text if prompt_type == "Custom Prompt" else None
 
81
  )
82
  batch = batch_summaries
83
  condensed_chunks.extend(batch)
 
94
  final_summary = summarizer.summarize_batch(
95
  [combined],
96
  prompt_type,
97
+ custom_prompt_text if prompt_type == "Custom Prompt" else None
 
98
  )[0]
99
 
100
  end_time = time.time()
 
120
  """
121
  **Model Selection Tips:**
122
  - **facebook/bart-large-cnn:** Fast, general-purpose summarization for short to medium texts.
123
+ - **sshleifer/distilbart-cnn-12-6:** A smaller, faster version of BART.
124
+ - **google/pegasus-cnn_dailymail:** Excellent for abstractive summarization.
125
  - **google/long-t5-local-base:** Designed for long documents; better context handling.
126
+ - **t5-small/t5-base:** Efficient and versatile for various tasks.
127
  - **mistralai/Mistral-7B-v0.1:** High-quality nuanced summaries; resource-intensive.
128
  - **Custom Local Model:** Specify a path to a downloaded model (e.g., `./models/my-bart-model`).
129
  """
 
156
  with gr.Row():
157
  iterations_slider = gr.Slider(minimum=1, maximum=5, step=1, label="Summarization Iterations", value=1)
158
  batch_size_slider = gr.Slider(minimum=1, maximum=8, step=1, label="Batch Size (for GPU)", value=4)
 
 
 
159
 
160
  summarize_button = gr.Button("Summarize")
161
 
 
173
  outputs=summarize_button
174
  ).then(
175
  fn=run_app,
176
+ inputs=[file_input, text_input, model_dropdown, local_model_path_input, prompt_dropdown, custom_prompt_input, iterations_slider, batch_size_slider],
177
  outputs=[output_text, status_log, download_button, summarize_button]
178
  )
179