Spaces:
Sleeping
Sleeping
Attempted to append the respond with a translation dataset for Vietnamese reponses.
Browse files
app.py
CHANGED
|
@@ -1,14 +1,15 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
-
|
| 4 |
from datasets import load_dataset
|
| 5 |
|
| 6 |
-
"""
|
| 7 |
-
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
|
| 8 |
-
"""
|
| 9 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 10 |
dataset = load_dataset("JustKiddo/KiddosVault")
|
|
|
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
def respond(
|
| 14 |
message,
|
|
@@ -38,19 +39,18 @@ def respond(
|
|
| 38 |
top_p=top_p,
|
| 39 |
):
|
| 40 |
token = message.choices[0].delta.content
|
| 41 |
-
|
| 42 |
response += token
|
| 43 |
yield response
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
demo = gr.ChatInterface(
|
| 49 |
respond,
|
| 50 |
additional_inputs=[
|
| 51 |
gr.Textbox(value="You are a professional Mental Healthcare Chatbot.", label="System message"),
|
| 52 |
gr.Slider(minimum=1, maximum=2048, value=2048, step=1, label="Max new tokens"),
|
| 53 |
-
gr.Slider(minimum=0.1, maximum
|
| 54 |
gr.Slider(
|
| 55 |
minimum=0.1,
|
| 56 |
maximum=1.0,
|
|
@@ -61,6 +61,5 @@ demo = gr.ChatInterface(
|
|
| 61 |
],
|
| 62 |
)
|
| 63 |
|
| 64 |
-
|
| 65 |
if __name__ == "__main__":
|
| 66 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
|
|
|
| 3 |
from datasets import load_dataset
|
| 4 |
|
|
|
|
|
|
|
|
|
|
| 5 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 6 |
dataset = load_dataset("JustKiddo/KiddosVault")
|
| 7 |
+
translation = load_dataset("IWSLT/mt_eng_vietnamese")
|
| 8 |
|
| 9 |
+
def translate_text(text, translation_dataset):
|
| 10 |
+
# Assuming the translation dataset has a method to translate text
|
| 11 |
+
translated_text = translation_dataset['train'][0]['translation']['vi'] # Example translation
|
| 12 |
+
return translated_text
|
| 13 |
|
| 14 |
def respond(
|
| 15 |
message,
|
|
|
|
| 39 |
top_p=top_p,
|
| 40 |
):
|
| 41 |
token = message.choices[0].delta.content
|
|
|
|
| 42 |
response += token
|
| 43 |
yield response
|
| 44 |
|
| 45 |
+
translated_response = translate_text(response, translation)
|
| 46 |
+
yield response + "\n\nTranslation: " + translated_response
|
| 47 |
+
|
| 48 |
demo = gr.ChatInterface(
|
| 49 |
respond,
|
| 50 |
additional_inputs=[
|
| 51 |
gr.Textbox(value="You are a professional Mental Healthcare Chatbot.", label="System message"),
|
| 52 |
gr.Slider(minimum=1, maximum=2048, value=2048, step=1, label="Max new tokens"),
|
| 53 |
+
gr.Slider(minimum=0.1, maximum 4.0, value=1, step=0.1, label="Temperature"),
|
| 54 |
gr.Slider(
|
| 55 |
minimum=0.1,
|
| 56 |
maximum=1.0,
|
|
|
|
| 61 |
],
|
| 62 |
)
|
| 63 |
|
|
|
|
| 64 |
if __name__ == "__main__":
|
| 65 |
demo.launch()
|