Spaces:
Runtime error
Runtime error
Adding initial template
Browse files- app.py +30 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Workaround to install the lib without "setup.py"
|
| 2 |
+
import sys
|
| 3 |
+
from git import Repo
|
| 4 |
+
Repo.clone_from("https://github.com/dimitreOliveira/hub.git", "./hub")
|
| 5 |
+
sys.path.append("/hub")
|
| 6 |
+
|
| 7 |
+
import gradio as gr
|
| 8 |
+
import tensorflow as tf
|
| 9 |
+
from hub.tensorflow_hub.hf_utils import pull_from_hub
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def model_fn(preprocessor, encoder):
|
| 13 |
+
text_input = tf.keras.layers.Input(shape=(), dtype=tf.string)
|
| 14 |
+
encoder_inputs = preprocessor(text_input)
|
| 15 |
+
outputs = encoder(encoder_inputs)
|
| 16 |
+
pooled_output = outputs["pooled_output"]
|
| 17 |
+
return tf.keras.Model(text_input, pooled_output)
|
| 18 |
+
|
| 19 |
+
def predict_fn(text):
|
| 20 |
+
embed = model(tf.constant([text]))[0].numpy()
|
| 21 |
+
return embed
|
| 22 |
+
|
| 23 |
+
preprocessor = pull_from_hub(repo_id="Dimitre/bert_en_cased_preprocess")
|
| 24 |
+
encoder = pull_from_hub(repo_id="Dimitre/bert_en_cased_L-12_H-768_A-12")
|
| 25 |
+
model = model_fn(preprocessor, encoder)
|
| 26 |
+
|
| 27 |
+
iface = gr.Interface(fn=predict_fn,
|
| 28 |
+
inputs=gr.Textbox(lines=2, placeholder="Text input here...", label="Text"),
|
| 29 |
+
outputs="text")
|
| 30 |
+
iface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
GitPython
|
| 2 |
+
tensorflow_hub
|