File size: 679 Bytes
617d6e7
 
 
 
 
1f45a5d
617d6e7
 
 
c4cc2f7
 
 
 
 
 
617d6e7
c4cc2f7
617d6e7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import gradio as gr
import torch
from transformers import AutoModelForSequenceClassification,AutoTokenizer,pipeline

model = AutoModelForSequenceClassification.from_pretrained('SeyedAli/Persian-Text-Sentiment-Bert-V1')
tokenizer = AutoTokenizer.from_pretrained('SeyedAli/Persian-Text-Sentiment-Bert-V1',add_special_token=True)

def Sentiment(text):
    pipline = pipeline(task="text-classification", model=model, tokenizer=tokenizer)
    preds=pipline(text)
    # return output
    outputs = {}
    for p in preds:
        outputs[p["label"]] = p["score"]
    return outputs

iface = gr.Interface(fn=Sentiment, inputs="text", outputs=gr.outputs.Label())
iface.launch(share=False)