itacaiunas commited on
Commit
3dec43b
·
verified ·
1 Parent(s): 60c8b83

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -6
app.py CHANGED
@@ -28,10 +28,13 @@ def generate(message, history, temperature=0.7, max_new_tokens=1024, top_p=0.90,
28
  seed=random.randint(1, 1111111111111111),
29
  )
30
 
 
31
  output = client.text_generation(formatted_prompt, **generate_kwargs)
32
 
 
33
  response = output.split("\n")[0].strip()
34
 
 
35
  if "Usuário:" in response or "ChatGEO:" in response:
36
  response = response.split("Usuário:")[0].strip()
37
 
@@ -39,26 +42,70 @@ def generate(message, history, temperature=0.7, max_new_tokens=1024, top_p=0.90,
39
  return response
40
 
41
  mychatbot = gr.Chatbot(
42
- avatar_images=["./user.png", "./botgm.png"],
43
  bubble_full_width=False,
44
  show_label=False,
45
  show_copy_button=True,
46
  likeable=True,
47
  )
48
 
49
- # Substituir additional_inputs por uma informação sobre o chatbot
50
- chatbot_info = gr.Markdown(
 
51
  """
52
  ### Bem-vindo ao ChatGEO!
53
  O ChatGEO é um assistente especializado em geografia, pronto para responder suas perguntas sobre o mundo ao nosso redor.
54
  Faça suas perguntas e explore tópicos interessantes com clareza e precisão.
55
  """
56
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
 
58
  iface = gr.ChatInterface(
59
  fn=generate,
60
  chatbot=mychatbot,
61
- additional_inputs=[chatbot_info], # Exibe a mensagem sobre o chatbot
62
  submit_btn='Enviar',
63
  retry_btn=None,
64
  undo_btn=None,
@@ -66,7 +113,7 @@ iface = gr.ChatInterface(
66
  )
67
 
68
  with gr.Blocks() as demo:
69
- gr.HTML("<center><h2 style='font-size: 22px; text-align: center; color: #007BFF;'>ChatGEO IA</h2><p><b>Tire suas dúvidas, peça sugestões sobre os assuntos da Geografia e muito mais!</b></p></center>")
70
  iface.render()
71
 
72
  demo.queue().launch(show_api=False)
 
28
  seed=random.randint(1, 1111111111111111),
29
  )
30
 
31
+ # Gerar o texto
32
  output = client.text_generation(formatted_prompt, **generate_kwargs)
33
 
34
+ # Extrair a resposta apenas até o primeiro ponto final ou outro delimitador
35
  response = output.split("\n")[0].strip()
36
 
37
+ # Limitar a resposta para que o bot não continue respondendo indefinidamente
38
  if "Usuário:" in response or "ChatGEO:" in response:
39
  response = response.split("Usuário:")[0].strip()
40
 
 
42
  return response
43
 
44
  mychatbot = gr.Chatbot(
45
+ avatar_images=["./user.png", "./botz.png"],
46
  bubble_full_width=False,
47
  show_label=False,
48
  show_copy_button=True,
49
  likeable=True,
50
  )
51
 
52
+ additional_inputs = [
53
+
54
+ chatbot_info = gr.Markdown(
55
  """
56
  ### Bem-vindo ao ChatGEO!
57
  O ChatGEO é um assistente especializado em geografia, pronto para responder suas perguntas sobre o mundo ao nosso redor.
58
  Faça suas perguntas e explore tópicos interessantes com clareza e precisão.
59
  """
60
+ ),
61
+
62
+ gr.Slider(
63
+ label="Temperature",
64
+ value=0.7,
65
+ minimum=0.0,
66
+ maximum=1.0,
67
+ step=0.01,
68
+ interactive=True,
69
+ info="Higher values generate more diverse outputs",
70
+ visible=False # Oculta o slider
71
+
72
+ ),
73
+ gr.Slider(
74
+ label="Max new tokens",
75
+ value=1024,
76
+ minimum=0,
77
+ maximum=8000,
78
+ step=64,
79
+ interactive=True,
80
+ info="The maximum number of new tokens",
81
+ visible=False # Oculta o slider
82
+ ),
83
+ gr.Slider(
84
+ label="Top-p",
85
+ value=0.90,
86
+ minimum=0.0,
87
+ maximum=1.0,
88
+ step=0.01,
89
+ interactive=True,
90
+ info="Higher values sample more low-probability tokens",
91
+ visible=False # Oculta o slider
92
+ ),
93
+ gr.Slider(
94
+ label="Repetition penalty",
95
+ value=1.0,
96
+ minimum=0.1,
97
+ maximum=2.0,
98
+ step=0.1,
99
+ interactive=True,
100
+ info="Penalize repeated tokens",
101
+ visible=False # Oculta o slider
102
+ )
103
+ ]
104
 
105
  iface = gr.ChatInterface(
106
  fn=generate,
107
  chatbot=mychatbot,
108
+ additional_inputs=additional_inputs,
109
  submit_btn='Enviar',
110
  retry_btn=None,
111
  undo_btn=None,
 
113
  )
114
 
115
  with gr.Blocks() as demo:
116
+ gr.HTML("<center><h2 style='font-size: 22px; text-align: center; color: #007BFF;'>ChatGEO IA</h2><p><b>Tire suas dúvidas, peça sugestões sobre os assuntos da Geografia. Usamos o modelo de IA Mistral-7B-Instruct-v0.3. e muito mais!</b></p></center>")
117
  iface.render()
118
 
119
  demo.queue().launch(show_api=False)