rayl-aoit commited on
Commit
ab66837
·
verified ·
1 Parent(s): 2226656

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -27
app.py CHANGED
@@ -2,15 +2,11 @@ import gradio as gr
2
  from transformers import pipeline
3
 
4
  playground = gr.Blocks()
 
5
  image_pipe = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
6
  summary_pipe = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
7
  ner_pipe = pipeline("ner", model="dslim/bert-base-NER")
8
 
9
- examples_summarization = [
10
- ["The tower is 324 metres (1,063 ft) tall, about the same height as an 81-storey building, and the tallest structure in Paris. Its base is square, measuring 125 metres (410 ft) on each side. During its construction, the Eiffel Tower surpassed the Washington Monument to become the tallest man-made structure in the world, a title it held for 41 years until the Chrysler Building in New York City was finished in 1930. It was the first structure to reach a height of 300 metres. Due to the addition of a broadcasting aerial at the top of the tower in 1957, it is now taller than the Chrysler Building by 5.2 metres (17 ft). Excluding transmitters, the Eiffel Tower is the second tallest free-standing structure in France after the Millau Viaduct."],
11
- ["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."]
12
- ]
13
-
14
  def launch_image_pipe(input):
15
  out = image_pipe(input)
16
  return out[0]['generated_text']
@@ -73,8 +69,7 @@ def create_tabs_header(topic, description, references):
73
  gr.Markdown("""
74
  ## Image Captioning
75
  ### Upload a image, check what AI understand and have vision on it.
76
- > category: Image-to-Text
77
- > model: [Salesforce/blip-image-captioning-base](https://huggingface.co/Salesforce/blip-image-captioning-base)
78
  """)
79
 
80
  with gr.Column(scale=1):
@@ -117,32 +112,21 @@ with playground:
117
 
118
  with gr.Row():
119
  with gr.Column():
120
- source_text = gr.Textbox(label="Text to summarize", lines=6)
121
- gr.Examples(examples=examples_summarization, inputs=source_text)
 
 
 
122
  with gr.Column():
123
- summary_textbox = gr.Textbox(lines=3, placeholder="", label="Summarization")
124
- translated_textbox = gr.Textbox(lines=3, placeholder="", label="Translate Result")
125
 
126
 
127
  text_pipeline_button.click(summarize,
128
  inputs=[source_text],
129
- outputs=[summary_textbox, translated_textbox])
130
 
131
  with gr.TabItem("Name Entity"):
132
- # gr.Markdown("""
133
- # > Name Entity Recognition
134
- # """)
135
-
136
- # iface = gr.Interface(fn=ner,
137
- # inputs=[gr.Textbox(label="Text to find entities", lines=2)],
138
- # outputs=[gr.HighlightedText(label="Text with entities")],
139
- # title="NER with dslim/bert-base-NER",
140
- # description="Find entities using the `dslim/bert-base-NER` model!",
141
- # allow_flagging="never",
142
- # examples=["My name is Ray, I'm learning through Hugging Face and DeepLearning.AI and I live in Caversham, Reading", "My name is Raymond, I work at A&O IT Group"])
143
-
144
- gr.Markdown("# NER with dslim/bert-base-NER")
145
- gr.Markdown("Find entities using the `dslim/bert-base-NER` model!")
146
  with gr.Row():
147
  with gr.Column(scale=4):
148
  gr.Markdown("""
@@ -157,7 +141,7 @@ with playground:
157
  with gr.Row():
158
  with gr.Column():
159
  ner_text_input = gr.Textbox(label="Text to find entities", lines=2)
160
- examples = gr.Examples(examples=[
161
  "My name is Ray, I'm learning through Hugging Face and DeepLearning.AI and I live in Caversham, Reading",
162
  "My name is Raymond, I work at A&O IT Group"
163
  ], inputs=ner_text_input)
 
2
  from transformers import pipeline
3
 
4
  playground = gr.Blocks()
5
+
6
  image_pipe = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
7
  summary_pipe = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
8
  ner_pipe = pipeline("ner", model="dslim/bert-base-NER")
9
 
 
 
 
 
 
10
  def launch_image_pipe(input):
11
  out = image_pipe(input)
12
  return out[0]['generated_text']
 
69
  gr.Markdown("""
70
  ## Image Captioning
71
  ### Upload a image, check what AI understand and have vision on it.
72
+ > category: Image-to-Text, model: [Salesforce/blip-image-captioning-base](https://huggingface.co/Salesforce/blip-image-captioning-base)
 
73
  """)
74
 
75
  with gr.Column(scale=1):
 
112
 
113
  with gr.Row():
114
  with gr.Column():
115
+ source_text = gr.Textbox(label="Text to summarize", lines=10)
116
+ gr.Examples(examples=[
117
+ "The tower is 324 metres (1,063 ft) tall, about the same height as an 81-storey building, and the tallest structure in Paris. Its base is square, measuring 125 metres (410 ft) on each side. During its construction, the Eiffel Tower surpassed the Washington Monument to become the tallest man-made structure in the world, a title it held for 41 years until the Chrysler Building in New York City was finished in 1930. It was the first structure to reach a height of 300 metres. Due to the addition of a broadcasting aerial at the top of the tower in 1957, it is now taller than the Chrysler Building by 5.2 metres (17 ft). Excluding transmitters, the Eiffel Tower is the second tallest free-standing structure in France after the Millau Viaduct.",
118
+ "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."
119
+ ], inputs=source_text)
120
  with gr.Column():
121
+ summary_textoutput = gr.Textbox(lines=3, placeholder="", label="Text Summarization")
122
+ translated_textbox = gr.Textbox(lines=3, placeholder="", label="Translated Result")
123
 
124
 
125
  text_pipeline_button.click(summarize,
126
  inputs=[source_text],
127
+ outputs=[summary_textoutput, translated_textbox])
128
 
129
  with gr.TabItem("Name Entity"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  with gr.Row():
131
  with gr.Column(scale=4):
132
  gr.Markdown("""
 
141
  with gr.Row():
142
  with gr.Column():
143
  ner_text_input = gr.Textbox(label="Text to find entities", lines=2)
144
+ gr.Examples(examples=[
145
  "My name is Ray, I'm learning through Hugging Face and DeepLearning.AI and I live in Caversham, Reading",
146
  "My name is Raymond, I work at A&O IT Group"
147
  ], inputs=ner_text_input)