Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,11 +3,28 @@ from transformers import pipeline
|
|
3 |
|
4 |
playground = gr.Blocks()
|
5 |
image_pipe = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
|
|
|
|
6 |
|
7 |
def launch_image_pipe(input):
|
8 |
out = image_pipe(input)
|
9 |
return out[0]['generated_text']
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
def create_playground_header():
|
12 |
gr.Markdown("""
|
13 |
# 🤗 Hugging Face Labs
|
@@ -50,7 +67,7 @@ with playground:
|
|
50 |
"model: [Salesforce/blip-image-captioning-base](https://huggingface.co/Salesforce/blip-image-captioning-base)"]
|
51 |
image_pipeline_button = create_tabs_header(topic, description, references)
|
52 |
|
53 |
-
with gr.Row(
|
54 |
with gr.Column():
|
55 |
img = gr.Image(type='pil')
|
56 |
with gr.Column():
|
@@ -64,7 +81,30 @@ with playground:
|
|
64 |
gr.Markdown("""
|
65 |
> Text Summarization and Translation
|
66 |
""")
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
with gr.TabItem("Name Entity"):
|
69 |
gr.Markdown("""
|
70 |
> Name Entity Recognition
|
|
|
3 |
|
4 |
playground = gr.Blocks()
|
5 |
image_pipe = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
6 |
+
get_completion = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
|
7 |
+
|
8 |
|
9 |
def launch_image_pipe(input):
|
10 |
out = image_pipe(input)
|
11 |
return out[0]['generated_text']
|
12 |
|
13 |
+
def translate(input_text, source, target):
|
14 |
+
try:
|
15 |
+
model = f"Helsinki-NLP/opus-mt-{source}-{target}"
|
16 |
+
pipe = pipeline("translation", model=model)
|
17 |
+
translation = pipe(input_text)
|
18 |
+
return translation[0]['translation_text'], ""
|
19 |
+
except KeyError:
|
20 |
+
return "", f"Error: Translation direction {source_readable} to {target} is not supported by Helsinki Translation Models"
|
21 |
+
|
22 |
+
def summarize(input):
|
23 |
+
output = get_completion(input)
|
24 |
+
summary_origin = output[0]['summary_text']
|
25 |
+
summary_translated = translate(summary_origin,'en','fr')
|
26 |
+
return summary_origin, summary_translated[0]
|
27 |
+
|
28 |
def create_playground_header():
|
29 |
gr.Markdown("""
|
30 |
# 🤗 Hugging Face Labs
|
|
|
67 |
"model: [Salesforce/blip-image-captioning-base](https://huggingface.co/Salesforce/blip-image-captioning-base)"]
|
68 |
image_pipeline_button = create_tabs_header(topic, description, references)
|
69 |
|
70 |
+
with gr.Row():
|
71 |
with gr.Column():
|
72 |
img = gr.Image(type='pil')
|
73 |
with gr.Column():
|
|
|
81 |
gr.Markdown("""
|
82 |
> Text Summarization and Translation
|
83 |
""")
|
84 |
+
with gr.Row():
|
85 |
+
with gr.Column(scale=4):
|
86 |
+
gr.Markdown("""
|
87 |
+
## Text Summarization and Translation
|
88 |
+
### Summarize the paragraph and translate it into other language.
|
89 |
+
> pipeline: summarization, model: [sshleifer/distilbart-cnn-12-6](https://huggingface.co/sshleifer/distilbart-cnn-12-6)
|
90 |
+
> pipeline: translation, model: [Helsinki-NLP/opus-mt-en-fr](https://huggingface.co/Helsinki-NLP/opus-mt-en-fr)
|
91 |
+
""")
|
92 |
+
|
93 |
+
with gr.Column(scale=1):
|
94 |
+
text_pipeline_button = gr.Button(value="Process")
|
95 |
+
|
96 |
+
with gr.Row():
|
97 |
+
with gr.Column():
|
98 |
+
source_text = gr.Textbox(label="Text to summarize", lines=6)
|
99 |
+
with gr.Column():
|
100 |
+
summary_textbox = gr.Textbox(lines=3, placeholder="", label="Summarization")
|
101 |
+
translated_textbox = gr.Textbox(lines=3, placeholder="", label="Translate Result")
|
102 |
+
|
103 |
+
|
104 |
+
text_pipeline_button.click(summarize,
|
105 |
+
inputs=[source_text],
|
106 |
+
outputs=[summary_textbox, translated_textbox])
|
107 |
+
|
108 |
with gr.TabItem("Name Entity"):
|
109 |
gr.Markdown("""
|
110 |
> Name Entity Recognition
|