Elieon commited on
Commit
2c31eb0
·
verified ·
1 Parent(s): 44ea2c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -5
app.py CHANGED
@@ -5,6 +5,7 @@ import os
5
  # Load secrets
6
  system_message = os.environ["SYSTEM_MESSAGE"]
7
  HF_TOKEN = os.environ["HF_TOKEN"]
 
8
 
9
  client = InferenceClient(token=HF_TOKEN)
10
 
@@ -18,7 +19,7 @@ def respond(message, history, max_tokens, temperature, top_p):
18
 
19
  response = []
20
  stream = client.chat.completions.create(
21
- model="mistralai/Mistral-7B-Instruct-v0.3",
22
  messages=prompt,
23
  max_tokens=max_tokens,
24
  temperature=temperature,
@@ -26,14 +27,13 @@ def respond(message, history, max_tokens, temperature, top_p):
26
  stream=True
27
  )
28
 
29
- # Fast generator (yield only when new content available)
30
  for chunk in stream:
31
  token = chunk.choices[0].delta.content
32
  if token:
33
  response.append(token)
34
  yield "".join(response)
35
 
36
- # UI (clean and efficient)
37
  app = gr.ChatInterface(
38
  fn=respond,
39
  additional_inputs=[
@@ -41,9 +41,7 @@ app = gr.ChatInterface(
41
  gr.Slider(0.1, 2.0, value=0.7, step=0.1, label="Temperature"),
42
  gr.Slider(0.1, 1.0, value=0.95, step=0.05, label="Top-p"),
43
  ],
44
-
45
  )
46
 
47
  if __name__ == "__main__":
48
  app.launch()
49
-
 
5
  # Load secrets
6
  system_message = os.environ["SYSTEM_MESSAGE"]
7
  HF_TOKEN = os.environ["HF_TOKEN"]
8
+ MODEL_NAME = os.environ["MODEL_NAME"] # <-- Add this
9
 
10
  client = InferenceClient(token=HF_TOKEN)
11
 
 
19
 
20
  response = []
21
  stream = client.chat.completions.create(
22
+ model=MODEL_NAME, # <-- use the secret here
23
  messages=prompt,
24
  max_tokens=max_tokens,
25
  temperature=temperature,
 
27
  stream=True
28
  )
29
 
 
30
  for chunk in stream:
31
  token = chunk.choices[0].delta.content
32
  if token:
33
  response.append(token)
34
  yield "".join(response)
35
 
36
+ # UI
37
  app = gr.ChatInterface(
38
  fn=respond,
39
  additional_inputs=[
 
41
  gr.Slider(0.1, 2.0, value=0.7, step=0.1, label="Temperature"),
42
  gr.Slider(0.1, 1.0, value=0.95, step=0.05, label="Top-p"),
43
  ],
 
44
  )
45
 
46
  if __name__ == "__main__":
47
  app.launch()