openfree commited on
Commit
f2c0975
ยท
verified ยท
1 Parent(s): 83ee74c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -35
app.py CHANGED
@@ -8,20 +8,20 @@ HF_TOKEN = os.getenv("HF_TOKEN")
8
 
9
  # Available LLM models
10
  LLM_MODELS = {
11
- "Llama-3.3": "meta-llama/Llama-3.3-70B-Instruct",
12
- "QwQ-32B": "Qwen/QwQ-32B-Preview",
13
- "C4AI-Command": "CohereForAI/c4ai-command-r-plus-08-2024",
14
- "Marco-o1": "AIDC-AI/Marco-o1",
15
- "Qwen2.5": "Qwen/Qwen2.5-72B-Instruct",
16
- "Mistral-Nemo": "mistralai/Mistral-Nemo-Instruct-2407",
17
- "Nemotron-70B": "nvidia/Llama-3.1-Nemotron-70B-Instruct-HF"
18
  }
19
 
20
  # Default selected models
21
  DEFAULT_MODELS = [
22
- "meta-llama/Llama-3.3-70B-Instruct",
23
- "CohereForAI/c4ai-command-r-plus-08-2024",
24
- "mistralai/Mistral-Nemo-Instruct-2407"
25
  ]
26
 
27
  # Initialize clients with token
@@ -46,7 +46,10 @@ def respond_single(
46
  temperature: float,
47
  top_p: float,
48
  ):
49
- messages = [{"role": "system", "content": system_message}]
 
 
 
50
 
51
  for user, assistant in history:
52
  if user:
@@ -58,15 +61,18 @@ def respond_single(
58
 
59
  response = ""
60
  try:
61
- for msg in client.text_generation(
62
- prompt=message,
63
- max_new_tokens=max_tokens,
64
  stream=True,
65
  temperature=temperature,
66
  top_p=top_p,
67
  ):
68
- response += msg
69
- yield response
 
 
 
70
  except Exception as e:
71
  yield f"Error: {str(e)}"
72
 
@@ -106,18 +112,11 @@ def respond_all(
106
  generate(clients[selected_models[2]], history3),
107
  )
108
 
109
-
110
-
111
  css = """
112
- footer {
113
- visibility: hidden;
114
- }
115
  """
116
 
117
-
118
-
119
- with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
120
-
121
  with gr.Row():
122
  model_choices = gr.Checkboxgroup(
123
  choices=list(LLM_MODELS.values()),
@@ -149,27 +148,27 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
149
  with gr.Row():
150
  with gr.Column():
151
  system_message = gr.Textbox(
152
- value="You are a friendly Chatbot.",
153
  label="System message"
154
  )
155
  max_tokens = gr.Slider(
156
  minimum=1,
157
- maximum=2048,
158
- value=512,
159
  step=1,
160
  label="Max new tokens"
161
  )
162
  temperature = gr.Slider(
163
- minimum=0.1,
164
- maximum=4.0,
165
  value=0.7,
166
  step=0.1,
167
  label="Temperature"
168
  )
169
  top_p = gr.Slider(
170
- minimum=0.1,
171
- maximum=1.0,
172
- value=0.95,
173
  step=0.05,
174
  label="Top-p"
175
  )
@@ -181,6 +180,20 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
181
  placeholder="Enter text and press enter",
182
  container=False
183
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
 
185
  def submit_message(message, file):
186
  return respond_all(
@@ -206,5 +219,4 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
206
  if __name__ == "__main__":
207
  if not HF_TOKEN:
208
  print("Warning: HF_TOKEN environment variable is not set")
209
- demo.launch()
210
-
 
8
 
9
  # Available LLM models
10
  LLM_MODELS = {
11
+ "Mistral": "mistralai/Mistral-7B-Instruct-v0.2",
12
+ "Zephyr": "HuggingFaceH4/zephyr-7b-beta",
13
+ "OpenChat": "openchat/openchat-3.5",
14
+ "Llama2": "meta-llama/Llama-2-7b-chat-hf",
15
+ "Phi": "microsoft/phi-2",
16
+ "Neural": "nvidia/neural-chat-7b-v3-1",
17
+ "Starling": "HuggingFaceH4/starling-lm-7b-alpha"
18
  }
19
 
20
  # Default selected models
21
  DEFAULT_MODELS = [
22
+ "mistralai/Mistral-7B-Instruct-v0.2",
23
+ "HuggingFaceH4/zephyr-7b-beta",
24
+ "openchat/openchat-3.5"
25
  ]
26
 
27
  # Initialize clients with token
 
46
  temperature: float,
47
  top_p: float,
48
  ):
49
+ system_prefix = """๋ฐ˜๋“œ์‹œ ํ•œ๊ธ€๋กœ ๋‹ต๋ณ€ํ• ๊ฒƒ. ๋„ˆ๋Š” ์ฃผ์–ด์ง„ ๋‚ด์šฉ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ์ƒ์„ธํ•œ ์„ค๋ช…๊ณผ Q&A๋ฅผ ์ œ๊ณตํ•˜๋Š” ์—ญํ• ์ด๋‹ค.
50
+ ์•„์ฃผ ์นœ์ ˆํ•˜๊ณ  ์ž์„ธํ•˜๊ฒŒ ์„ค๋ช…ํ•˜๋ผ."""
51
+
52
+ messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}]
53
 
54
  for user, assistant in history:
55
  if user:
 
61
 
62
  response = ""
63
  try:
64
+ for msg in client.chat_completion(
65
+ messages,
66
+ max_tokens=max_tokens,
67
  stream=True,
68
  temperature=temperature,
69
  top_p=top_p,
70
  ):
71
+ if hasattr(msg.choices[0].delta, 'content'):
72
+ token = msg.choices[0].delta.content
73
+ if token is not None:
74
+ response += token
75
+ yield response
76
  except Exception as e:
77
  yield f"Error: {str(e)}"
78
 
 
112
  generate(clients[selected_models[2]], history3),
113
  )
114
 
 
 
115
  css = """
116
+ footer {visibility: hidden}
 
 
117
  """
118
 
119
+ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
 
 
 
120
  with gr.Row():
121
  model_choices = gr.Checkboxgroup(
122
  choices=list(LLM_MODELS.values()),
 
148
  with gr.Row():
149
  with gr.Column():
150
  system_message = gr.Textbox(
151
+ value="๋‹น์‹ ์€ ์นœ์ ˆํ•œ AI ์–ด์‹œ์Šคํ„ดํŠธ์ž…๋‹ˆ๋‹ค.",
152
  label="System message"
153
  )
154
  max_tokens = gr.Slider(
155
  minimum=1,
156
+ maximum=8000,
157
+ value=4000,
158
  step=1,
159
  label="Max new tokens"
160
  )
161
  temperature = gr.Slider(
162
+ minimum=0,
163
+ maximum=1,
164
  value=0.7,
165
  step=0.1,
166
  label="Temperature"
167
  )
168
  top_p = gr.Slider(
169
+ minimum=0,
170
+ maximum=1,
171
+ value=0.9,
172
  step=0.05,
173
  label="Top-p"
174
  )
 
180
  placeholder="Enter text and press enter",
181
  container=False
182
  )
183
+
184
+ examples = [
185
+ ["์ƒ์„ธํ•œ ์‚ฌ์šฉ ๋ฐฉ๋ฒ•์„ ๋งˆ์น˜ ํ™”๋ฉด์„ ๋ณด๋ฉด์„œ ์„ค๋ช…ํ•˜๋“ฏ์ด 4000 ํ† ํฐ ์ด์ƒ ์ž์„ธํžˆ ์„ค๋ช…ํ•˜๋ผ"],
186
+ ["FAQ 20๊ฑด์„ ์ƒ์„ธํ•˜๊ฒŒ ์ž‘์„ฑํ•˜๋ผ. 4000ํ† ํฐ ์ด์ƒ ์‚ฌ์šฉํ•˜๋ผ."],
187
+ ["์‚ฌ์šฉ ๋ฐฉ๋ฒ•๊ณผ ์ฐจ๋ณ„์ , ํŠน์ง•, ๊ฐ•์ ์„ ์ค‘์‹ฌ์œผ๋กœ 4000 ํ† ํฐ ์ด์ƒ ์œ ํŠœ๋ธŒ ์˜์ƒ ์Šคํฌ๋ฆฝํŠธ ํ˜•ํƒœ๋กœ ์ž‘์„ฑํ•˜๋ผ"],
188
+ ["๋ณธ ์„œ๋น„์Šค๋ฅผ SEO ์ตœ์ ํ™”ํ•˜์—ฌ ๋ธ”๋กœ๊ทธ ํฌ์ŠคํŠธ๋กœ 4000 ํ† ํฐ ์ด์ƒ ์ž‘์„ฑํ•˜๋ผ"],
189
+ ["๊ณ„์† ์ด์–ด์„œ ๋‹ต๋ณ€ํ•˜๋ผ"],
190
+ ]
191
+
192
+ gr.Examples(
193
+ examples=examples,
194
+ inputs=msg_input,
195
+ cache_examples=False
196
+ )
197
 
198
  def submit_message(message, file):
199
  return respond_all(
 
219
  if __name__ == "__main__":
220
  if not HF_TOKEN:
221
  print("Warning: HF_TOKEN environment variable is not set")
222
+ demo.launch()