rayl-aoit commited on
Commit
d41dc2a
·
verified ·
1 Parent(s): 33ccd4a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -6
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
  from huggingface_hub import InferenceClient
 
4
  # from IPython.display import Audio as IPythonAudio
5
 
6
  playground = gr.Blocks()
@@ -61,10 +62,13 @@ def translate(input_text, source, target):
61
  except KeyError:
62
  return "", f"Error: Translation direction {source_readable} to {target} is not supported by Helsinki Translation Models"
63
 
64
- def summarize(input):
65
- output = summary_pipe(input)
66
  summary_origin = output[0]['summary_text']
67
- summary_translated = translate(summary_origin,'en','fr')
 
 
 
68
  return summary_origin, summary_translated[0]
69
 
70
  def merge_tokens(tokens):
@@ -136,18 +140,22 @@ with playground:
136
  gr.Markdown("""
137
  ## Text Summarization and Translation
138
  ### Summarize the paragraph and translate it into other language.
139
- > pipeline: summarization, model: [sshleifer/distilbart-cnn-12-6](https://huggingface.co/sshleifer/distilbart-cnn-12-6)
140
- > pipeline: translation, model: [Helsinki-NLP/opus-mt-en-fr](https://huggingface.co/Helsinki-NLP/opus-mt-en-fr)
141
  """)
142
 
143
  with gr.Column(scale=1):
144
  text_pipeline_button = gr.Button(value="Start Process", variant="primary")
 
145
 
146
  with gr.Row():
147
  with gr.Column():
148
  source_text = gr.Textbox(label="Text to summarize", lines=13)
149
  with gr.Column():
150
  summary_textoutput = gr.Textbox(lines=3, placeholder="", label="Text Summarization")
 
 
 
151
  translated_textbox = gr.Textbox(lines=3, placeholder="", label="Translated Result")
152
  Text_Clear_button = gr.ClearButton(components=[source_text, summary_textoutput, translated_textbox], value="Clear")
153
 
@@ -158,7 +166,7 @@ with playground:
158
  "Tower Bridge is a Grade I listed combined bascule, suspension, and, until 1960, cantilever bridge[1] in London, built between 1886 and 1894, designed by Horace Jones and engineered by John Wolfe Barry with the help of Henry Marc Brunel.[2] It crosses the River Thames close to the Tower of London and is one of five London bridges owned and maintained by the City Bridge Foundation, a charitable trust founded in 1282. The bridge was constructed to connect the 39 per cent of London's population that lived east of London Bridge, while allowing shipping to access the Pool of London between the Tower of London and London Bridge. The bridge was opened by Edward, Prince of Wales and Alexandra, Princess of Wales on 30 June 1894."
159
  ], inputs=[source_text], outputs=[summary_textoutput, translated_textbox], run_on_click=True, cache_examples=True, fn=summarize)
160
 
161
- text_pipeline_button.click(summarize, inputs=[source_text], outputs=[summary_textoutput, translated_textbox])
162
 
163
  ## ================================================================================================================================
164
  ## Find entities
 
1
  import gradio as gr
2
  from transformers import pipeline
3
  from huggingface_hub import InferenceClient
4
+ from language_directions import *
5
  # from IPython.display import Audio as IPythonAudio
6
 
7
  playground = gr.Blocks()
 
62
  except KeyError:
63
  return "", f"Error: Translation direction {source_readable} to {target} is not supported by Helsinki Translation Models"
64
 
65
+ def summarize_translate(input_text, target_lang):
66
+ output = summary_pipe(input_text)
67
  summary_origin = output[0]['summary_text']
68
+ source = 'en'
69
+ target_lang_dict = get_all_source_languages()
70
+ target = target_lang_dict[target_lang]
71
+ summary_translated = translate(summary_origin,source,target)
72
  return summary_origin, summary_translated[0]
73
 
74
  def merge_tokens(tokens):
 
140
  gr.Markdown("""
141
  ## Text Summarization and Translation
142
  ### Summarize the paragraph and translate it into other language.
143
+ - pipeline: summarization, model: [sshleifer/distilbart-cnn-12-6](https://huggingface.co/sshleifer/distilbart-cnn-12-6)
144
+ - pipeline: translation, model: [Helsinki-NLP/opus-mt-en-fr](https://huggingface.co/Helsinki-NLP/opus-mt-en-fr)
145
  """)
146
 
147
  with gr.Column(scale=1):
148
  text_pipeline_button = gr.Button(value="Start Process", variant="primary")
149
+
150
 
151
  with gr.Row():
152
  with gr.Column():
153
  source_text = gr.Textbox(label="Text to summarize", lines=13)
154
  with gr.Column():
155
  summary_textoutput = gr.Textbox(lines=3, placeholder="", label="Text Summarization")
156
+ target_language_dropdown = gr.Dropdown( choices=["Chinese", "French", "Spanish"],
157
+ value="Chinese",
158
+ label="Translate to Language")
159
  translated_textbox = gr.Textbox(lines=3, placeholder="", label="Translated Result")
160
  Text_Clear_button = gr.ClearButton(components=[source_text, summary_textoutput, translated_textbox], value="Clear")
161
 
 
166
  "Tower Bridge is a Grade I listed combined bascule, suspension, and, until 1960, cantilever bridge[1] in London, built between 1886 and 1894, designed by Horace Jones and engineered by John Wolfe Barry with the help of Henry Marc Brunel.[2] It crosses the River Thames close to the Tower of London and is one of five London bridges owned and maintained by the City Bridge Foundation, a charitable trust founded in 1282. The bridge was constructed to connect the 39 per cent of London's population that lived east of London Bridge, while allowing shipping to access the Pool of London between the Tower of London and London Bridge. The bridge was opened by Edward, Prince of Wales and Alexandra, Princess of Wales on 30 June 1894."
167
  ], inputs=[source_text], outputs=[summary_textoutput, translated_textbox], run_on_click=True, cache_examples=True, fn=summarize)
168
 
169
+ text_pipeline_button.click(summarize_translate, inputs=[source_text, target_language_dropdown], outputs=[summary_textoutput, translated_textbox])
170
 
171
  ## ================================================================================================================================
172
  ## Find entities