Spaces:
Runtime error
Runtime error
File size: 1,028 Bytes
8d0e09f |
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 |
# Workaround to install the lib without "setup.py"
import sys
from git import Repo
Repo.clone_from("https://github.com/dimitreOliveira/hub.git", "./hub")
sys.path.append("/hub")
import gradio as gr
import tensorflow as tf
from hub.tensorflow_hub.hf_utils import pull_from_hub
def model_fn(preprocessor, encoder):
text_input = tf.keras.layers.Input(shape=(), dtype=tf.string)
encoder_inputs = preprocessor(text_input)
outputs = encoder(encoder_inputs)
pooled_output = outputs["pooled_output"]
return tf.keras.Model(text_input, pooled_output)
def predict_fn(text):
embed = model(tf.constant([text]))[0].numpy()
return embed
preprocessor = pull_from_hub(repo_id="Dimitre/bert_en_cased_preprocess")
encoder = pull_from_hub(repo_id="Dimitre/bert_en_cased_L-12_H-768_A-12")
model = model_fn(preprocessor, encoder)
iface = gr.Interface(fn=predict_fn,
inputs=gr.Textbox(lines=2, placeholder="Text input here...", label="Text"),
outputs="text")
iface.launch() |