Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
intf = gr.Interface(
|
| 2 |
fn = get_sentiment_score,
|
| 3 |
inputs = gr.Textbox(),
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import tensorflow_text as text
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
from huggingface_hub import from_pretrained_keras
|
| 8 |
+
|
| 9 |
+
model = from_pretrained_keras("weightedhuman/fine-tuned-bert-news-classifier")
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def get_sentiment_score(text):
|
| 13 |
+
if text is not None:
|
| 14 |
+
serving_results = model \
|
| 15 |
+
.signatures['serving_default'](tf.constant(text))
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
serving_results = tf.sigmoid(serving_results['classifier'])
|
| 19 |
+
|
| 20 |
+
serving_results_np = serving_results.numpy()
|
| 21 |
+
|
| 22 |
+
for i in range(len(serving_results_np)):
|
| 23 |
+
|
| 24 |
+
output_value = serving_results_np[i][0]
|
| 25 |
+
|
| 26 |
+
return float(output_value)
|
| 27 |
+
else:
|
| 28 |
+
return ""
|
| 29 |
+
|
| 30 |
intf = gr.Interface(
|
| 31 |
fn = get_sentiment_score,
|
| 32 |
inputs = gr.Textbox(),
|