File size: 4,560 Bytes
97a4bf8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# app.py - Módulo para src
import streamlit as st
from streamlit_option_menu import option_menu
import streamlit_lottie as st_lottie
import json
import google.generativeai as genai
from dotenv import load_dotenv
import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

# Importaciones locales
from datos.upload import show_upload
from datos.prepare import show_prepare
from models.train import show_train
from models.test import show_test
from models.unsupervised import show_unsupervised

# Configuración inicial
st.set_page_config(initial_sidebar_state="collapsed", page_title="Machine Learning", page_icon="🤖", layout="wide")
load_dotenv()

# Función para cargar el archivo Lottie
def load_lottie_file(filepath: str):
    try:
        # Construir ruta absoluta
        base_path = os.path.dirname(os.path.abspath(__file__))
        full_path = os.path.join(base_path, 'assets', filepath)
        
        with open(full_path, 'r') as f:
            return json.load(f)
    except FileNotFoundError:
        st.error(f"Archivo Lottie no encontrado: {full_path}")
        return None

# Configuración del sidebar
with st.sidebar:
    # Cargar y mostrar el logo animado
    try:
        gemini_logo = load_lottie_file('gemini_logo.json')
        if gemini_logo:
            st_lottie.st_lottie(
                gemini_logo, 
                key='logo', 
                height=50,
                width=50,
                loop=True,
                quality="low"
            )
    except Exception as e:
        st.error(f"Error al cargar el logo: {e}")
    
    # Sección de API Keys
    st.markdown("### Configuración de APIs")
    
    # Gemini API
    st.markdown('''
        [Consigue tu API Key de Google AI Studio](https://aistudio.google.com/app/apikey)
    ''')
    genai_api_key = st.text_input(
        "Gemini API Key",
        type="password", 
        placeholder="Ingresa tu API Key de Gemini",
        key='gemini_api_key'
    )

    # Supabase API
    st.markdown('''
        [Consigue tus credenciales de Supabase](https://supabase.com/dashboard/project/_/settings/api)
    ''')
    supabase_url = st.text_input(
        "Supabase URL",
        type="password",
        placeholder="Ingresa tu Supabase URL",
        key='supabase_url'
    )
    
    supabase_key = st.text_input(
        "Supabase Key",
        type="password",
        placeholder="Ingresa tu Supabase Key",
        key='supabase_key'
    )

    # Validación de credenciales
    if not all([genai_api_key, supabase_url, supabase_key]):
        st.warning("Por favor ingresa todas las credenciales necesarias.")
    else:
        genai.configure(api_key=genai_api_key)
        model = genai.GenerativeModel('gemini-1.5-flash')
        st.success("✅ Credenciales configuradas correctamente")

    st.sidebar.markdown(
        f'''
        <div style="text-align: center; margin-bottom: 20px;">
            <a href="https://jersonalvr.shinyapps.io/prophet/" target="_blank" style="text-decoration: none; color: inherit;">Analizar series temporales</a>
            <br></br>
            Elaborado por 
            <a href="https://www.linkedin.com/in/jersonalvr" target="_blank" style="text-decoration: none; color: inherit;">
                <img src="https://cdn-icons-png.flaticon.com/512/174/174857.png" alt="LinkedIn" width="20" style="vertical-align: middle; margin-right: 5px;"/>
                Jerson Ruiz Alva
            </a>
        </div>
        ''',
        unsafe_allow_html=True
    )

# Configuración de estilos de navegación
pages = ["Upload", "Prepare", "Training", "ModelTest", "Unsupervised"]

selected_page = option_menu(
    None,
    options=pages,
    icons=['cloud-upload', 'gear', 'robot', 'folder-check', 'search'],
    default_index=0,
    orientation="horizontal",
    styles={
        "container": {"padding": "0!important", "background-color": None},
        "icon": {"color": None, "font-size": "20px"}, 
        "nav-link": {
            "font-size": "15px",
            "text-align": "center",
            "margin": "0px",
            "--hover-color": "rgba(15, 21, 34, 0.25)",
        },
        "nav-link-selected": {"background-color": "rgba(15, 21, 34, 1)"},
    }
)

# The rest of the page routing remains the same
if selected_page == "Upload":
    show_upload()
elif selected_page == "Prepare":
    show_prepare()
elif selected_page == "Training":
    show_train()
elif selected_page == "Test":
    show_test()
elif selected_page == "Unsupervised":
    show_unsupervised()