Spaces:
Runtime error
Runtime error
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() | |