Spaces:
Running
Running
Upload apps
Browse files- .gitattributes +1 -0
- app.py +32 -0
- img2txt.py +21 -0
- imgs/car.jpg +0 -0
- imgs/swan.jpg +0 -0
- imgs/tiger.jpg +3 -0
- keyextract.py +28 -0
- ner.py +42 -0
- qa.py +29 -0
- requirements.txt +4 -0
- sentiment.py +30 -0
- summarizer.py +30 -0
- wc.py +29 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
imgs/tiger.jpg filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
#Blocks or Interface instances
|
4 |
+
from summarizer import interface_summarization
|
5 |
+
from sentiment import interface_sentiment
|
6 |
+
from ner import interface_ner
|
7 |
+
from wc import interface_wc
|
8 |
+
from qa import interface_qa
|
9 |
+
from img2txt import interface_img2txt
|
10 |
+
from keyextract import interface_keyextract
|
11 |
+
|
12 |
+
|
13 |
+
with gr.Blocks(title='AI Marketplace') as main_demo:
|
14 |
+
gr.Markdown("Your NLP Swiss Army Knife. Start by selecting the app you want to run in the tabbed interface.")
|
15 |
+
|
16 |
+
with gr.Tabs():
|
17 |
+
with gr.TabItem('Summarization'):
|
18 |
+
interface_summarization.render()
|
19 |
+
with gr.TabItem('Sentiment Analysis'):
|
20 |
+
interface_sentiment.render()
|
21 |
+
with gr.TabItem('NER'):
|
22 |
+
interface_ner.render()
|
23 |
+
with gr.TabItem('WordCloud'):
|
24 |
+
interface_wc.render()
|
25 |
+
with gr.TabItem('Question Answering'):
|
26 |
+
interface_qa.render()
|
27 |
+
with gr.TabItem('Image captioning'):
|
28 |
+
interface_img2txt.render()
|
29 |
+
with gr.TabItem('Keyword Extraction'):
|
30 |
+
interface_keyextract.render()
|
31 |
+
|
32 |
+
main_demo.launch()
|
img2txt.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
get_caption = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
5 |
+
|
6 |
+
def caption(img):
|
7 |
+
if not img:
|
8 |
+
pass
|
9 |
+
else:
|
10 |
+
output = get_caption(img)
|
11 |
+
return output[0]["generated_text"]
|
12 |
+
|
13 |
+
interface_img2txt = gr.Interface(fn=caption,
|
14 |
+
inputs=gr.Image(label="Image", type='pil'),
|
15 |
+
outputs=gr.Textbox(label="Caption"),
|
16 |
+
examples=["imgs/car.jpg", "imgs/tiger.jpg", "imgs/swan.jpg"],
|
17 |
+
title="Image captioning",
|
18 |
+
description="Get a image caption.",
|
19 |
+
css="footer{display:none !important}",
|
20 |
+
allow_flagging="never"
|
21 |
+
)
|
imgs/car.jpg
ADDED
imgs/swan.jpg
ADDED
imgs/tiger.jpg
ADDED
Git LFS Details
|
keyextract.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from keybert import KeyBERT
|
3 |
+
|
4 |
+
keyextract_examples = [
|
5 |
+
"""
|
6 |
+
Machine learning (ML) is an umbrella term for solving problems for which development of algorithms by human programmers would be cost-prohibitive, and instead the problems are solved by helping machines 'discover' their 'own' algorithms, without needing to be explicitly told what to do by any human-developed algorithms.
|
7 |
+
Recently, generative artificial neural networks have been able to surpass results of many previous approaches. Machine learning approaches have been applied to large language models, computer vision, speech recognition, email filtering, agriculture and medicine, where it is too costly to develop algorithms to perform the needed tasks.
|
8 |
+
The mathematical foundations of ML are provided by mathematical optimization (mathematical programming) methods. Data mining is a related (parallel) field of study, focusing on exploratory data analysis through unsupervised learning. ML is known in its application across business problems under the name predictive analytics. Although not all machine learning is statistically-based, computational statistics is an important source of the field's methods.
|
9 |
+
""",]
|
10 |
+
|
11 |
+
kw_model = KeyBERT(model='all-MiniLM-L6-v2')
|
12 |
+
|
13 |
+
def key(input):
|
14 |
+
if not input:
|
15 |
+
pass
|
16 |
+
else:
|
17 |
+
keywords = kw_model.extract_keywords(input, highlight=False, stop_words=None)
|
18 |
+
return keywords
|
19 |
+
|
20 |
+
interface_keyextract = gr.Interface(fn=key,
|
21 |
+
inputs=gr.Textbox(label="Text", lines=4),
|
22 |
+
outputs=gr.HighlightedText(label="Keywords"),
|
23 |
+
examples = keyextract_examples,
|
24 |
+
title="Keyword extraction",
|
25 |
+
description="Highlight keywords in a given text.",
|
26 |
+
css="footer{display:none !important}",
|
27 |
+
allow_flagging="never"
|
28 |
+
)
|
ner.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
ner_example = [
|
5 |
+
"""
|
6 |
+
My name is Superman, and I come from the planet Krypton
|
7 |
+
""",
|
8 |
+
]
|
9 |
+
|
10 |
+
get_entities = pipeline("ner", model="dslim/bert-base-NER")
|
11 |
+
|
12 |
+
def merge_tokens(tokens):
|
13 |
+
merged_tokens = []
|
14 |
+
for token in tokens:
|
15 |
+
if merged_tokens and token['entity'].startswith('I-') and merged_tokens[-1]['entity'].endswith(token['entity'][2:]):
|
16 |
+
# If current token continues the entity of the last one, merge them
|
17 |
+
last_token = merged_tokens[-1]
|
18 |
+
last_token['word'] += token['word'].replace('##', '')
|
19 |
+
last_token['end'] = token['end']
|
20 |
+
last_token['score'] = (last_token['score'] + token['score']) / 2
|
21 |
+
else:
|
22 |
+
# Otherwise, add the token to the list
|
23 |
+
merged_tokens.append(token)
|
24 |
+
return merged_tokens
|
25 |
+
|
26 |
+
def ner(input):
|
27 |
+
if not input:
|
28 |
+
pass
|
29 |
+
else:
|
30 |
+
output = get_entities(input)
|
31 |
+
merged_tokens = merge_tokens(output)
|
32 |
+
return {"text": input, "entities": merged_tokens}
|
33 |
+
|
34 |
+
interface_ner = gr.Interface(fn=ner,
|
35 |
+
inputs=[gr.Textbox(label="Text to identify entities", lines=1)],
|
36 |
+
outputs=[gr.HighlightedText(label="Text with entities")],
|
37 |
+
examples=ner_example,
|
38 |
+
title="Named Entity Recognition",
|
39 |
+
description="Find entities in given text.",
|
40 |
+
css="footer{display:none !important}",
|
41 |
+
allow_flagging="never"
|
42 |
+
)
|
qa.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
context_example = """
|
5 |
+
Machine learning (ML) is an umbrella term for solving problems for which development of algorithms by human programmers would be cost-prohibitive, and instead the problems are solved by helping machines 'discover' their 'own' algorithms, without needing to be explicitly told what to do by any human-developed algorithms.
|
6 |
+
Recently, generative artificial neural networks have been able to surpass results of many previous approaches. Machine learning approaches have been applied to large language models, computer vision, speech recognition, email filtering, agriculture and medicine, where it is too costly to develop algorithms to perform the needed tasks.
|
7 |
+
The mathematical foundations of ML are provided by mathematical optimization (mathematical programming) methods. Data mining is a related (parallel) field of study, focusing on exploratory data analysis through unsupervised learning.
|
8 |
+
ML is known in its application across business problems under the name predictive analytics. Although not all machine learning is statistically-based, computational statistics is an important source of the field's methods.
|
9 |
+
"""
|
10 |
+
question_example = "What are the foundations of Machine learning?"
|
11 |
+
|
12 |
+
get_question_answering = pipeline("question-answering", model='distilbert-base-cased-distilled-squad')
|
13 |
+
|
14 |
+
def qa(context, question):
|
15 |
+
if not context or not question:
|
16 |
+
pass
|
17 |
+
else:
|
18 |
+
output = get_question_answering(question=question, context=context)
|
19 |
+
return output['answer']
|
20 |
+
|
21 |
+
interface_qa = gr.Interface(qa,
|
22 |
+
inputs=[gr.Textbox(label="Text to ask questions from", lines=4), gr.Textbox(label="Question", lines=4)],
|
23 |
+
outputs=[gr.Textbox(label="Answer")],
|
24 |
+
examples = [[context_example, question_example]],
|
25 |
+
title="Question Answering",
|
26 |
+
description="Ask questions about a given text.",
|
27 |
+
css="footer{display:none !important}",
|
28 |
+
allow_flagging="never"
|
29 |
+
)
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
transformers
|
3 |
+
keybert
|
4 |
+
wordcloud
|
sentiment.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
sentiment_examples = [
|
5 |
+
"""
|
6 |
+
I have been a customer for several years now. I have always received
|
7 |
+
the best service, product, and customer service whenever I come here.
|
8 |
+
For all my service needs, this is the place I trust
|
9 |
+
""", """
|
10 |
+
I had a terrible experience here. Everyone was rude and unhelpful. I would not recommend this place to anyone.
|
11 |
+
""",]
|
12 |
+
|
13 |
+
sentiment = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
|
14 |
+
|
15 |
+
def get_sentiment(input):
|
16 |
+
if not input:
|
17 |
+
pass
|
18 |
+
else:
|
19 |
+
output = sentiment(input.lower())
|
20 |
+
return output[0]['label']
|
21 |
+
|
22 |
+
interface_sentiment = gr.Interface(fn = get_sentiment,
|
23 |
+
inputs=gr.Textbox(label="Text", lines=4),
|
24 |
+
outputs=gr.Textbox(label="Sentiment"),
|
25 |
+
title = 'Sentiment Analysis',
|
26 |
+
examples=sentiment_examples,
|
27 |
+
description="Get Sentiment (Positive / Negative) for a given text.",
|
28 |
+
css="footer{display:none !important}",
|
29 |
+
allow_flagging="never"
|
30 |
+
)
|
summarizer.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
summary_examples = [
|
5 |
+
"""
|
6 |
+
Machine learning (ML) is an umbrella term for solving problems for which development of algorithms by human programmers would be cost-prohibitive, and instead the problems are solved by helping machines 'discover' their 'own' algorithms, without needing to be explicitly told what to do by any human-developed algorithms.
|
7 |
+
Recently, generative artificial neural networks have been able to surpass results of many previous approaches. Machine learning approaches have been applied to large language models, computer vision, speech recognition, email filtering, agriculture and medicine, where it is too costly to develop algorithms to perform the needed tasks.
|
8 |
+
The mathematical foundations of ML are provided by mathematical optimization (mathematical programming) methods. Data mining is a related (parallel) field of study, focusing on exploratory data analysis through unsupervised learning.
|
9 |
+
ML is known in its application across business problems under the name predictive analytics. Although not all machine learning is statistically-based, computational statistics is an important source of the field's methods.
|
10 |
+
""",]
|
11 |
+
|
12 |
+
get_summary = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
|
13 |
+
|
14 |
+
def summarize(input):
|
15 |
+
print(input)
|
16 |
+
if not input:
|
17 |
+
pass
|
18 |
+
else:
|
19 |
+
output = get_summary(input)
|
20 |
+
return output[0]['summary_text']
|
21 |
+
|
22 |
+
interface_summarization = gr.Interface(fn=summarize,
|
23 |
+
inputs=gr.Textbox(label="Text", lines=4),
|
24 |
+
outputs=gr.Textbox(label="Summary"),
|
25 |
+
examples = summary_examples,
|
26 |
+
title="Summarize text",
|
27 |
+
description="Create a summary of a given text.",
|
28 |
+
css="footer{display:none !important}",
|
29 |
+
allow_flagging="never"
|
30 |
+
)
|
wc.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from wordcloud import WordCloud
|
3 |
+
|
4 |
+
wc_example = ["""
|
5 |
+
Machine learning (ML) is an umbrella term for solving problems for which development of algorithms by human programmers would be cost-prohibitive, and instead the problems are solved by helping machines 'discover' their 'own' algorithms, without needing to be explicitly told what to do by any human-developed algorithms.
|
6 |
+
Recently, generative artificial neural networks have been able to surpass results of many previous approaches. Machine learning approaches have been applied to large language models, computer vision, speech recognition, email filtering, agriculture and medicine, where it is too costly to develop algorithms to perform the needed tasks.
|
7 |
+
The mathematical foundations of ML are provided by mathematical optimization (mathematical programming) methods. Data mining is a related (parallel) field of study, focusing on exploratory data analysis through unsupervised learning.
|
8 |
+
ML is known in its application across business problems under the name predictive analytics. Although not all machine learning is statistically-based, computational statistics is an important source of the field's methods.
|
9 |
+
""",]
|
10 |
+
|
11 |
+
def create_wc(text):
|
12 |
+
"""
|
13 |
+
Generate wordcloud
|
14 |
+
"""
|
15 |
+
if not text:
|
16 |
+
pass
|
17 |
+
else:
|
18 |
+
wordcloud = WordCloud(collocations=False).generate(text.lower())
|
19 |
+
return wordcloud.to_image()
|
20 |
+
|
21 |
+
interface_wc = gr.Interface(create_wc,
|
22 |
+
inputs=gr.Textbox(placeholder="Insert text here", label='Text'),
|
23 |
+
outputs=[gr.Image(type="pil", label="Wordcloud", show_label=False)],
|
24 |
+
examples = wc_example,
|
25 |
+
title="WordCloud builder",
|
26 |
+
description="Create a WordCloud from given text.",
|
27 |
+
css="footer{display:none !important}",
|
28 |
+
allow_flagging="never"
|
29 |
+
)
|