Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,13 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
|
|
3 |
|
4 |
"""
|
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 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
|
|
|
|
8 |
|
9 |
|
10 |
def respond(
|
@@ -15,6 +18,9 @@ def respond(
|
|
15 |
temperature,
|
16 |
top_p,
|
17 |
):
|
|
|
|
|
|
|
18 |
messages = [{"role": "system", "content": system_message}]
|
19 |
|
20 |
for val in history:
|
@@ -25,19 +31,17 @@ def respond(
|
|
25 |
|
26 |
messages.append({"role": "user", "content": message})
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
for message in client.chat_completion(
|
31 |
messages,
|
32 |
max_tokens=max_tokens,
|
33 |
stream=True,
|
34 |
temperature=temperature,
|
35 |
top_p=top_p,
|
36 |
-
)
|
37 |
-
token = message.choices[0].delta.content
|
38 |
|
39 |
-
|
40 |
-
|
|
|
41 |
|
42 |
|
43 |
"""
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
+
from deep_translator import GoogleTranslator
|
4 |
|
5 |
"""
|
6 |
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
|
7 |
"""
|
8 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
9 |
+
translator_vi2en = GoogleTranslator(source='vi', target='en')
|
10 |
+
translator_en2vi = GoogleTranslator(source='en', target='vi')
|
11 |
|
12 |
|
13 |
def respond(
|
|
|
18 |
temperature,
|
19 |
top_p,
|
20 |
):
|
21 |
+
|
22 |
+
message_en = translator_vi2en.translate(message)
|
23 |
+
|
24 |
messages = [{"role": "system", "content": system_message}]
|
25 |
|
26 |
for val in history:
|
|
|
31 |
|
32 |
messages.append({"role": "user", "content": message})
|
33 |
|
34 |
+
respnse = client.text_generation(
|
|
|
|
|
35 |
messages,
|
36 |
max_tokens=max_tokens,
|
37 |
stream=True,
|
38 |
temperature=temperature,
|
39 |
top_p=top_p,
|
40 |
+
)
|
|
|
41 |
|
42 |
+
response_vi = translator_en2vi.translate(response)
|
43 |
+
|
44 |
+
return response_vi
|
45 |
|
46 |
|
47 |
"""
|