Update app.py
Browse files
app.py
CHANGED
|
@@ -580,7 +580,129 @@ gamification_engine = GamificationEngine() # No necesita instanciar, es de clase
|
|
| 580 |
|
| 581 |
# --- Módulo 8: Interfaz Gradio (UI/UX Argento de Nivel Superior con Voz) ---
|
| 582 |
# Se crea el objeto demo fuera del bloque 'with' para asegurar que sea accesible globalmente
|
| 583 |
-
demo = gr.Blocks(theme=gr.themes.Soft(), css="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 584 |
|
| 585 |
with demo: # Ahora el bloque 'with' utiliza el objeto demo ya creado
|
| 586 |
# gr.State para mantener el objeto User en la sesión y el estado de la UI
|
|
@@ -621,134 +743,12 @@ with demo: # Ahora el bloque 'with' utiliza el objeto demo ya creado
|
|
| 621 |
<span style="font-size: 0.8em;">✨ Oráculo Vocal ✨</span>
|
| 622 |
<span>🇦🇷 MateAI 🇦🇷</span>
|
| 623 |
</div>
|
| 624 |
-
<style>
|
| 625 |
-
@keyframes pulse-argentina-superior {
|
| 626 |
-
0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.7); }
|
| 627 |
-
50% { transform: scale(1.05); box-shadow: 0 0 0 20px rgba(56, 189, 248, 0); }
|
| 628 |
-
100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(56, 189, 248, 0); }
|
| 629 |
-
}
|
| 630 |
-
</style>
|
| 631 |
</div>
|
| 632 |
"""
|
| 633 |
)
|
| 634 |
|
| 635 |
# --- Componentes de voz ocultos para la interacción JS ---
|
| 636 |
gr.HTML("""
|
| 637 |
-
<style>
|
| 638 |
-
@keyframes matecito-talk {
|
| 639 |
-
0% { transform: scale(1); }
|
| 640 |
-
50% { transform: scale(1.1); }
|
| 641 |
-
100% { transform: scale(1); }
|
| 642 |
-
}
|
| 643 |
-
.matecito-avatar {
|
| 644 |
-
font-size: 4em; /* Tamaño del emoji */
|
| 645 |
-
display: none; /* Oculto por defecto */
|
| 646 |
-
position: fixed;
|
| 647 |
-
bottom: 20px;
|
| 648 |
-
right: 20px;
|
| 649 |
-
z-index: 1000;
|
| 650 |
-
background: rgba(255, 255, 255, 0.9);
|
| 651 |
-
border-radius: 50%;
|
| 652 |
-
padding: 10px;
|
| 653 |
-
box-shadow: 0 4px 10px rgba(0,0,0,0.2);
|
| 654 |
-
animation: fade-in 0.3s forwards;
|
| 655 |
-
}
|
| 656 |
-
.matecito-talking {
|
| 657 |
-
animation: matecito-talk 0.8s infinite ease-in-out;
|
| 658 |
-
}
|
| 659 |
-
.matecito-listening {
|
| 660 |
-
animation: pulse-argentina-superior 1.5s infinite ease-in-out; /* Reusar la animación de pulso */
|
| 661 |
-
}
|
| 662 |
-
@keyframes fade-in {
|
| 663 |
-
from { opacity: 0; transform: scale(0.8); }
|
| 664 |
-
to { opacity: 1; transform: scale(1); }
|
| 665 |
-
}
|
| 666 |
-
@keyframes fade-out {
|
| 667 |
-
from { opacity: 1; transform: scale(1); }
|
| 668 |
-
to { opacity: 0; transform: scale(0.8); }
|
| 669 |
-
}
|
| 670 |
-
/* Estilos para el nuevo menú */
|
| 671 |
-
.menu-grid {
|
| 672 |
-
display: grid;
|
| 673 |
-
grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
|
| 674 |
-
gap: 15px;
|
| 675 |
-
padding: 20px;
|
| 676 |
-
max-width: 800px;
|
| 677 |
-
margin: 20px auto;
|
| 678 |
-
background-color: #f8fafc; /* light blue-gray */
|
| 679 |
-
border-radius: 20px;
|
| 680 |
-
box-shadow: 0 8px 20px rgba(0,0,0,0.1);
|
| 681 |
-
}
|
| 682 |
-
.menu-button-custom { /* Clase para los botones personalizados con iconos */
|
| 683 |
-
display: flex;
|
| 684 |
-
flex-direction: column;
|
| 685 |
-
align-items: center;
|
| 686 |
-
justify-content: center;
|
| 687 |
-
height: 100px;
|
| 688 |
-
background-color: #ffffff;
|
| 689 |
-
border-radius: 15px;
|
| 690 |
-
border: 1px solid #e2e8f0;
|
| 691 |
-
color: #4b5563;
|
| 692 |
-
font-weight: 600;
|
| 693 |
-
font-size: 0.9em;
|
| 694 |
-
cursor: pointer;
|
| 695 |
-
transition: all 0.2s ease-in-out;
|
| 696 |
-
text-align: center;
|
| 697 |
-
padding: 10px;
|
| 698 |
-
}
|
| 699 |
-
.menu-button-custom:hover {
|
| 700 |
-
background-color: #e0f2fe; /* sky-100 */
|
| 701 |
-
border-color: #38bdf8; /* sky-400 */
|
| 702 |
-
transform: translateY(-3px);
|
| 703 |
-
box-shadow: 0 4px 10px rgba(0,0,0,0.1);
|
| 704 |
-
}
|
| 705 |
-
.menu-button-custom .icon {
|
| 706 |
-
font-size: 2.5em; /* Tamaño del icono */
|
| 707 |
-
margin-bottom: 5px;
|
| 708 |
-
}
|
| 709 |
-
.section-content {
|
| 710 |
-
padding: 20px;
|
| 711 |
-
background-color: #ffffff;
|
| 712 |
-
border-radius: 20px;
|
| 713 |
-
box-shadow: 0 8px 20px rgba(0,0,0,0.1);
|
| 714 |
-
margin-top: 20px;
|
| 715 |
-
}
|
| 716 |
-
/* Estilos para el navegador simulado */
|
| 717 |
-
.browser-frame {
|
| 718 |
-
border: 1px solid #ccc;
|
| 719 |
-
border-radius: 8px;
|
| 720 |
-
overflow: hidden;
|
| 721 |
-
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
|
| 722 |
-
}
|
| 723 |
-
.browser-header {
|
| 724 |
-
background-color: #f1f1f1;
|
| 725 |
-
padding: 8px 12px;
|
| 726 |
-
border-bottom: 1px solid #e0e0e0;
|
| 727 |
-
display: flex;
|
| 728 |
-
align-items: center;
|
| 729 |
-
gap: 8px;
|
| 730 |
-
}
|
| 731 |
-
.browser-address-bar {
|
| 732 |
-
flex-grow: 1;
|
| 733 |
-
background-color: #fff;
|
| 734 |
-
border: 1px solid #ddd;
|
| 735 |
-
border-radius: 4px;
|
| 736 |
-
padding: 6px 10px;
|
| 737 |
-
font-size: 0.9em;
|
| 738 |
-
color: #333;
|
| 739 |
-
}
|
| 740 |
-
.browser-content {
|
| 741 |
-
width: 100%;
|
| 742 |
-
height: 400px; /* Altura fija para la simulación */
|
| 743 |
-
background-color: #f9f9f9;
|
| 744 |
-
display: flex;
|
| 745 |
-
align-items: center;
|
| 746 |
-
justify-content: center;
|
| 747 |
-
font-size: 1.2em;
|
| 748 |
-
color: #666;
|
| 749 |
-
text-align: center;
|
| 750 |
-
}
|
| 751 |
-
</style>
|
| 752 |
<div id="matecito_avatar" class="matecito-avatar">🧉</div>
|
| 753 |
<script>
|
| 754 |
let recognition;
|
|
@@ -898,17 +898,6 @@ with demo: # Ahora el bloque 'with' utiliza el objeto demo ya creado
|
|
| 898 |
|
| 899 |
// Expose the speakText function globally for Gradio to call it
|
| 900 |
window.speakText = speakText;
|
| 901 |
-
|
| 902 |
-
// Function to change Gradio view (called from custom HTML buttons)
|
| 903 |
-
function changeGradioView(viewName) {
|
| 904 |
-
const hiddenButton = document.getElementById('hidden_view_changer_button');
|
| 905 |
-
const viewInput = document.getElementById('hidden_view_input');
|
| 906 |
-
if (hiddenButton && viewInput) {
|
| 907 |
-
viewInput.value = viewName;
|
| 908 |
-
hiddenButton.click();
|
| 909 |
-
}
|
| 910 |
-
}
|
| 911 |
-
window.changeGradioView = changeGradioView; // Expose globally
|
| 912 |
</script>
|
| 913 |
""")
|
| 914 |
# Input oculto para el texto reconocido por voz
|
|
@@ -918,10 +907,6 @@ with demo: # Ahora el bloque 'with' utiliza el objeto demo ya creado
|
|
| 918 |
# Output oculto para el texto que MateAI debe vocalizar
|
| 919 |
voice_output_text = gr.Textbox(elem_id="voice_output_text", visible=False)
|
| 920 |
|
| 921 |
-
# Componentes ocultos para el cambio de vista desde JS
|
| 922 |
-
hidden_view_input = gr.Textbox(elem_id="hidden_view_input", visible=False)
|
| 923 |
-
hidden_view_changer_button = gr.Button("Change View", elem_id="hidden_view_changer_button", visible=False)
|
| 924 |
-
|
| 925 |
gr.Markdown("<p id='voice_status' style='text-align: center; font-weight: bold; color: #4b5563;'>Listo para hablar 🎤</p>")
|
| 926 |
gr.Button("🎙️ Empezar a Hablar con MateAI 🎙️", variant="secondary", elem_id="start_voice_button").click(
|
| 927 |
fn=None,
|
|
@@ -930,37 +915,138 @@ with demo: # Ahora el bloque 'with' utiliza el objeto demo ya creado
|
|
| 930 |
js="startListening()"
|
| 931 |
)
|
| 932 |
|
| 933 |
-
# --- Nuevo Menú de Navegación con
|
| 934 |
gr.Markdown("<h2 style='text-align: center; color: #38bdf8; margin-top: 2em;'>Navegación MateAI</h2>")
|
| 935 |
-
gr.
|
| 936 |
-
|
| 937 |
-
|
| 938 |
-
<div class="
|
| 939 |
-
|
| 940 |
-
|
| 941 |
-
|
| 942 |
-
|
| 943 |
-
|
| 944 |
-
|
| 945 |
-
|
| 946 |
-
|
| 947 |
-
|
| 948 |
-
|
| 949 |
-
|
| 950 |
-
|
| 951 |
-
|
| 952 |
-
|
| 953 |
-
|
| 954 |
-
|
| 955 |
-
|
| 956 |
-
<div class="
|
| 957 |
-
|
| 958 |
-
|
| 959 |
-
|
| 960 |
-
|
| 961 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 962 |
|
| 963 |
-
# --- Contenido de cada Sección
|
| 964 |
# Todas las secciones deben ser definidas aquí para poder ser referenciadas en los outputs
|
| 965 |
home_section = gr.Column(elem_id="home_section", elem_classes="section-content", visible=True)
|
| 966 |
nudges_section = gr.Column(elem_id="nudges_section", elem_classes="section-content", visible=False)
|
|
@@ -1145,26 +1231,26 @@ with demo: # Ahora el bloque 'with' utiliza el objeto demo ya creado
|
|
| 1145 |
def change_view(view_name):
|
| 1146 |
# Create a dictionary to hold updates for each section
|
| 1147 |
updates = {
|
| 1148 |
-
"
|
| 1149 |
-
"
|
| 1150 |
-
"
|
| 1151 |
-
"
|
| 1152 |
-
"
|
| 1153 |
-
"
|
| 1154 |
-
"
|
| 1155 |
}
|
| 1156 |
# Set the selected section to visible
|
| 1157 |
-
updates[view_name
|
| 1158 |
|
| 1159 |
# Return the updates in a consistent order, followed by the state update
|
| 1160 |
return (
|
| 1161 |
-
updates["
|
| 1162 |
-
updates["
|
| 1163 |
-
updates["
|
| 1164 |
-
updates["
|
| 1165 |
-
updates["
|
| 1166 |
-
updates["
|
| 1167 |
-
updates["
|
| 1168 |
view_name # This is the current_view_state output
|
| 1169 |
)
|
| 1170 |
|
|
@@ -1565,16 +1651,5 @@ with demo: # Ahora el bloque 'with' utiliza el objeto demo ya creado
|
|
| 1565 |
js="text => window.speakText(text)"
|
| 1566 |
)
|
| 1567 |
|
| 1568 |
-
# --- Conexión del botón oculto de cambio de vista ---
|
| 1569 |
-
hidden_view_changer_button.click(
|
| 1570 |
-
fn=change_view,
|
| 1571 |
-
inputs=[hidden_view_input],
|
| 1572 |
-
outputs=[
|
| 1573 |
-
home_section, nudges_section, oracle_section,
|
| 1574 |
-
challenges_section, history_section, tasks_section,
|
| 1575 |
-
browser_agent_section, current_view_state
|
| 1576 |
-
]
|
| 1577 |
-
)
|
| 1578 |
-
|
| 1579 |
# Lanza la interfaz de Gradio
|
| 1580 |
demo.launch()
|
|
|
|
| 580 |
|
| 581 |
# --- Módulo 8: Interfaz Gradio (UI/UX Argento de Nivel Superior con Voz) ---
|
| 582 |
# Se crea el objeto demo fuera del bloque 'with' para asegurar que sea accesible globalmente
|
| 583 |
+
demo = gr.Blocks(theme=gr.themes.Soft(), css="""
|
| 584 |
+
footer { display: none !important; }
|
| 585 |
+
@keyframes matecito-talk {
|
| 586 |
+
0% { transform: scale(1); }
|
| 587 |
+
50% { transform: scale(1.1); }
|
| 588 |
+
100% { transform: scale(1); }
|
| 589 |
+
}
|
| 590 |
+
.matecito-avatar {
|
| 591 |
+
font-size: 4em; /* Tamaño del emoji */
|
| 592 |
+
display: none; /* Oculto por defecto */
|
| 593 |
+
position: fixed;
|
| 594 |
+
bottom: 20px;
|
| 595 |
+
right: 20px;
|
| 596 |
+
z-index: 1000;
|
| 597 |
+
background: rgba(255, 255, 255, 0.9);
|
| 598 |
+
border-radius: 50%;
|
| 599 |
+
padding: 10px;
|
| 600 |
+
box-shadow: 0 4px 10px rgba(0,0,0,0.2);
|
| 601 |
+
animation: fade-in 0.3s forwards;
|
| 602 |
+
}
|
| 603 |
+
.matecito-talking {
|
| 604 |
+
animation: matecito-talk 0.8s infinite ease-in-out;
|
| 605 |
+
}
|
| 606 |
+
.matecito-listening {
|
| 607 |
+
animation: pulse-argentina-superior 1.5s infinite ease-in-out; /* Reusar la animación de pulso */
|
| 608 |
+
}
|
| 609 |
+
@keyframes fade-in {
|
| 610 |
+
from { opacity: 0; transform: scale(0.8); }
|
| 611 |
+
to { opacity: 1; transform: scale(1); }
|
| 612 |
+
}
|
| 613 |
+
@keyframes fade-out {
|
| 614 |
+
from { opacity: 1; transform: scale(1); }
|
| 615 |
+
to { opacity: 0; transform: scale(0.8); }
|
| 616 |
+
}
|
| 617 |
+
/* Estilos para el nuevo menú */
|
| 618 |
+
.menu-grid {
|
| 619 |
+
display: grid;
|
| 620 |
+
grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
|
| 621 |
+
gap: 15px;
|
| 622 |
+
padding: 20px;
|
| 623 |
+
max-width: 800px;
|
| 624 |
+
margin: 20px auto;
|
| 625 |
+
background-color: #f8fafc; /* light blue-gray */
|
| 626 |
+
border-radius: 20px;
|
| 627 |
+
box-shadow: 0 8px 20px rgba(0,0,0,0.1);
|
| 628 |
+
}
|
| 629 |
+
/* Aplicar a los botones de Gradio */
|
| 630 |
+
.menu-button-custom .wrap-inner.gr-button { /* Target the inner button element */
|
| 631 |
+
display: flex;
|
| 632 |
+
flex-direction: column;
|
| 633 |
+
align-items: center;
|
| 634 |
+
justify-content: center;
|
| 635 |
+
height: 100px;
|
| 636 |
+
background-color: #ffffff;
|
| 637 |
+
border-radius: 15px;
|
| 638 |
+
border: 1px solid #e2e8f0;
|
| 639 |
+
color: #4b5563;
|
| 640 |
+
font-weight: 600;
|
| 641 |
+
font-size: 0.9em;
|
| 642 |
+
cursor: pointer;
|
| 643 |
+
transition: all 0.2s ease-in-out;
|
| 644 |
+
text-align: center;
|
| 645 |
+
padding: 10px;
|
| 646 |
+
}
|
| 647 |
+
.menu-button-custom .wrap-inner.gr-button:hover {
|
| 648 |
+
background-color: #e0f2fe; /* sky-100 */
|
| 649 |
+
border-color: #38bdf8; /* sky-400 */
|
| 650 |
+
transform: translateY(-3px);
|
| 651 |
+
box-shadow: 0 4px 10px rgba(0,0,0,0.1);
|
| 652 |
+
}
|
| 653 |
+
.menu-button-custom .icon {
|
| 654 |
+
font-size: 2.5em; /* Tamaño del icono */
|
| 655 |
+
margin-bottom: 5px;
|
| 656 |
+
}
|
| 657 |
+
.section-content {
|
| 658 |
+
padding: 20px;
|
| 659 |
+
background-color: #ffffff;
|
| 660 |
+
border-radius: 20px;
|
| 661 |
+
box-shadow: 0 8px 20px rgba(0,0,0,0.1);
|
| 662 |
+
margin-top: 20px;
|
| 663 |
+
}
|
| 664 |
+
/* Estilos para el navegador simulado */
|
| 665 |
+
.browser-frame {
|
| 666 |
+
border: 1px solid #ccc;
|
| 667 |
+
border-radius: 8px;
|
| 668 |
+
overflow: hidden;
|
| 669 |
+
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
|
| 670 |
+
}
|
| 671 |
+
.browser-header {
|
| 672 |
+
background-color: #f1f1f1;
|
| 673 |
+
padding: 8px 12px;
|
| 674 |
+
border-bottom: 1px solid #e0e0e0;
|
| 675 |
+
display: flex;
|
| 676 |
+
align-items: center;
|
| 677 |
+
gap: 8px;
|
| 678 |
+
}
|
| 679 |
+
.browser-address-bar {
|
| 680 |
+
flex-grow: 1;
|
| 681 |
+
background-color: #fff;
|
| 682 |
+
border: 1px solid #ddd;
|
| 683 |
+
border-radius: 4px;
|
| 684 |
+
padding: 6px 10px;
|
| 685 |
+
font-size: 0.9em;
|
| 686 |
+
color: #333;
|
| 687 |
+
}
|
| 688 |
+
.browser-content {
|
| 689 |
+
width: 100%;
|
| 690 |
+
height: 400px; /* Altura fija para la simulación */
|
| 691 |
+
background-color: #f9f9f9;
|
| 692 |
+
display: flex;
|
| 693 |
+
flex-direction: column; /* Allow content to stack */
|
| 694 |
+
align-items: center;
|
| 695 |
+
justify-content: center;
|
| 696 |
+
font-size: 1.2em;
|
| 697 |
+
color: #666;
|
| 698 |
+
text-align: center;
|
| 699 |
+
}
|
| 700 |
+
@keyframes pulse-argentina-superior {
|
| 701 |
+
0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.7); }
|
| 702 |
+
50% { transform: scale(1.05); box-shadow: 0 0 0 20px rgba(56, 189, 248, 0); }
|
| 703 |
+
100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(56, 189, 248, 0); }
|
| 704 |
+
}
|
| 705 |
+
""")
|
| 706 |
|
| 707 |
with demo: # Ahora el bloque 'with' utiliza el objeto demo ya creado
|
| 708 |
# gr.State para mantener el objeto User en la sesión y el estado de la UI
|
|
|
|
| 743 |
<span style="font-size: 0.8em;">✨ Oráculo Vocal ✨</span>
|
| 744 |
<span>🇦🇷 MateAI 🇦🇷</span>
|
| 745 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 746 |
</div>
|
| 747 |
"""
|
| 748 |
)
|
| 749 |
|
| 750 |
# --- Componentes de voz ocultos para la interacción JS ---
|
| 751 |
gr.HTML("""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 752 |
<div id="matecito_avatar" class="matecito-avatar">🧉</div>
|
| 753 |
<script>
|
| 754 |
let recognition;
|
|
|
|
| 898 |
|
| 899 |
// Expose the speakText function globally for Gradio to call it
|
| 900 |
window.speakText = speakText;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 901 |
</script>
|
| 902 |
""")
|
| 903 |
# Input oculto para el texto reconocido por voz
|
|
|
|
| 907 |
# Output oculto para el texto que MateAI debe vocalizar
|
| 908 |
voice_output_text = gr.Textbox(elem_id="voice_output_text", visible=False)
|
| 909 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 910 |
gr.Markdown("<p id='voice_status' style='text-align: center; font-weight: bold; color: #4b5563;'>Listo para hablar 🎤</p>")
|
| 911 |
gr.Button("🎙️ Empezar a Hablar con MateAI 🎙️", variant="secondary", elem_id="start_voice_button").click(
|
| 912 |
fn=None,
|
|
|
|
| 915 |
js="startListening()"
|
| 916 |
)
|
| 917 |
|
| 918 |
+
# --- Nuevo Menú de Navegación con Gradio Buttons ---
|
| 919 |
gr.Markdown("<h2 style='text-align: center; color: #38bdf8; margin-top: 2em;'>Navegación MateAI</h2>")
|
| 920 |
+
with gr.Row(elem_classes="menu-grid"):
|
| 921 |
+
# Cada botón ahora es un gr.Button con estilo personalizado
|
| 922 |
+
gr.Button(
|
| 923 |
+
value="""<div class="icon">🏠</div>Inicio & Perfil""",
|
| 924 |
+
elem_classes="menu-button-custom",
|
| 925 |
+
variant="secondary"
|
| 926 |
+
).click(
|
| 927 |
+
fn=lambda: change_view('home'),
|
| 928 |
+
inputs=[],
|
| 929 |
+
outputs=[
|
| 930 |
+
gr.Column.update(visible=True), # home_section
|
| 931 |
+
gr.Column.update(visible=False), # nudges_section
|
| 932 |
+
gr.Column.update(visible=False), # oracle_section
|
| 933 |
+
gr.Column.update(visible=False), # challenges_section
|
| 934 |
+
gr.Column.update(visible=False), # history_section
|
| 935 |
+
gr.Column.update(visible=False), # tasks_section
|
| 936 |
+
gr.Column.update(visible=False), # browser_agent_section
|
| 937 |
+
current_view_state # Update the state
|
| 938 |
+
]
|
| 939 |
+
)
|
| 940 |
+
gr.Button(
|
| 941 |
+
value="""<div class="icon">💬</div>Conversar con MateAI""",
|
| 942 |
+
elem_classes="menu-button-custom",
|
| 943 |
+
variant="secondary"
|
| 944 |
+
).click(
|
| 945 |
+
fn=lambda: change_view('nudges'),
|
| 946 |
+
inputs=[],
|
| 947 |
+
outputs=[
|
| 948 |
+
gr.Column.update(visible=False), # home_section
|
| 949 |
+
gr.Column.update(visible=True), # nudges_section
|
| 950 |
+
gr.Column.update(visible=False), # oracle_section
|
| 951 |
+
gr.Column.update(visible=False), # challenges_section
|
| 952 |
+
gr.Column.update(visible=False), # history_section
|
| 953 |
+
gr.Column.update(visible=False), # tasks_section
|
| 954 |
+
gr.Column.update(visible=False), # browser_agent_section
|
| 955 |
+
current_view_state
|
| 956 |
+
]
|
| 957 |
+
)
|
| 958 |
+
gr.Button(
|
| 959 |
+
value="""<div class="icon">✨</div>Oráculo del Día""",
|
| 960 |
+
elem_classes="menu-button-custom",
|
| 961 |
+
variant="secondary"
|
| 962 |
+
).click(
|
| 963 |
+
fn=lambda: change_view('oracle'),
|
| 964 |
+
inputs=[],
|
| 965 |
+
outputs=[
|
| 966 |
+
gr.Column.update(visible=False), # home_section
|
| 967 |
+
gr.Column.update(visible=False), # nudges_section
|
| 968 |
+
gr.Column.update(visible=True), # oracle_section
|
| 969 |
+
gr.Column.update(visible=False), # challenges_section
|
| 970 |
+
gr.Column.update(visible=False), # history_section
|
| 971 |
+
gr.Column.update(visible=False), # tasks_section
|
| 972 |
+
gr.Column.update(visible=False), # browser_agent_section
|
| 973 |
+
current_view_state
|
| 974 |
+
]
|
| 975 |
+
)
|
| 976 |
+
gr.Button(
|
| 977 |
+
value="""<div class="icon">🎯</div>Desafíos MateAI""",
|
| 978 |
+
elem_classes="menu-button-custom",
|
| 979 |
+
variant="secondary"
|
| 980 |
+
).click(
|
| 981 |
+
fn=lambda: change_view('challenges'),
|
| 982 |
+
inputs=[],
|
| 983 |
+
outputs=[
|
| 984 |
+
gr.Column.update(visible=False), # home_section
|
| 985 |
+
gr.Column.update(visible=False), # nudges_section
|
| 986 |
+
gr.Column.update(visible=False), # oracle_section
|
| 987 |
+
gr.Column.update(visible=True), # challenges_section
|
| 988 |
+
gr.Column.update(visible=False), # history_section
|
| 989 |
+
gr.Column.update(visible=False), # tasks_section
|
| 990 |
+
gr.Column.update(visible=False), # browser_agent_section
|
| 991 |
+
current_view_state
|
| 992 |
+
]
|
| 993 |
+
)
|
| 994 |
+
gr.Button(
|
| 995 |
+
value="""<div class="icon">📝</div>Mi Gestor de Tareas""",
|
| 996 |
+
elem_classes="menu-button-custom",
|
| 997 |
+
variant="secondary"
|
| 998 |
+
).click(
|
| 999 |
+
fn=lambda: change_view('tasks'),
|
| 1000 |
+
inputs=[],
|
| 1001 |
+
outputs=[
|
| 1002 |
+
gr.Column.update(visible=False), # home_section
|
| 1003 |
+
gr.Column.update(visible=False), # nudges_section
|
| 1004 |
+
gr.Column.update(visible=False), # oracle_section
|
| 1005 |
+
gr.Column.update(visible=False), # challenges_section
|
| 1006 |
+
gr.Column.update(visible=False), # history_section
|
| 1007 |
+
gr.Column.update(visible=True), # tasks_section
|
| 1008 |
+
gr.Column.update(visible=False), # browser_agent_section
|
| 1009 |
+
current_view_state
|
| 1010 |
+
]
|
| 1011 |
+
)
|
| 1012 |
+
gr.Button(
|
| 1013 |
+
value="""<div class="icon">📜</div>Mi Historial & Logros""",
|
| 1014 |
+
elem_classes="menu-button-custom",
|
| 1015 |
+
variant="secondary"
|
| 1016 |
+
).click(
|
| 1017 |
+
fn=lambda: change_view('history'),
|
| 1018 |
+
inputs=[],
|
| 1019 |
+
outputs=[
|
| 1020 |
+
gr.Column.update(visible=False), # home_section
|
| 1021 |
+
gr.Column.update(visible=False), # nudges_section
|
| 1022 |
+
gr.Column.update(visible=False), # oracle_section
|
| 1023 |
+
gr.Column.update(visible=False), # challenges_section
|
| 1024 |
+
gr.Column.update(visible=True), # history_section
|
| 1025 |
+
gr.Column.update(visible=False), # tasks_section
|
| 1026 |
+
gr.Column.update(visible=False), # browser_agent_section
|
| 1027 |
+
current_view_state
|
| 1028 |
+
]
|
| 1029 |
+
)
|
| 1030 |
+
gr.Button(
|
| 1031 |
+
value="""<div class="icon">🌐</div>Asistente Web (Concepto)""",
|
| 1032 |
+
elem_classes="menu-button-custom",
|
| 1033 |
+
variant="secondary"
|
| 1034 |
+
).click(
|
| 1035 |
+
fn=lambda: change_view('browser_agent'),
|
| 1036 |
+
inputs=[],
|
| 1037 |
+
outputs=[
|
| 1038 |
+
gr.Column.update(visible=False), # home_section
|
| 1039 |
+
gr.Column.update(visible=False), # nudges_section
|
| 1040 |
+
gr.Column.update(visible=False), # oracle_section
|
| 1041 |
+
gr.Column.update(visible=False), # challenges_section
|
| 1042 |
+
gr.Column.update(visible=False), # history_section
|
| 1043 |
+
gr.Column.update(visible=False), # tasks_section
|
| 1044 |
+
gr.Column.update(visible=True), # browser_agent_section
|
| 1045 |
+
current_view_state
|
| 1046 |
+
]
|
| 1047 |
+
)
|
| 1048 |
|
| 1049 |
+
# --- Contenido de cada Sección ---
|
| 1050 |
# Todas las secciones deben ser definidas aquí para poder ser referenciadas en los outputs
|
| 1051 |
home_section = gr.Column(elem_id="home_section", elem_classes="section-content", visible=True)
|
| 1052 |
nudges_section = gr.Column(elem_id="nudges_section", elem_classes="section-content", visible=False)
|
|
|
|
| 1231 |
def change_view(view_name):
|
| 1232 |
# Create a dictionary to hold updates for each section
|
| 1233 |
updates = {
|
| 1234 |
+
"home": gr.Column.update(visible=False),
|
| 1235 |
+
"nudges": gr.Column.update(visible=False),
|
| 1236 |
+
"oracle": gr.Column.update(visible=False),
|
| 1237 |
+
"challenges": gr.Column.update(visible=False),
|
| 1238 |
+
"history": gr.Column.update(visible=False),
|
| 1239 |
+
"tasks": gr.Column.update(visible=False),
|
| 1240 |
+
"browser_agent": gr.Column.update(visible=False),
|
| 1241 |
}
|
| 1242 |
# Set the selected section to visible
|
| 1243 |
+
updates[view_name] = gr.Column.update(visible=True)
|
| 1244 |
|
| 1245 |
# Return the updates in a consistent order, followed by the state update
|
| 1246 |
return (
|
| 1247 |
+
updates["home"],
|
| 1248 |
+
updates["nudges"],
|
| 1249 |
+
updates["oracle"],
|
| 1250 |
+
updates["challenges"],
|
| 1251 |
+
updates["history"],
|
| 1252 |
+
updates["tasks"],
|
| 1253 |
+
updates["browser_agent"],
|
| 1254 |
view_name # This is the current_view_state output
|
| 1255 |
)
|
| 1256 |
|
|
|
|
| 1651 |
js="text => window.speakText(text)"
|
| 1652 |
)
|
| 1653 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1654 |
# Lanza la interfaz de Gradio
|
| 1655 |
demo.launch()
|