Sakalti commited on
Commit
c351726
1 Parent(s): 7b9927c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -15
app.py CHANGED
@@ -1,11 +1,12 @@
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(
11
  message,
@@ -37,28 +38,31 @@ def respond(
37
  token = message.choices[0].delta.content
38
 
39
  response += token
40
- yield response
 
 
41
 
42
-
43
- """
44
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
45
- """
46
  demo = gr.ChatInterface(
47
  respond,
48
  additional_inputs=[
49
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
50
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
51
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
52
  gr.Slider(
53
  minimum=0.1,
54
  maximum=1.0,
55
  value=0.95,
56
  step=0.05,
57
- label="Top-p (nucleus sampling)",
58
  ),
59
  ],
 
 
 
 
 
60
  )
61
 
62
-
63
  if __name__ == "__main__":
64
- demo.launch()
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
+ from googletrans import Translator
4
 
5
+ # Googletransの初期化
6
+ translator = Translator()
 
 
7
 
8
+ # Hugging FaceのInferenceClientの初期化
9
+ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
10
 
11
  def respond(
12
  message,
 
38
  token = message.choices[0].delta.content
39
 
40
  response += token
41
+ # レスポンスを日本語に翻訳
42
+ translated_response = translator.translate(response, src='en', dest='ja').text
43
+ yield translated_response
44
 
45
+ # GUIのラベルを日本語に変更
 
 
 
46
  demo = gr.ChatInterface(
47
  respond,
48
  additional_inputs=[
49
+ gr.Textbox(value="あなたはフレンドリーなチャットボットです。", label="システムメッセージ"),
50
+ gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="新しいトークンの最大数"),
51
+ gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="温度"),
52
  gr.Slider(
53
  minimum=0.1,
54
  maximum=1.0,
55
  value=0.95,
56
  step=0.05,
57
+ label="Top-p (核サンプリング)",
58
  ),
59
  ],
60
+ additional_inputs_text="カスタマイズオプション",
61
+ chatbot_placeholder="ここにチャットが表示されます。",
62
+ input_placeholder="メッセージを入力してください...",
63
+ title="チャットボット",
64
+ description="このチャットボットは英語を日本語に翻訳して対応します。",
65
  )
66
 
 
67
  if __name__ == "__main__":
68
+ demo.launch()