leadingbridge commited on
Commit
a0f20a6
Β·
1 Parent(s): 23c6e27

Create app.py

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