leadingbridge commited on
Commit
1acd752
Β·
1 Parent(s): 3bd86d9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import BertTokenizerFast,TFBertForSequenceClassification,TextClassificationPipeline
2
+ import numpy as np
3
+ import tensorflow as tf
4
+ import gradio as gr
5
+
6
+
7
+ model_path = "leadingbridge/sentiment-analysis"
8
+ tokenizer = BertTokenizerFast.from_pretrained(model_path)
9
+ model = TFBertForSequenceClassification.from_pretrained(model_path, id2label={0: 'negative', 1: 'positive'} )
10
+
11
+ def sentiment_analysis(text):
12
+ pipe = TextClassificationPipeline(model=model, tokenizer=tokenizer)
13
+ result = pipe(text)
14
+ return result
15
+
16
+
17
+ with gr.Blocks() as demo:
18
+ gr.Markdown("Choose the Chinese NLP model you want to use.")
19
+ with gr.Tab("Sentiment Analysis"):
20
+ text_button = gr.Button("proceed")
21
+ text_button.click(fn=sentiment_analysis,inputs=gr.Textbox(placeholder="Enter a positive or negative sentence here..."),
22
+ outputs=gr.Textbox(label="Sentiment Analysis"))
23
+
24
+ demo.launch()