wendellast commited on
Commit
5ce34b7
·
verified ·
1 Parent(s): 906d949

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -21
app.py CHANGED
@@ -1,17 +1,11 @@
1
  import gradio as gr
2
  import json
3
-
4
-
5
  from datetime import datetime
6
-
7
  from huggingface_hub import InferenceClient
8
 
9
-
10
-
11
  now = datetime.now()
12
 
13
-
14
-
15
  with open("data/config.json", "r", encoding="UTF-8") as file:
16
  config = json.load(file)
17
 
@@ -19,7 +13,6 @@ client = InferenceClient(
19
  model="meta-llama/Llama-3.2-3B-Instruct"
20
  )
21
 
22
-
23
  rules = f"""
24
  # INFORMAÇÕES GERAIS: (hoje é {now.strftime("%d/%m/%Y %H:%M:%S")},
25
  # VOCÊ FOI CRIADO PELO GRUPO Last, O SEU NOME É 'GUI',
@@ -27,7 +20,6 @@ rules = f"""
27
  # SUAS RESPOSTAS DEVEM SER SARCASTICAMENTE DIVERTIDAS :),
28
  """
29
 
30
-
31
  def respond(
32
  message,
33
  history: list[tuple[str, str]],
@@ -36,6 +28,7 @@ def respond(
36
  temperature,
37
  top_p,
38
  ):
 
39
  messages = [{"role": "system", "content": system_message}]
40
 
41
  for val in history:
@@ -48,6 +41,7 @@ def respond(
48
 
49
  response = ""
50
 
 
51
  for message in client.chat_completion(
52
  messages,
53
  max_tokens=max_tokens,
@@ -56,27 +50,20 @@ def respond(
56
  top_p=top_p,
57
  ):
58
  token = message.choices[0].delta.content
59
-
60
  response += token
61
  yield response
62
 
63
-
64
  demo = gr.ChatInterface(
65
- respond,
66
- additional_inputs=[
67
  gr.Textbox(value=rules, label="System message"),
68
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
69
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
70
- gr.Slider(
71
- minimum=0.1,
72
- maximum=1.0,
73
- value=0.95,
74
- step=0.05,
75
- label="Top-p (nucleus sampling)",
76
- ),
77
  ],
 
78
  )
79
 
80
-
81
  if __name__ == "__main__":
82
  demo.launch()
 
1
  import gradio as gr
2
  import json
 
 
3
  from datetime import datetime
 
4
  from huggingface_hub import InferenceClient
5
 
 
 
6
  now = datetime.now()
7
 
8
+ # Carregar configurações
 
9
  with open("data/config.json", "r", encoding="UTF-8") as file:
10
  config = json.load(file)
11
 
 
13
  model="meta-llama/Llama-3.2-3B-Instruct"
14
  )
15
 
 
16
  rules = f"""
17
  # INFORMAÇÕES GERAIS: (hoje é {now.strftime("%d/%m/%Y %H:%M:%S")},
18
  # VOCÊ FOI CRIADO PELO GRUPO Last, O SEU NOME É 'GUI',
 
20
  # SUAS RESPOSTAS DEVEM SER SARCASTICAMENTE DIVERTIDAS :),
21
  """
22
 
 
23
  def respond(
24
  message,
25
  history: list[tuple[str, str]],
 
28
  temperature,
29
  top_p,
30
  ):
31
+ # Formatação das mensagens conforme o novo padrão
32
  messages = [{"role": "system", "content": system_message}]
33
 
34
  for val in history:
 
41
 
42
  response = ""
43
 
44
+ # Chamada para o cliente de chat usando o novo formato
45
  for message in client.chat_completion(
46
  messages,
47
  max_tokens=max_tokens,
 
50
  top_p=top_p,
51
  ):
52
  token = message.choices[0].delta.content
 
53
  response += token
54
  yield response
55
 
56
+ # Atualização para a nova versão de Gradio (usando 'type="messages"')
57
  demo = gr.ChatInterface(
58
+ fn=respond,
59
+ inputs=[
60
  gr.Textbox(value=rules, label="System message"),
61
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
62
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
63
+ gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
 
 
 
 
 
 
64
  ],
65
+ type="messages"
66
  )
67
 
 
68
  if __name__ == "__main__":
69
  demo.launch()