DHEIVER commited on
Commit
9248299
1 Parent(s): 8b8813c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -27
app.py CHANGED
@@ -2,62 +2,58 @@ from huggingface_hub import InferenceClient
2
  import gradio as gr
3
 
4
  class MixtralChatInterface:
5
- def __init__(self):
6
- self.client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
7
-
8
- self.additional_inputs = [
9
  gr.Textbox(
10
- label="Mensagem do Sistema",
11
  max_lines=1,
12
  interactive=True,
13
  ),
14
  gr.Slider(
15
- label="Temperatura",
16
  value=0.9,
17
  minimum=0.0,
18
  maximum=1.0,
19
  step=0.05,
20
  interactive=True,
21
- info="Valores mais altos produzem saídas mais diversas",
22
  ),
23
  gr.Slider(
24
- label="Máximo de Novos Tokens",
25
  value=256,
26
  minimum=0,
27
  maximum=1048,
28
  step=64,
29
  interactive=True,
30
- info="O número máximo de novos tokens",
31
  ),
32
  gr.Slider(
33
- label="Top-p (amostragem de núcleo)",
34
  value=0.90,
35
  minimum=0.0,
36
  maximum=1,
37
  step=0.05,
38
  interactive=True,
39
- info="Valores mais altos amostram mais tokens de baixa probabilidade",
40
  ),
41
  gr.Slider(
42
- label="Penalidade de Repetição",
43
  value=1.2,
44
  minimum=1.0,
45
  maximum=2.0,
46
  step=0.05,
47
  interactive=True,
48
- info="Penaliza tokens repetidos",
49
  )
50
  ]
51
-
52
- self.examples = [
53
- [
54
- ["Descreva os sintomas típicos de um paciente com diabetes tipo 2 e explique as principais complicações associadas. Responda em pt", None, None, None, None, None],
55
- ["Quais são os protocolos recomendados para o tratamento de pacientes com hipertensão arterial sistêmica? Responda em pt ", None, None, None, None, None],
56
- ["Explique os diferentes estágios do câncer de mama e os métodos de detecção precoce mais eficazes. Responda em pt", None, None, None, None, None],
57
- ["Forneça orientações sobre como conduzir uma consulta eficaz com pacientes que sofrem de transtornos de ansiedade. Responda em pt", None, None, None, None, None],
58
- ["Quais são as opções de tratamento disponíveis para pacientes diagnosticados com esclerose múltipla? Responda em pt", None, None, None, None, None],
59
- ["Descreva os efeitos colaterais comuns associados ao uso prolongado de anti-inflamatórios não esteroidais em pacientes idosos. Responda em pt", None, None, None, None, None],
60
- ]
61
  ]
62
 
63
  def format_prompt(self, message, history):
@@ -92,7 +88,7 @@ class MixtralChatInterface:
92
  yield output
93
  return output
94
 
95
- def launch_interface(self):
96
  gr.ChatInterface(
97
  fn=self.generate,
98
  chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
@@ -101,6 +97,9 @@ class MixtralChatInterface:
101
  examples=self.examples,
102
  concurrency_limit=20,
103
  ).launch(show_api=False)
104
-
105
- interface = MixtralChatInterface()
106
- interface.launch_interface()
 
 
 
 
2
  import gradio as gr
3
 
4
  class MixtralChatInterface:
5
+ def __init__(self, model_name):
6
+ self.client = InferenceClient(model_name)
7
+ self.additional_inputs=[
 
8
  gr.Textbox(
9
+ label="System Prompt",
10
  max_lines=1,
11
  interactive=True,
12
  ),
13
  gr.Slider(
14
+ label="Temperature",
15
  value=0.9,
16
  minimum=0.0,
17
  maximum=1.0,
18
  step=0.05,
19
  interactive=True,
20
+ info="Higher values produce more diverse outputs",
21
  ),
22
  gr.Slider(
23
+ label="Max new tokens",
24
  value=256,
25
  minimum=0,
26
  maximum=1048,
27
  step=64,
28
  interactive=True,
29
+ info="The maximum numbers of new tokens",
30
  ),
31
  gr.Slider(
32
+ label="Top-p (nucleus sampling)",
33
  value=0.90,
34
  minimum=0.0,
35
  maximum=1,
36
  step=0.05,
37
  interactive=True,
38
+ info="Higher values sample more low-probability tokens",
39
  ),
40
  gr.Slider(
41
+ label="Repetition penalty",
42
  value=1.2,
43
  minimum=1.0,
44
  maximum=2.0,
45
  step=0.05,
46
  interactive=True,
47
+ info="Penalize repeated tokens",
48
  )
49
  ]
50
+ self.examples=[
51
+ ["I'm planning a vacation to Japan. Can you suggest a one-week itinerary including must-visit places and local cuisines to try?", None, None, None, None, None, ],
52
+ ["Can you write a short story about a time-traveling detective who solves historical mysteries?", None, None, None, None, None,],
53
+ ["I'm trying to learn French. Can you provide some common phrases that would be useful for a beginner, along with their pronunciations?", None, None, None, None, None,],
54
+ ["I have chicken, rice, and bell peppers in my kitchen. Can you suggest an easy recipe I can make with these ingredients?", None, None, None, None, None,],
55
+ ["Can you explain how the QuickSort algorithm works and provide a Python implementation?", None, None, None, None, None,],
56
+ ["What are some unique features of Rust that make it stand out compared to other systems programming languages like C++?", None, None, None, None, None,],
 
 
 
57
  ]
58
 
59
  def format_prompt(self, message, history):
 
88
  yield output
89
  return output
90
 
91
+ def launch(self):
92
  gr.ChatInterface(
93
  fn=self.generate,
94
  chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
 
97
  examples=self.examples,
98
  concurrency_limit=20,
99
  ).launch(show_api=False)
100
+
101
+ # Usage
102
+ if __name__ == "__main__":
103
+ model_name = "mistralai/Mixtral-8x7B-Instruct-v0.1"
104
+ chat_interface = MixtralChatInterface(model_name)
105
+ chat_interface.launch()