File size: 757 Bytes
4f29d58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6e37b04
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import gradio as gr
import tensorflow as tf
import tensorflow_text as text



from huggingface_hub import from_pretrained_keras

model = from_pretrained_keras("weightedhuman/fine-tuned-bert-news-classifier")


def get_sentiment_score(text):
  if text is not None:
    serving_results = model \
                .signatures['serving_default'](tf.constant(text))


    serving_results = tf.sigmoid(serving_results['classifier'])
        
    serving_results_np = serving_results.numpy()

    for i in range(len(serving_results_np)):

        output_value = serving_results_np[i][0]

        return float(output_value)
  else:
    return ""

intf = gr.Interface(
    fn = get_sentiment_score,
    inputs = gr.Textbox(),
    outputs = gr.Label()
)

intf.launch()