codeteach commited on
Commit
b451def
1 Parent(s): fb658f7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -2
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
  from sentence_transformers import SentenceTransformer, util
 
4
 
5
  # Translation models
6
  translation_models = {
@@ -35,10 +36,33 @@ def generate_bullet_points(text):
35
 
36
  return "\n".join(f"- {point}" for point in bullet_points)
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  # Helper function to summarize text
39
  def summarize_text(text):
40
- summary = summarizer(text, max_length=150, min_length=40, do_sample=False)
41
- return summary[0]['summary_text']
 
42
 
43
  # Helper function to translate text
44
  def translate_text(text, language):
@@ -72,3 +96,4 @@ iface = gr.Interface(
72
  iface.launch()
73
 
74
 
 
 
1
  import gradio as gr
2
  from transformers import pipeline
3
  from sentence_transformers import SentenceTransformer, util
4
+ import math
5
 
6
  # Translation models
7
  translation_models = {
 
36
 
37
  return "\n".join(f"- {point}" for point in bullet_points)
38
 
39
+ # Helper function to split text into chunks
40
+ def split_text(text, max_tokens=1024):
41
+ sentences = text.split('. ')
42
+ chunks = []
43
+ current_chunk = ""
44
+ current_tokens = 0
45
+
46
+ for sentence in sentences:
47
+ sentence_tokens = len(sentence.split())
48
+ if current_tokens + sentence_tokens > max_tokens:
49
+ chunks.append(current_chunk.strip())
50
+ current_chunk = sentence
51
+ current_tokens = sentence_tokens
52
+ else:
53
+ current_chunk += sentence + ". "
54
+ current_tokens += sentence_tokens
55
+
56
+ if current_chunk:
57
+ chunks.append(current_chunk.strip())
58
+
59
+ return chunks
60
+
61
  # Helper function to summarize text
62
  def summarize_text(text):
63
+ chunks = split_text(text)
64
+ summaries = [summarizer(chunk, max_length=150, min_length=40, do_sample=False)[0]['summary_text'] for chunk in chunks]
65
+ return " ".join(summaries)
66
 
67
  # Helper function to translate text
68
  def translate_text(text, language):
 
96
  iface.launch()
97
 
98
 
99
+