File size: 1,001 Bytes
23df2ff
c125186
 
a6ca1ac
c125186
a6ca1ac
c125186
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
290ab60
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
import torch
import gradio as gr
from transformers import pipeline
from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
pipe = pipeline("text-classification", model="./model", tokenizer=tokenizer)

def is_depression(txt):
    pred_dict = pipe(txt)
    for d in pred_dict:
        d['label'] = False if d['label'] == 'LABEL_0' else True
    return [{item['label']: item['score']} for item in pred_dict]

def predict_gradio(txt):
    return is_depression(txt)[0]

title = "Depression Classifier"
description = "A NLP classifier trained with Hugging Face Transformers."
interpretation='default'
examples = ["Today is a great day!", "I have no motivation to do anything. I feel useless."]
enable_queue=True

gr.Interface(fn=predict_gradio, inputs=gr.inputs.Textbox(label="Text"), outputs=gr.outputs.Label(label="is_depression"), title=title,description=description,examples=examples,interpretation=interpretation,enable_queue=enable_queue).launch()