Spaces:
Runtime error
Runtime error
Commit
Β·
e05abd0
1
Parent(s):
d1ddd40
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,24 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
def greet(name):
|
| 4 |
-
return "Hello " + name + "!!"
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|