matteopilotto commited on
Commit
1d4ad2c
β€’
1 Parent(s): 177e45f

Add app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import gradio as gr
3
+ from huggingface_hub import from_pretrained_fastai
4
+ import torch
5
+ from fastai.text.all import *
6
+ from blurr.text.data.all import *
7
+ from blurr.text.modeling.all import *
8
+
9
+ # load model
10
+ repo_id = 'matteopilotto/deberta-v3-base-tweet_eval-emotion'
11
+ load_learner = from_pretrained_fastai(repo_id)
12
+
13
+ # define labels
14
+ labels_url = 'https://huggingface.co/matteopilotto/deberta-v3-base-tweet_eval-emotion/raw/main/class_names.txt'
15
+ labels = requests.get(labels_url).text.splitlines()
16
+
17
+ # define function to pass to gradio.Interface
18
+ def predict(prompt):
19
+ out = load_learner.blurr_predict(prompt)[0]
20
+ confidences = {label: prob for label, prob in zip(labels, out['probs'])}
21
+ return confidences
22
+
23
+ # define input texbox to pass to gradio.Interface
24
+ textbox = gr.Textbox(
25
+ label='input',
26
+ placeholder=None,
27
+ lines=2
28
+ )
29
+
30
+ # define exables to pass to gradio.Interface
31
+ examples = ["hey @user #fields in #skibbereen give your online delivery service a horrible name. 1.5 hours late on the 1 hour delivery window.",
32
+ "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 πŸ˜‚"]
33
+
34
+ gr.Interface(
35
+ fn=predict,
36
+ inputs=textbox,
37
+ outputs=gr.Label(),
38
+ title='Emotion in tweets',
39
+ description="""<center><img src="https://huggingface.co/matteopilotto/deberta-v3-base-tweet_eval-emotion/resolve/main/emoji_image.png" width=600px></center>""",
40
+ examples = examples,
41
+ live=True
42
+ ).launch()