Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -132,63 +132,169 @@ def executar_equipe_interface(disciplina, assunto, topicos_str):
|
|
| 132 |
|
| 133 |
return saida_final, pdf_path
|
| 134 |
|
| 135 |
-
# Main application function with both login and main interfaces
|
| 136 |
def main_app():
|
| 137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
# Authentication state
|
| 139 |
is_logged_in = gr.State(False)
|
| 140 |
current_user = gr.State("")
|
| 141 |
|
| 142 |
# Login Interface
|
| 143 |
with gr.Group(visible=True) as login_block:
|
| 144 |
-
gr.
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
|
| 159 |
# Main Application Interface
|
| 160 |
with gr.Group(visible=False) as main_block:
|
| 161 |
-
gr.
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
|
| 177 |
-
# Login function
|
| 178 |
def login_fn(username, password):
|
| 179 |
success, message = login(username, password)
|
| 180 |
if success:
|
| 181 |
return {
|
| 182 |
login_block: gr.update(visible=False),
|
| 183 |
main_block: gr.update(visible=True),
|
| 184 |
-
login_message: message,
|
| 185 |
-
|
| 186 |
is_logged_in: True,
|
| 187 |
current_user: username
|
| 188 |
}
|
| 189 |
else:
|
| 190 |
return {
|
| 191 |
-
login_message: message,
|
| 192 |
is_logged_in: False
|
| 193 |
}
|
| 194 |
|
|
@@ -199,21 +305,48 @@ def main_app():
|
|
| 199 |
main_block: gr.update(visible=False),
|
| 200 |
username_input: "",
|
| 201 |
password_input: "",
|
| 202 |
-
login_message: "",
|
| 203 |
is_logged_in: False,
|
| 204 |
current_user: ""
|
| 205 |
}
|
| 206 |
|
| 207 |
-
# Generate material function
|
| 208 |
-
def generate_material(disciplina, assunto, topicos):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
markdown, pdf = executar_equipe_interface(disciplina, assunto, topicos)
|
| 210 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
|
| 212 |
# Connect buttons to functions
|
| 213 |
login_button.click(
|
| 214 |
login_fn,
|
| 215 |
inputs=[username_input, password_input],
|
| 216 |
-
outputs=[login_block, main_block, login_message,
|
| 217 |
)
|
| 218 |
|
| 219 |
logout_button.click(
|
|
@@ -223,9 +356,12 @@ def main_app():
|
|
| 223 |
)
|
| 224 |
|
| 225 |
generate_button.click(
|
|
|
|
|
|
|
|
|
|
| 226 |
generate_material,
|
| 227 |
inputs=[disciplina_input, assunto_input, topicos_input],
|
| 228 |
-
outputs=[markdown_output, pdf_output]
|
| 229 |
)
|
| 230 |
|
| 231 |
return app
|
|
|
|
| 132 |
|
| 133 |
return saida_final, pdf_path
|
| 134 |
|
|
|
|
| 135 |
def main_app():
|
| 136 |
+
# Custom CSS for better styling
|
| 137 |
+
custom_css = """
|
| 138 |
+
.main-container {
|
| 139 |
+
background-color: #f8f9fa;
|
| 140 |
+
border-radius: 10px;
|
| 141 |
+
padding: 20px;
|
| 142 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 143 |
+
margin: 10px;
|
| 144 |
+
}
|
| 145 |
+
.header {
|
| 146 |
+
text-align: center;
|
| 147 |
+
margin-bottom: 20px;
|
| 148 |
+
}
|
| 149 |
+
.header h1 {
|
| 150 |
+
color: #4a4a4a;
|
| 151 |
+
font-weight: bold;
|
| 152 |
+
}
|
| 153 |
+
.login-container {
|
| 154 |
+
max-width: 500px;
|
| 155 |
+
margin: 0 auto;
|
| 156 |
+
padding: 30px;
|
| 157 |
+
background-color: white;
|
| 158 |
+
border-radius: 8px;
|
| 159 |
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
|
| 160 |
+
}
|
| 161 |
+
.input-group {
|
| 162 |
+
margin-bottom: 15px;
|
| 163 |
+
}
|
| 164 |
+
.btn-primary {
|
| 165 |
+
background-color: #3498db;
|
| 166 |
+
color: white;
|
| 167 |
+
border: none;
|
| 168 |
+
padding: 10px 20px;
|
| 169 |
+
border-radius: 5px;
|
| 170 |
+
cursor: pointer;
|
| 171 |
+
transition: background-color 0.3s;
|
| 172 |
+
}
|
| 173 |
+
.btn-primary:hover {
|
| 174 |
+
background-color: #2980b9;
|
| 175 |
+
}
|
| 176 |
+
.user-info {
|
| 177 |
+
display: flex;
|
| 178 |
+
justify-content: space-between;
|
| 179 |
+
align-items: center;
|
| 180 |
+
margin-bottom: 20px;
|
| 181 |
+
padding: 10px;
|
| 182 |
+
background-color: #e8f4fd;
|
| 183 |
+
border-radius: 5px;
|
| 184 |
+
}
|
| 185 |
+
.form-card {
|
| 186 |
+
padding: 20px;
|
| 187 |
+
background-color: white;
|
| 188 |
+
border-radius: 8px;
|
| 189 |
+
margin-bottom: 20px;
|
| 190 |
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
|
| 191 |
+
}
|
| 192 |
+
.tab-content {
|
| 193 |
+
padding: 20px;
|
| 194 |
+
background-color: white;
|
| 195 |
+
border-radius: 0 0 8px 8px;
|
| 196 |
+
min-height: 400px;
|
| 197 |
+
}
|
| 198 |
+
/* Hide Gradio footer */
|
| 199 |
+
footer {
|
| 200 |
+
display: none !important;
|
| 201 |
+
}
|
| 202 |
+
"""
|
| 203 |
+
|
| 204 |
+
with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as app:
|
| 205 |
# Authentication state
|
| 206 |
is_logged_in = gr.State(False)
|
| 207 |
current_user = gr.State("")
|
| 208 |
|
| 209 |
# Login Interface
|
| 210 |
with gr.Group(visible=True) as login_block:
|
| 211 |
+
with gr.Column(elem_classes=["main-container"]):
|
| 212 |
+
with gr.Row(elem_classes=["header"]):
|
| 213 |
+
gr.Markdown("# Sistema de Material de Estudo")
|
| 214 |
+
gr.Markdown("### Assistente Inteligente para Geração de Material Educacional")
|
| 215 |
+
|
| 216 |
+
with gr.Column(elem_classes=["login-container"]):
|
| 217 |
+
gr.Markdown("### Login")
|
| 218 |
+
with gr.Group():
|
| 219 |
+
username_input = gr.Textbox(label="Usuário", placeholder="Digite seu nome de usuário")
|
| 220 |
+
password_input = gr.Textbox(label="Senha", type="password", placeholder="Digite sua senha")
|
| 221 |
+
login_message = gr.Textbox(label="", interactive=False, visible=False)
|
| 222 |
+
login_button = gr.Button("Entrar", variant="primary")
|
| 223 |
+
|
| 224 |
+
with gr.Accordion("Credenciais para teste", open=False):
|
| 225 |
+
gr.Markdown("""
|
| 226 |
+
- Usuário: admin, Senha: admin
|
| 227 |
+
- Usuário: user, Senha: user123
|
| 228 |
+
- Usuário: test, Senha: test
|
| 229 |
+
""")
|
| 230 |
|
| 231 |
# Main Application Interface
|
| 232 |
with gr.Group(visible=False) as main_block:
|
| 233 |
+
with gr.Column(elem_classes=["main-container"]):
|
| 234 |
+
with gr.Row(elem_classes=["user-info"]):
|
| 235 |
+
user_display = gr.Markdown("Bem-vindo!")
|
| 236 |
+
logout_button = gr.Button("Sair", size="sm")
|
| 237 |
+
|
| 238 |
+
gr.Markdown("# Gerador Inteligente de Material de Estudos")
|
| 239 |
+
gr.Markdown("### Personalize seu material educacional completo em minutos")
|
| 240 |
+
|
| 241 |
+
with gr.Column(elem_classes=["form-card"]):
|
| 242 |
+
gr.Markdown("### Dados do Material")
|
| 243 |
+
with gr.Row():
|
| 244 |
+
with gr.Column(scale=1):
|
| 245 |
+
disciplina_input = gr.Textbox(
|
| 246 |
+
label="Disciplina",
|
| 247 |
+
placeholder="Ex: Matemática, Física, História...",
|
| 248 |
+
value="Matemática"
|
| 249 |
+
)
|
| 250 |
+
with gr.Column(scale=1):
|
| 251 |
+
assunto_input = gr.Textbox(
|
| 252 |
+
label="Assunto",
|
| 253 |
+
placeholder="Ex: Funções, Leis de Newton, Segunda Guerra Mundial...",
|
| 254 |
+
value="Funções"
|
| 255 |
+
)
|
| 256 |
+
|
| 257 |
+
topicos_input = gr.Textbox(
|
| 258 |
+
label="Tópicos (separados por vírgula)",
|
| 259 |
+
placeholder="Ex: Função quadrática, Função exponencial, Função logarítmica...",
|
| 260 |
+
value="Função quadrática, Função exponencial, Função logarítmica",
|
| 261 |
+
lines=2
|
| 262 |
+
)
|
| 263 |
+
|
| 264 |
+
with gr.Row():
|
| 265 |
+
generate_button = gr.Button("Gerar Material de Estudo", variant="primary", size="lg")
|
| 266 |
+
|
| 267 |
+
# Progress indicator during generation
|
| 268 |
+
with gr.Group(visible=False) as progress_group:
|
| 269 |
+
progress_bar = gr.Progress()
|
| 270 |
+
progress_text = gr.Markdown("Gerando material, por favor aguarde...")
|
| 271 |
+
|
| 272 |
+
# Output tabs
|
| 273 |
+
with gr.Tabs() as tabs:
|
| 274 |
+
with gr.TabItem("Visualizar Material"):
|
| 275 |
+
markdown_output = gr.Markdown(label="Material Completo")
|
| 276 |
+
|
| 277 |
+
with gr.TabItem("Download"):
|
| 278 |
+
with gr.Column():
|
| 279 |
+
gr.Markdown("### Download do Material")
|
| 280 |
+
pdf_output = gr.File(label="Download PDF")
|
| 281 |
+
gr.Markdown("Clique no botão acima para baixar seu material em formato PDF.")
|
| 282 |
|
| 283 |
+
# Login function with improved feedback
|
| 284 |
def login_fn(username, password):
|
| 285 |
success, message = login(username, password)
|
| 286 |
if success:
|
| 287 |
return {
|
| 288 |
login_block: gr.update(visible=False),
|
| 289 |
main_block: gr.update(visible=True),
|
| 290 |
+
login_message: gr.update(value=message, visible=False),
|
| 291 |
+
user_display: f"**Usuário:** {username}",
|
| 292 |
is_logged_in: True,
|
| 293 |
current_user: username
|
| 294 |
}
|
| 295 |
else:
|
| 296 |
return {
|
| 297 |
+
login_message: gr.update(value=message, visible=True),
|
| 298 |
is_logged_in: False
|
| 299 |
}
|
| 300 |
|
|
|
|
| 305 |
main_block: gr.update(visible=False),
|
| 306 |
username_input: "",
|
| 307 |
password_input: "",
|
| 308 |
+
login_message: gr.update(value="", visible=False),
|
| 309 |
is_logged_in: False,
|
| 310 |
current_user: ""
|
| 311 |
}
|
| 312 |
|
| 313 |
+
# Generate material function with progress tracking
|
| 314 |
+
def generate_material(disciplina, assunto, topicos, progress=gr.Progress()):
|
| 315 |
+
# Show progress during generation
|
| 316 |
+
progress(0, desc="Iniciando geração do material...")
|
| 317 |
+
|
| 318 |
+
# First phase - motivational content
|
| 319 |
+
progress(0.25, desc="Gerando conteúdo motivacional...")
|
| 320 |
+
|
| 321 |
+
# Second phase - study plan
|
| 322 |
+
progress(0.5, desc="Elaborando plano de estudos...")
|
| 323 |
+
|
| 324 |
+
# Third phase - gathering video resources
|
| 325 |
+
progress(0.75, desc="Pesquisando recursos de vídeo...")
|
| 326 |
+
|
| 327 |
+
# Execute the actual material generation
|
| 328 |
markdown, pdf = executar_equipe_interface(disciplina, assunto, topicos)
|
| 329 |
+
|
| 330 |
+
# Complete
|
| 331 |
+
progress(1.0, desc="Material gerado com sucesso!")
|
| 332 |
+
|
| 333 |
+
return {
|
| 334 |
+
markdown_output: markdown,
|
| 335 |
+
pdf_output: pdf,
|
| 336 |
+
progress_group: gr.update(visible=False)
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
# Show progress during generation
|
| 340 |
+
def show_progress():
|
| 341 |
+
return {
|
| 342 |
+
progress_group: gr.update(visible=True)
|
| 343 |
+
}
|
| 344 |
|
| 345 |
# Connect buttons to functions
|
| 346 |
login_button.click(
|
| 347 |
login_fn,
|
| 348 |
inputs=[username_input, password_input],
|
| 349 |
+
outputs=[login_block, main_block, login_message, user_display, is_logged_in, current_user]
|
| 350 |
)
|
| 351 |
|
| 352 |
logout_button.click(
|
|
|
|
| 356 |
)
|
| 357 |
|
| 358 |
generate_button.click(
|
| 359 |
+
show_progress,
|
| 360 |
+
outputs=[progress_group]
|
| 361 |
+
).then(
|
| 362 |
generate_material,
|
| 363 |
inputs=[disciplina_input, assunto_input, topicos_input],
|
| 364 |
+
outputs=[markdown_output, pdf_output, progress_group]
|
| 365 |
)
|
| 366 |
|
| 367 |
return app
|