David commited on
Commit
8015341
·
1 Parent(s): 8ba6850

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ from pysentimiento.preprocessing import preprocess_tweet
4
+
5
+ pl = pipeline("ner", tokenizer="google/electra-base-discriminator", model="Recognai/veganuary_ner", aggregation_strategy="first")
6
+
7
+ def ner(text):
8
+ text = preprocess_tweet(text)
9
+ predictions = pl(text)
10
+ return "\n".join([pred["word"] for pred in predictions if pred["entity_group"] == "LABEL_1"])
11
+
12
+ iface = gr.Interface(
13
+ ner,
14
+ gr.inputs.Textbox(placeholder="copy&paste your veganuary tweet here ...", label="Tweet"),
15
+ gr.outputs.Textbox(label="List of detected food mentions in the tweet"),
16
+ examples=[
17
+ ["Fruit is delicious AND healthy. Brighten up your plate & palate with fresh watermelon, Greek yoghurt & berries, smashed avocado or lime added to water. A piece of #fruit a day keeps the doctor away! #Veganuary2022 #vegetarian #plantbased #ActiveHealthMatters #PerspicuousHealth https://t.co/BvLUoVnPCh"]
18
+ ],
19
+ allow_flagging=False,
20
+ title="Veganuary NER",
21
+ description="Extract food entities from veganuary tweets 😋",
22
+ )
23
+
24
+ iface.launch(share=False)