Spaces:
Runtime error
Runtime error
chore: adding app and requirements
Browse files- app.py +26 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-bahdanau-attention",
|
9 |
+
clone_from="pyimagesearch/nmt-bahdanau-attention",
|
10 |
+
use_auth_token=os.environ.get("token")
|
11 |
+
)
|
12 |
+
reloaded = tf.saved_model.load("nmt-bahdanau-attention/translator")
|
13 |
+
|
14 |
+
def get_translation(sentence):
|
15 |
+
result = reloaded.translate(
|
16 |
+
sourceText=tf.constant([sentence])
|
17 |
+
)["text"].numpy()[0].decode()
|
18 |
+
return result
|
19 |
+
|
20 |
+
nmt_space = gr.Interface(
|
21 |
+
fn=get_translation,
|
22 |
+
inputs="text",
|
23 |
+
outputs="text"
|
24 |
+
)
|
25 |
+
|
26 |
+
nmt_space.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
tensorflow
|
2 |
+
tensorflow-text
|
3 |
+
huggingface_hub
|