File size: 925 Bytes
e05abd0
 
 
 
ffacbee
 
e05abd0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d6539e5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from transformers import BertTokenizerFast,TFBertForSequenceClassification,TextClassificationPipeline
import numpy as np
import tensorflow as tf
import gradio as gr 


model_path = "leadingbridge/sentiment-analysis"
tokenizer = BertTokenizerFast.from_pretrained(model_path)
model = TFBertForSequenceClassification.from_pretrained(model_path, id2label={0: 'negative', 1: 'positive'} )

def sentiment_analysis(text):
  pipe = TextClassificationPipeline(model=model, tokenizer=tokenizer)
  result = pipe(text)
  return result


with gr.Blocks() as demo:
    gr.Markdown("Choose the Chinese NLP model you want to use.")
    with gr.Tab("Sentiment Analysis"):
        text_button = gr.Button("proceed")          
        text_button.click(fn=sentiment_analysis,inputs=gr.Textbox(placeholder="Enter a positive or negative sentence here..."),
                 outputs=gr.Textbox(label="Sentiment Analysis"))

demo.launch(share=True)