MakiAi commited on
Commit
6480777
·
verified ·
1 Parent(s): f713d11

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -18
app.py CHANGED
@@ -6,19 +6,21 @@ from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStream
6
  import gradio as gr
7
  from threading import Thread
8
 
 
9
  MODELS = {
10
- "Phi-3.5-mini": "microsoft/Phi-3.5-mini-instruct",
11
  "Borea-Phi-3.5-mini-Jp": "AXCXEPT/Borea-Phi-3.5-mini-Instruct-Jp",
12
- "EZO-Common-9B": "HODACHI/EZO-Common-9B-gemma-2-it"
 
13
  }
14
 
15
  HF_TOKEN = os.environ.get("HF_TOKEN", None)
16
 
17
- TITLE = "<h1><center>Multi-Model Chat Interface</center></h1>"
 
18
 
19
  PLACEHOLDER = """
20
  <center>
21
- <p>Hi, I'm an AI assistant. Ask me anything.</p>
22
  </center>
23
  """
24
 
@@ -40,7 +42,8 @@ quantization_config = BitsAndBytesConfig(
40
  load_in_4bit=True,
41
  bnb_4bit_compute_dtype=torch.bfloat16,
42
  bnb_4bit_use_double_quant=True,
43
- bnb_4bit_quant_type="nf4")
 
44
 
45
  model = None
46
  tokenizer = None
@@ -53,7 +56,8 @@ def load_model(model_name):
53
  model_path,
54
  torch_dtype=torch.bfloat16,
55
  device_map="auto",
56
- quantization_config=quantization_config)
 
57
 
58
  @spaces.GPU()
59
  def stream_chat(
@@ -68,10 +72,10 @@ def stream_chat(
68
  model_name: str = "Phi-3.5-mini"
69
  ):
70
  global model, tokenizer
71
-
72
  if model is None or tokenizer is None or model.name_or_path != MODELS[model_name]:
73
  load_model(model_name)
74
-
75
  print(f'message: {message}')
76
  print(f'history: {history}')
77
 
@@ -121,22 +125,22 @@ with gr.Blocks(css=CSS, theme='ParityError/Interstellar') as demo:
121
  fill_height=True,
122
  additional_inputs=[
123
  gr.Textbox(
124
- value="You are a helpful assistant",
125
- label="System Prompt",
126
  ),
127
  gr.Slider(
128
  minimum=0,
129
  maximum=1,
130
  step=0.1,
131
  value=0.8,
132
- label="Temperature",
133
  ),
134
  gr.Slider(
135
  minimum=128,
136
  maximum=8192,
137
  step=1,
138
  value=1024,
139
- label="Max new tokens",
140
  ),
141
  gr.Slider(
142
  minimum=0.0,
@@ -157,19 +161,19 @@ with gr.Blocks(css=CSS, theme='ParityError/Interstellar') as demo:
157
  maximum=2.0,
158
  step=0.1,
159
  value=1.2,
160
- label="Repetition penalty",
161
  ),
162
  gr.Dropdown(
163
  choices=list(MODELS.keys()),
164
  value="Phi-3.5-mini",
165
- label="Model",
166
  ),
167
  ],
168
  examples=[
169
- ["Help me study vocabulary: write a sentence for me to fill in the blank, and I'll try to pick the correct option."],
170
- ["What are 5 creative things I could do with my kids' art? I don't want to throw them away, but it's also so much clutter."],
171
- ["Tell me a random fun fact about the Roman Empire."],
172
- ["Show me a code snippet of a website's sticky header in CSS and JavaScript."],
173
  ],
174
  cache_examples=False,
175
  )
 
6
  import gradio as gr
7
  from threading import Thread
8
 
9
+ # モデルの定義
10
  MODELS = {
 
11
  "Borea-Phi-3.5-mini-Jp": "AXCXEPT/Borea-Phi-3.5-mini-Instruct-Jp",
12
+ "EZO-Common-9B": "HODACHI/EZO-Common-9B-gemma-2-it",
13
+ "Phi-3.5-mini": "microsoft/Phi-3.5-mini-instruct",
14
  }
15
 
16
  HF_TOKEN = os.environ.get("HF_TOKEN", None)
17
 
18
+ # タイトルとプレースホルダーを日本語に変更
19
+ TITLE = "<h1><center>Borea/EZO デモアプリ</center></h1>"
20
 
21
  PLACEHOLDER = """
22
  <center>
23
+ <p>こんにちは、私はAIアシスタントです。何でも質問してください。</p>
24
  </center>
25
  """
26
 
 
42
  load_in_4bit=True,
43
  bnb_4bit_compute_dtype=torch.bfloat16,
44
  bnb_4bit_use_double_quant=True,
45
+ bnb_4bit_quant_type="nf4"
46
+ )
47
 
48
  model = None
49
  tokenizer = None
 
56
  model_path,
57
  torch_dtype=torch.bfloat16,
58
  device_map="auto",
59
+ quantization_config=quantization_config
60
+ )
61
 
62
  @spaces.GPU()
63
  def stream_chat(
 
72
  model_name: str = "Phi-3.5-mini"
73
  ):
74
  global model, tokenizer
75
+
76
  if model is None or tokenizer is None or model.name_or_path != MODELS[model_name]:
77
  load_model(model_name)
78
+
79
  print(f'message: {message}')
80
  print(f'history: {history}')
81
 
 
125
  fill_height=True,
126
  additional_inputs=[
127
  gr.Textbox(
128
+ value="あなたは親切なアシスタントです。",
129
+ label="システムプロンプト",
130
  ),
131
  gr.Slider(
132
  minimum=0,
133
  maximum=1,
134
  step=0.1,
135
  value=0.8,
136
+ label="温度 (Temperature)",
137
  ),
138
  gr.Slider(
139
  minimum=128,
140
  maximum=8192,
141
  step=1,
142
  value=1024,
143
+ label="最大新規トークン数",
144
  ),
145
  gr.Slider(
146
  minimum=0.0,
 
161
  maximum=2.0,
162
  step=0.1,
163
  value=1.2,
164
+ label="繰り返しペナルティ",
165
  ),
166
  gr.Dropdown(
167
  choices=list(MODELS.keys()),
168
  value="Phi-3.5-mini",
169
+ label="モデル選択",
170
  ),
171
  ],
172
  examples=[
173
+ ["語彙の勉強を手伝ってください。空欄を埋めるための文章を書いてください。私は正しい選択肢を選びます。"],
174
+ ["子供のアート作品でできる5つの創造的なことを教えてください。捨てたくはないのですが、散らかってしまいます。"],
175
+ ["ローマ帝国についてのランダムな面白い事実を教えてください。"],
176
+ ["ウェブサイトの固定ヘッダーのCSSJavaScriptのコードスニペットを見せてください。"],
177
  ],
178
  cache_examples=False,
179
  )