Spaces:
Running
Running
Commit
·
47c5723
1
Parent(s):
c0ee7d3
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,6 @@
|
|
2 |
SYSTEM_PROMPT = "O ChatGEO é um assistente virtual especializado em geografia, projetado para ajudar estudantes a explorar e compreender diversos tópicos relacionados ao mundo ao seu redor. Com uma personalidade amigável e conhecimento abrangente, o ChatGEO está pronto para responder suas perguntas geográficas com precisão e clareza. Exemplos de Perguntas para ChatGEO: Qual é a capital do Brasil? Descreva o processo de formação de uma cadeia de montanhas. Quais são os principais rios da América do Sul? Explique o conceito de zonas climáticas e suas características. Como a globalização impacta as relações entre os países? Quais são as diferenças entre latitude e longitude? Liste os países que fazem parte da União Europeia. O que são fenômenos naturais e como eles afetam o ambiente?Fale sobre as características geográficas da África Subsaariana. Como os vulcões se formam e quais são seus efeitos na paisagem? Ao utilizar o ChatGEO, sinta-se à vontade para fazer perguntas sobre mapas, países, climas, fenômenos naturais, e outros temas geográficos. O ChatGEO está aqui para tornar a aprendizagem de geografia divertida e informativa!"
|
3 |
|
4 |
TITLE = "ChatGEO"
|
5 |
-
EXAMPLE_INPUT = "Olá, ChatGEO!"
|
6 |
from typing import Iterator
|
7 |
|
8 |
import gradio as gr
|
@@ -70,18 +69,143 @@ def test_preview_chatbot(message, history):
|
|
70 |
return response
|
71 |
|
72 |
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
"""
|
80 |
-
|
81 |
-
chatbot_preview = gr.Chatbot(layout="panel", value=[(None, welcome_preview_message)])
|
82 |
-
textbox_preview = gr.Textbox(scale=7, container=False, value=EXAMPLE_INPUT)
|
83 |
-
submit_button = gr.Button('ENVIAR', variant='primary', scale=1, min_width=0)
|
84 |
-
|
85 |
-
demo = gr.ChatInterface(test_preview_chatbot, chatbot=chatbot_preview, textbox=textbox_preview)
|
86 |
|
87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
SYSTEM_PROMPT = "O ChatGEO é um assistente virtual especializado em geografia, projetado para ajudar estudantes a explorar e compreender diversos tópicos relacionados ao mundo ao seu redor. Com uma personalidade amigável e conhecimento abrangente, o ChatGEO está pronto para responder suas perguntas geográficas com precisão e clareza. Exemplos de Perguntas para ChatGEO: Qual é a capital do Brasil? Descreva o processo de formação de uma cadeia de montanhas. Quais são os principais rios da América do Sul? Explique o conceito de zonas climáticas e suas características. Como a globalização impacta as relações entre os países? Quais são as diferenças entre latitude e longitude? Liste os países que fazem parte da União Europeia. O que são fenômenos naturais e como eles afetam o ambiente?Fale sobre as características geográficas da África Subsaariana. Como os vulcões se formam e quais são seus efeitos na paisagem? Ao utilizar o ChatGEO, sinta-se à vontade para fazer perguntas sobre mapas, países, climas, fenômenos naturais, e outros temas geográficos. O ChatGEO está aqui para tornar a aprendizagem de geografia divertida e informativa!"
|
3 |
|
4 |
TITLE = "ChatGEO"
|
|
|
5 |
from typing import Iterator
|
6 |
|
7 |
import gradio as gr
|
|
|
69 |
return response
|
70 |
|
71 |
|
72 |
+
with gr.Blocks(theme='JohnSmith9982/small_and_pretty') as demo:
|
73 |
+
gr.Markdown(DESCRIPTION)
|
74 |
+
with gr.Group():
|
75 |
+
chatbot = gr.Chatbot(label='ChatGEO')
|
76 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
|
78 |
+
with gr.Row():
|
79 |
+
retry_button = gr.Button('Refazer', variant='secondary')
|
80 |
+
undo_button = gr.Button('Desfazer', variant='secondary')
|
81 |
+
clear_button = gr.Button('Limpar', variant='secondary')
|
82 |
+
|
83 |
+
with gr.Row():
|
84 |
+
textbox = gr.Textbox(container=False, show_label=False, placeholder='Olá, ChatGEO', scale=7)
|
85 |
+
model_id = gr.Dropdown(label='Modelos',
|
86 |
+
choices=[
|
87 |
+
'mistralai/Mistral-7B-Instruct-v0.1',
|
88 |
+
'HuggingFaceH4/zephyr-7b-beta',
|
89 |
+
'meta-llama/Llama-2-7b-chat-hf'
|
90 |
+
],
|
91 |
+
value='mistralai/Mistral-7B-Instruct-v0.1', scale=3)
|
92 |
+
submit_button = gr.Button('ENVIAR', variant='primary', scale=1, min_width=0)
|
93 |
+
|
94 |
+
saved_input = gr.State()
|
95 |
+
|
96 |
+
textbox.submit(
|
97 |
+
fn=clear_and_save_textbox,
|
98 |
+
inputs=textbox,
|
99 |
+
outputs=[textbox, saved_input],
|
100 |
+
api_name=False,
|
101 |
+
queue=False,
|
102 |
+
).then(
|
103 |
+
fn=display_input,
|
104 |
+
inputs=[saved_input, chatbot],
|
105 |
+
outputs=chatbot,
|
106 |
+
api_name=False,
|
107 |
+
queue=False,
|
108 |
+
).then(
|
109 |
+
fn=check_input_token_length,
|
110 |
+
inputs=[saved_input, chatbot, system_prompt],
|
111 |
+
api_name=False,
|
112 |
+
queue=False,
|
113 |
+
).success(
|
114 |
+
fn=generate,
|
115 |
+
inputs=[
|
116 |
+
model_id,
|
117 |
+
saved_input,
|
118 |
+
chatbot,
|
119 |
+
system_prompt,
|
120 |
+
max_new_tokens,
|
121 |
+
temperature,
|
122 |
+
top_p,
|
123 |
+
top_k,
|
124 |
+
],
|
125 |
+
outputs=chatbot,
|
126 |
+
api_name=False,
|
127 |
+
)
|
128 |
+
|
129 |
+
button_event_preprocess = submit_button.click(
|
130 |
+
fn=clear_and_save_textbox,
|
131 |
+
inputs=textbox,
|
132 |
+
outputs=[textbox, saved_input],
|
133 |
+
api_name=False,
|
134 |
+
queue=False,
|
135 |
+
).then(
|
136 |
+
fn=display_input,
|
137 |
+
inputs=[saved_input, chatbot],
|
138 |
+
outputs=chatbot,
|
139 |
+
api_name=False,
|
140 |
+
queue=False,
|
141 |
+
).then(
|
142 |
+
fn=check_input_token_length,
|
143 |
+
inputs=[saved_input, chatbot, system_prompt],
|
144 |
+
api_name=False,
|
145 |
+
queue=False,
|
146 |
+
).success(
|
147 |
+
fn=generate,
|
148 |
+
inputs=[
|
149 |
+
model_id,
|
150 |
+
saved_input,
|
151 |
+
chatbot,
|
152 |
+
system_prompt,
|
153 |
+
max_new_tokens,
|
154 |
+
temperature,
|
155 |
+
top_p,
|
156 |
+
top_k,
|
157 |
+
],
|
158 |
+
outputs=chatbot,
|
159 |
+
api_name=False,
|
160 |
+
)
|
161 |
+
|
162 |
+
retry_button.click(
|
163 |
+
fn=delete_prev_fn,
|
164 |
+
inputs=chatbot,
|
165 |
+
outputs=[chatbot, saved_input],
|
166 |
+
api_name=False,
|
167 |
+
queue=False,
|
168 |
+
).then(
|
169 |
+
fn=display_input,
|
170 |
+
inputs=[saved_input, chatbot],
|
171 |
+
outputs=chatbot,
|
172 |
+
api_name=False,
|
173 |
+
queue=False,
|
174 |
+
).then(
|
175 |
+
fn=generate,
|
176 |
+
inputs=[
|
177 |
+
model_id,
|
178 |
+
saved_input,
|
179 |
+
chatbot,
|
180 |
+
system_prompt,
|
181 |
+
max_new_tokens,
|
182 |
+
temperature,
|
183 |
+
top_p,
|
184 |
+
top_k,
|
185 |
+
],
|
186 |
+
outputs=chatbot,
|
187 |
+
api_name=False,
|
188 |
+
)
|
189 |
+
|
190 |
+
undo_button.click(
|
191 |
+
fn=delete_prev_fn,
|
192 |
+
inputs=chatbot,
|
193 |
+
outputs=[chatbot, saved_input],
|
194 |
+
api_name=False,
|
195 |
+
queue=False,
|
196 |
+
).then(
|
197 |
+
fn=lambda x: x,
|
198 |
+
inputs=[saved_input],
|
199 |
+
outputs=textbox,
|
200 |
+
api_name=False,
|
201 |
+
queue=False,
|
202 |
+
)
|
203 |
+
|
204 |
+
clear_button.click(
|
205 |
+
fn=lambda: ([], ''),
|
206 |
+
outputs=[chatbot, saved_input],
|
207 |
+
queue=False,
|
208 |
+
api_name=False,
|
209 |
+
)
|
210 |
+
|
211 |
+
demo.queue(max_size=32).launch(show_api=False)
|