matteopilotto commited on
Commit
69b9c76
·
1 Parent(s): ebbe695

Add application file

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import gradio as gr
3
+ from huggingface_hub import from_pretrained_fastai
4
+
5
+ # load model
6
+ repo_id = 'matteopilotto/deberta-v3-base-tweet_eval-emotion'
7
+ load_learner = from_pretrained_fastai(repo_id)
8
+
9
+ # define labels
10
+ labels_url = 'https://huggingface.co/matteopilotto/deberta-v3-base-tweet_eval-emotion/raw/main/class_names.txt'
11
+ labels = requests.get(labels_url).text.splitlines()
12
+
13
+ # define function to pass to gradio.Interface
14
+ def predict(prompt):
15
+ out = load_learner.blurr_predict(prompt)[0]
16
+ confidences = {label: prob for label, prob in zip(labels, out['probs'])}
17
+ return confidences
18
+
19
+ # define input texbox to pass to gradio.Interface
20
+ textbox = gr.Textbox(
21
+ label='input',
22
+ placeholder=None,
23
+ lines=2
24
+ )
25
+
26
+ # define exables to pass to gradio.Interface
27
+ examples = ["hey @user #fields in #skibbereen give your online delivery service a horrible name. 1.5 hours late on the 1 hour delivery window.",
28
+ "when you only meet each other once at an interview and you recognise each other on the streets 🙆 i don't even know what's your name 😂"]
29
+
30
+ gr.Interface(
31
+ fn=predict,
32
+ inputs=textbox,
33
+ outputs=gr.Label(),
34
+ title='Emotion in tweets',
35
+ description="""<center><img src="https://huggingface.co/matteopilotto/deberta-v3-base-tweet_eval-emotion/resolve/main/emoji_image.png" width=600px></center>""",
36
+ examples = examples,
37
+ live=True
38
+ ).launch()