Spaces:
Runtime error
Runtime error
Commit
·
7b1e59b
1
Parent(s):
d5b7569
Fix with https://github.com/jeanigarcia/ernie_demo_local/blob/master/app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,19 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
import
|
| 4 |
-
import sklearn
|
| 5 |
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from ernie.ernie import SentenceClassifier
|
| 3 |
+
from ernie import helper
|
|
|
|
| 4 |
|
| 5 |
+
file_list=['config.json', 'tf_model.h5', 'tokenizer.json', 'vocab.txt', 'special_tokens_map.json', 'tokenizer_config.json']
|
| 6 |
|
| 7 |
+
for f in file_list:
|
| 8 |
+
helper.download_from_hub(repo_id='jeang/bert-finetuned-sentence-classification-toy', filename=f, cache_dir='model/')
|
| 9 |
+
|
| 10 |
+
classifier = SentenceClassifier(model_path='model/', max_length=128, labels_no=2)
|
| 11 |
|
| 12 |
+
def classify(sentence):
|
| 13 |
+
probability = classifier.predict_one(sentence)[1]
|
| 14 |
+
|
| 15 |
+
return 'probability = ' + str(probability) + ' (' + ('positive' if probability >= 0.5 else 'negative') + ')'
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
iface = gr.Interface(fn=classify, inputs="text", outputs="text")
|
| 19 |
+
iface.launch()
|