File size: 738 Bytes
0b42139
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
import gradio as gr

tokenizer = AutoTokenizer.from_pretrained("jarvisx17/japanese-sentiment-analysis")
model = AutoModelForSequenceClassification.from_pretrained("jarvisx17/japanese-sentiment-analysis")

classes = ["negative", "positive"]

def predict(sequence):
  input = tokenizer(sequence, return_tensors="pt")
  classification_logits = model(**input).logits
  results = torch.softmax(classification_logits, dim=1).tolist()[0]

  output = classes[0] + ":" + str(int(round(results[0] * 100))) + "\n"
  output += classes[1] + ":" + str(int(round(results[1] * 100)))

  return output

gr.Interface(fn=predict, inputs="text", outputs="text").launch()