thomasanto7001 commited on
Commit
04a8676
·
verified ·
1 Parent(s): d8ec807

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -4
app.py CHANGED
@@ -41,12 +41,32 @@ def transcribe_audio(audio_path):
41
  return result["text"]
42
 
43
  # 📄 Summary generator with batching
44
- def generate_summary(text, max_len=130, min_len=30):
 
45
  sentences = sent_tokenize(text)
 
 
46
  chunks = [' '.join(sentences[i:i + 10]) for i in range(0, len(sentences), 10)]
47
-
48
- results = summarizer(chunks, max_length=max_len, min_length=min_len, do_sample=False)
49
- return " ".join([r["summary_text"] for r in results])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
  # ❓ Quiz generator
52
  def generate_quiz(text, num_questions=5):
 
41
  return result["text"]
42
 
43
  # 📄 Summary generator with batching
44
+ ddef generate_summary(text, default_max_len=130, default_min_len=30):
45
+ summarizer = pipeline("summarization")
46
  sentences = sent_tokenize(text)
47
+
48
+ # Chunk sentences in groups of 10
49
  chunks = [' '.join(sentences[i:i + 10]) for i in range(0, len(sentences), 10)]
50
+ summary = ""
51
+
52
+ for chunk in chunks:
53
+ input_len = len(chunk.split())
54
+
55
+ # Dynamically scale max and min length
56
+ dynamic_max = max(20, min(default_max_len, input_len - 1))
57
+ dynamic_min = max(10, min(default_min_len, dynamic_max - 10))
58
+
59
+ # Avoid max_length > input_length error
60
+ result = summarizer(
61
+ chunk,
62
+ max_length=dynamic_max,
63
+ min_length=dynamic_min,
64
+ do_sample=False
65
+ )[0]["summary_text"]
66
+
67
+ summary += result + " "
68
+
69
+ return summary.strip()
70
 
71
  # ❓ Quiz generator
72
  def generate_quiz(text, num_questions=5):