Spaces:
Running
Running
Commit
·
2b1cc8c
1
Parent(s):
4b9181d
Changes
Browse files
app.py
CHANGED
@@ -5,7 +5,8 @@ from huggingface_hub import InferenceClient
|
|
5 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
"""
|
7 |
englishToFinnishClient = InferenceClient("Helsinki-NLP/opus-mt-en-fi")
|
8 |
-
|
|
|
9 |
|
10 |
|
11 |
def respond(
|
@@ -18,34 +19,54 @@ def respond(
|
|
18 |
sourceLanguage,
|
19 |
targetLanguage
|
20 |
):
|
21 |
-
|
|
|
22 |
|
23 |
-
|
|
|
|
|
24 |
|
25 |
print("the text",message, 'the source',sourceLanguage,"the target",targetLanguage)
|
|
|
|
|
26 |
|
27 |
|
28 |
-
if(
|
29 |
-
|
30 |
message,
|
31 |
#max_new_tokens=100
|
32 |
tgt_lang= targetLanguage,
|
33 |
src_lang=sourceLanguage
|
34 |
)
|
35 |
|
36 |
-
|
|
|
|
|
|
|
|
|
37 |
|
38 |
-
|
|
|
39 |
else:
|
40 |
text="Translate to "f"{targetLanguage}: "f"{message}"
|
41 |
print("the text",text)
|
42 |
-
|
43 |
-
|
|
|
44 |
)
|
45 |
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
-
|
49 |
|
50 |
|
51 |
"""
|
|
|
5 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
"""
|
7 |
englishToFinnishClient = InferenceClient("Helsinki-NLP/opus-mt-en-fi")
|
8 |
+
googleClient = InferenceClient("google/flan-t5-large")#"facebook/nllb-200-1.3B")#"facebook/nllb-200-1.3B")
|
9 |
+
finnishToEnglishClient = InferenceClient("Helsinki-NLP/opus-mt-fi-en")
|
10 |
|
11 |
|
12 |
def respond(
|
|
|
19 |
sourceLanguage,
|
20 |
targetLanguage
|
21 |
):
|
22 |
+
toFinnish=targetLanguage=='Finnish' and sourceLanguage=="English"
|
23 |
+
fromFinnish=targetLanguage=='English' and sourceLanguage=="Finnish"
|
24 |
|
25 |
+
#adminClient=englishToFinnishClient if(toFinnish)else googleClient
|
26 |
+
|
27 |
+
#candidateClient=finnishToEnglishClient if(fromFinnish)else googleClient
|
28 |
|
29 |
print("the text",message, 'the source',sourceLanguage,"the target",targetLanguage)
|
30 |
+
|
31 |
+
response=''
|
32 |
|
33 |
|
34 |
+
if(toFinnish):
|
35 |
+
fiResponse= englishToFinnishClient.translation(
|
36 |
message,
|
37 |
#max_new_tokens=100
|
38 |
tgt_lang= targetLanguage,
|
39 |
src_lang=sourceLanguage
|
40 |
)
|
41 |
|
42 |
+
text="Translate to "f"{targetLanguage}: "f"{message}"
|
43 |
+
print("the text",text)
|
44 |
+
googResponse= googleClient.text_generation(
|
45 |
+
text
|
46 |
+
)
|
47 |
|
48 |
+
response=f"{googResponse}<b>Translation 2</b><br/> {fiResponse.translation_text}"
|
49 |
+
|
50 |
else:
|
51 |
text="Translate to "f"{targetLanguage}: "f"{message}"
|
52 |
print("the text",text)
|
53 |
+
|
54 |
+
googleResponse= googleClient.text_generation(
|
55 |
+
text
|
56 |
)
|
57 |
|
58 |
+
response=f"{googleResponse}"
|
59 |
+
|
60 |
+
if(fromFinnish):
|
61 |
+
fiResponse=finnishToEnglishClient.translation(
|
62 |
+
message,
|
63 |
+
tgt_lang= targetLanguage,
|
64 |
+
src_lang=sourceLanguage
|
65 |
+
)
|
66 |
+
|
67 |
+
response+=f'<b>Translation 2</b><br/>{fiResponse.translation_text}'
|
68 |
|
69 |
+
response
|
70 |
|
71 |
|
72 |
"""
|