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