Spaces:
Runtime error
Runtime error
chore: adding app
Browse files- app.py +34 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import tensorflow as tf
|
| 4 |
+
import tensorflow_text as tf_text
|
| 5 |
+
from huggingface_hub import Repository
|
| 6 |
+
|
| 7 |
+
repo = Repository(
|
| 8 |
+
local_dir="nmt-transformer",
|
| 9 |
+
clone_from="pyimagesearch/nmt-transformer",
|
| 10 |
+
use_auth_token=os.environ.get("token")
|
| 11 |
+
)
|
| 12 |
+
reloaded = tf.saved_model.load("nmt-transformer/translator")
|
| 13 |
+
|
| 14 |
+
title="Neural Machine Translation with Transformer"
|
| 15 |
+
description="The model used here is a POC and not SOTA on NMT."
|
| 16 |
+
|
| 17 |
+
examples=["how are you?", "good morning.", "how is your health?"]
|
| 18 |
+
|
| 19 |
+
def get_translation(sentence):
|
| 20 |
+
result = reloaded(
|
| 21 |
+
sentence=tf.constant([sentence])
|
| 22 |
+
).numpy()[0].decode()
|
| 23 |
+
return result
|
| 24 |
+
|
| 25 |
+
nmt_space = gr.Interface(
|
| 26 |
+
fn=get_translation,
|
| 27 |
+
inputs=gr.Textbox(label="English Sentence"),
|
| 28 |
+
outputs=gr.Textbox(label="French Sentence"),
|
| 29 |
+
title=title,
|
| 30 |
+
description=description,
|
| 31 |
+
examples=examples,
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
nmt_space.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tensorflow
|
| 2 |
+
tensorflow-text
|
| 3 |
+
huggingface_hub
|