codeteach commited on
Commit
b588b2c
1 Parent(s): da54932

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -2
app.py CHANGED
@@ -10,6 +10,9 @@ translation_models = {
10
  'Spanish': "Helsinki-NLP/opus-mt-en-es"
11
  }
12
 
 
 
 
13
  # Initialize translation pipeline
14
  def get_translator(language):
15
  model_name = translation_models.get(language)
@@ -32,6 +35,11 @@ def generate_bullet_points(text):
32
 
33
  return "\n".join(f"- {point}" for point in bullet_points)
34
 
 
 
 
 
 
35
  # Helper function to translate text
36
  def translate_text(text, language):
37
  translator = get_translator(language)
@@ -41,7 +49,8 @@ def translate_text(text, language):
41
  return text
42
 
43
  def process_text(input_text, language):
44
- bullet_points = generate_bullet_points(input_text)
 
45
  translated_text = translate_text(bullet_points, language)
46
  return bullet_points, translated_text
47
 
@@ -57,7 +66,8 @@ iface = gr.Interface(
57
  gr.Textbox(label="Translated Bullet Points")
58
  ],
59
  title="Text to Bullet Points and Translation",
60
- description="Paste any text, and the program will transform it into bullet points. Optionally, translate the bullet points into Vietnamese, Japanese, Thai, or Spanish."
61
  )
62
 
63
  iface.launch()
 
 
10
  'Spanish': "Helsinki-NLP/opus-mt-en-es"
11
  }
12
 
13
+ # Initialize summarization pipeline
14
+ summarizer = pipeline("summarization")
15
+
16
  # Initialize translation pipeline
17
  def get_translator(language):
18
  model_name = translation_models.get(language)
 
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):
45
  translator = get_translator(language)
 
49
  return text
50
 
51
  def process_text(input_text, language):
52
+ summary = summarize_text(input_text)
53
+ bullet_points = generate_bullet_points(summary)
54
  translated_text = translate_text(bullet_points, language)
55
  return bullet_points, translated_text
56
 
 
66
  gr.Textbox(label="Translated Bullet Points")
67
  ],
68
  title="Text to Bullet Points and Translation",
69
+ description="Paste any text, and the program will summarize it into bullet points. Optionally, translate the bullet points into Vietnamese, Japanese, Thai, or Spanish."
70
  )
71
 
72
  iface.launch()
73
+