Spaces:
Running
Running
File size: 1,062 Bytes
ebb2014 4c5f8db b2eb1be ebb2014 89bf2ed 11c4f8e 9fb84ef 4c5f8db 9fb84ef 4c5f8db 0fd5020 4c5f8db b94fd1c 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 |
import gradio as gr
import torch
from transformers import pipeline, AutoTokenizer, DistilBertForSequenceClassification
modelName = "Pendrokar/TorchMoji"
distil_tokenizer = AutoTokenizer.from_pretrained(modelName)
#distil_tokenizer.save_pretrained("./model/")
#distil_model = DistilBertForSequenceClassification.from_pretrained(modelName, problem_type="multi_label_classification")
distil_model = DistilBertForMultilabelSequenceClassification.from_pretrained("colinryan/hf-deepmoji")
#num_labels = len(model.config.id2label)
#pipeline = pipeline(task="text-classification", model=distil_model, tokenizer=distil_tokenizer)
pipeline = pipeline(task="text-classification", model=distil_model, tokenizer=distil_tokenizer)
#pipeline = pipeline(task="text-classification", model=modelName)
def predict(deepmoji_analysis):
predictions = pipeline(deepmoji_analysis)
return deepmoji_analysis, {p["label"]: p["score"] for p in predictions}
gradio_app = gr.Interface(fn=predict, inputs="text", outputs="text")
if __name__ == "__main__":
gradio_app.launch() |