File size: 1,208 Bytes
ebb2014
4c5f8db
8e4d744
ebb2014
89bf2ed
11c4f8e
9fb84ef
8e4d744
0fd5020
b94fd1c
ebb2014
 
 
20106f5
0a214bf
20106f5
a00765b
0a214bf
ebb2014
8e4d744
 
 
0a214bf
8e4d744
 
 
 
 
 
 
 
ebb2014
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import gradio as gr
import torch
from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification, DistilBertForSequenceClassification

modelName = "Pendrokar/TorchMoji"

distil_tokenizer = AutoTokenizer.from_pretrained(modelName)
distil_model = AutoModelForSequenceClassification.from_pretrained(modelName, problem_type="multi_label_classification")

pipeline = pipeline(task="text-classification", model=distil_model, tokenizer=distil_tokenizer)

def predict(deepmoji_analysis):
    predictions = pipeline(deepmoji_analysis)

    output_text = "\n"
    for p in predictions:
        output_text += p['label'] + ' (' + str(p['score']) + ")\n"
    return str(distil_tokenizer(deepmoji_analysis)["input_ids"]) + output_text

gradio_app = gr.Interface(
    fn=predict,
    inputs="text",
    outputs="text",
    examples=[
        "This GOT show just remember LOTR times!",
        "Man, can't believe that my 30 days of training just got a NaN loss",
        "I couldn't see 3 Tom Hollands coming...",
        "There is nothing better than a soul-warming coffee in the morning",
        "I fear the vanishing gradient", "deberta"
    ]
)

if __name__ == "__main__":
    gradio_app.launch()