Spaces:
Runtime error
Runtime error
add both translation and langid endpoints
Browse files- __pycache__/app.cpython-37.pyc +0 -0
- app.py +21 -7
__pycache__/app.cpython-37.pyc
ADDED
Binary file (913 Bytes). View file
|
|
app.py
CHANGED
@@ -7,18 +7,32 @@ description = """"""
|
|
7 |
article = "Check out [the original repo](https://huggingface.co/language-tools/language-translation) that this demo is based off of."
|
8 |
|
9 |
|
10 |
-
|
|
|
11 |
ACCESS_TOKEN = os.environ.get("ACCESS_TOKEN")
|
|
|
12 |
headers = {"Authorization": f"Bearer {ACCESS_TOKEN}"}
|
13 |
|
|
|
14 |
def query(payload):
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
gr.Interface(
|
19 |
-
|
20 |
-
|
21 |
-
outputs=
|
|
|
|
|
|
|
22 |
title=title,
|
23 |
description=description,
|
24 |
article=article
|
|
|
7 |
article = "Check out [the original repo](https://huggingface.co/language-tools/language-translation) that this demo is based off of."
|
8 |
|
9 |
|
10 |
+
TRANSLATION_API_URL = "https://api-inference.huggingface.co/models/t5-base"
|
11 |
+
LANG_ID_API_URL = "https://noe30ht5sav83xm1.us-east-1.aws.endpoints.huggingface.cloud"
|
12 |
ACCESS_TOKEN = os.environ.get("ACCESS_TOKEN")
|
13 |
+
# ACCESS_TOKEN = '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'
|
14 |
headers = {"Authorization": f"Bearer {ACCESS_TOKEN}"}
|
15 |
|
16 |
+
|
17 |
def query(payload):
|
18 |
+
translation_response = requests.post(TRANSLATION_API_URL, headers=headers, json={
|
19 |
+
"inputs": payload, "wait_for_model": True})
|
20 |
+
translation = translation_response.json()[0]['translation_text']
|
21 |
+
|
22 |
+
lang_id_response = requests.post(LANG_ID_API_URL, headers=headers, json={
|
23 |
+
"inputs": payload, "wait_for_model": True})
|
24 |
+
lang_id = lang_id_response.json()[0][0]
|
25 |
+
|
26 |
+
return [lang_id, translation]
|
27 |
+
|
28 |
+
|
29 |
gr.Interface(
|
30 |
+
query,
|
31 |
+
gr.Textbox(lines=2),
|
32 |
+
outputs=[
|
33 |
+
gr.Textbox(lines=3, label="Detected Language"),
|
34 |
+
gr.Textbox(lines=3, label="Translation")
|
35 |
+
],
|
36 |
title=title,
|
37 |
description=description,
|
38 |
article=article
|