Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,15 +2,15 @@ import torch
|
|
| 2 |
import gradio as gr
|
| 3 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
# 1.
|
| 7 |
-
#
|
| 8 |
|
| 9 |
MODEL_ID = "DavidBazaldua/llama3_finetuned_transformes"
|
| 10 |
-
DEVICE = "cpu"
|
| 11 |
DTYPE = torch.float32
|
| 12 |
|
| 13 |
-
|
| 14 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
|
| 15 |
model = AutoModelForCausalLM.from_pretrained(
|
| 16 |
MODEL_ID,
|
|
@@ -19,6 +19,7 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
| 19 |
)
|
| 20 |
model.to(DEVICE)
|
| 21 |
model.eval()
|
|
|
|
| 22 |
|
| 23 |
DEFAULT_SYSTEM_PROMPT = (
|
| 24 |
"You are a helpful, precise AI assistant. "
|
|
@@ -26,29 +27,29 @@ DEFAULT_SYSTEM_PROMPT = (
|
|
| 26 |
"Respond in English unless the user asks otherwise."
|
| 27 |
)
|
| 28 |
|
| 29 |
-
#
|
| 30 |
-
# 2.
|
| 31 |
-
#
|
| 32 |
|
| 33 |
def build_prompt(system_prompt, context, history, user_message):
|
| 34 |
messages = []
|
| 35 |
-
#
|
| 36 |
if system_prompt and system_prompt.strip():
|
| 37 |
messages.append({"role": "system", "content": system_prompt})
|
| 38 |
|
| 39 |
-
# Contexto
|
| 40 |
if context and context.strip():
|
| 41 |
messages.append({
|
| 42 |
"role": "system",
|
| 43 |
"content": f"Use the following context if relevant:\n{context}"
|
| 44 |
})
|
| 45 |
|
| 46 |
-
# Historial
|
| 47 |
for user, assistant in history:
|
| 48 |
messages.append({"role": "user", "content": user})
|
| 49 |
messages.append({"role": "assistant", "content": assistant})
|
| 50 |
|
| 51 |
-
# Mensaje actual
|
| 52 |
messages.append({"role": "user", "content": user_message})
|
| 53 |
|
| 54 |
prompt = tokenizer.apply_chat_template(
|
|
@@ -59,13 +60,17 @@ def build_prompt(system_prompt, context, history, user_message):
|
|
| 59 |
return prompt
|
| 60 |
|
| 61 |
def chat_logic(message, history, system_prompt, context, max_tokens, temperature, top_p):
|
|
|
|
|
|
|
|
|
|
| 62 |
if history is None:
|
| 63 |
history = []
|
| 64 |
|
| 65 |
if not system_prompt:
|
| 66 |
system_prompt = DEFAULT_SYSTEM_PROMPT
|
| 67 |
|
| 68 |
-
|
|
|
|
| 69 |
|
| 70 |
prompt = build_prompt(system_prompt, context, history, message)
|
| 71 |
|
|
@@ -83,26 +88,25 @@ def chat_logic(message, history, system_prompt, context, max_tokens, temperature
|
|
| 83 |
|
| 84 |
decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 85 |
|
| 86 |
-
#
|
| 87 |
if decoded.startswith(prompt):
|
| 88 |
answer = decoded[len(prompt):].strip()
|
| 89 |
else:
|
| 90 |
-
# Fallback
|
| 91 |
-
# (Depende de cómo funcione el modelo específico, a veces devuelve todo)
|
| 92 |
answer = decoded.split("assistant\n")[-1].strip()
|
| 93 |
|
| 94 |
history.append((message, answer))
|
| 95 |
return "", history
|
| 96 |
|
| 97 |
-
#
|
| 98 |
-
# 3.
|
| 99 |
-
#
|
| 100 |
|
| 101 |
-
# CSS para
|
| 102 |
CSS = """
|
| 103 |
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700&display=swap');
|
| 104 |
|
| 105 |
-
/* --- FORZAR
|
| 106 |
:root, .dark, body, .gradio-container {
|
| 107 |
--body-text-color: #1f2937 !important;
|
| 108 |
--body-background-fill: transparent !important;
|
|
@@ -111,50 +115,46 @@ CSS = """
|
|
| 111 |
--block-background-fill: transparent !important;
|
| 112 |
--block-border-color: rgba(255,255,255, 0.4) !important;
|
| 113 |
--input-background-fill: rgba(255, 255, 255, 0.9) !important;
|
|
|
|
| 114 |
}
|
| 115 |
|
| 116 |
body {
|
| 117 |
font-family: 'Inter', sans-serif !important;
|
| 118 |
-
/*
|
| 119 |
background: radial-gradient(circle at 10% 10%, #ffeef8 0%, #edf6ff 50%, #f7f0ff 90%) !important;
|
| 120 |
color: #1f2937 !important;
|
| 121 |
margin: 0; padding: 0;
|
|
|
|
| 122 |
}
|
| 123 |
|
| 124 |
-
/*
|
| 125 |
-
h1 { font-weight: 700 !important; color: #111827 !important; }
|
| 126 |
p, span, label { color: #4b5563 !important; }
|
| 127 |
|
| 128 |
-
/* ---
|
| 129 |
.config-card {
|
| 130 |
-
background: rgba(255, 255, 255, 0.
|
| 131 |
-
border: 1px solid rgba(255, 255, 255, 0.
|
| 132 |
backdrop-filter: blur(12px);
|
| 133 |
border-radius: 24px;
|
| 134 |
padding: 24px;
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
/* Evitar que los grupos internos se pongan negros */
|
| 138 |
-
.config-card .gr-form,
|
| 139 |
-
.config-card .gr-box,
|
| 140 |
-
.config-card .gr-block {
|
| 141 |
-
background: transparent !important;
|
| 142 |
-
border: none !important;
|
| 143 |
}
|
| 144 |
|
| 145 |
/* Inputs y Sliders */
|
| 146 |
-
textarea, input[type="text"] {
|
| 147 |
-
background-color: rgba(255, 255, 255, 0.
|
| 148 |
color: #111827 !important;
|
| 149 |
border: 1px solid #e5e7eb !important;
|
| 150 |
border-radius: 12px !important;
|
|
|
|
| 151 |
}
|
| 152 |
input[type=range] { accent-color: #111827; }
|
| 153 |
|
| 154 |
-
/* --- VENTANA DE CHAT (
|
| 155 |
.chat-window {
|
| 156 |
-
background: rgba(255, 255, 255, 0.
|
| 157 |
-
border: 1px solid rgba(255, 255, 255, 0.
|
| 158 |
backdrop-filter: blur(20px);
|
| 159 |
border-radius: 24px;
|
| 160 |
box-shadow: 0 20px 50px rgba(0,0,0,0.05);
|
|
@@ -164,34 +164,37 @@ input[type=range] { accent-color: #111827; }
|
|
| 164 |
|
| 165 |
/* Header tipo Mac */
|
| 166 |
.window-header {
|
| 167 |
-
padding: 20px 24px 10px 24px;
|
| 168 |
display: flex; gap: 8px; align-items: center;
|
|
|
|
|
|
|
| 169 |
}
|
| 170 |
.dot { width: 12px; height: 12px; border-radius: 50%; }
|
| 171 |
.red { background-color: #ff5f56; }
|
| 172 |
.yellow { background-color: #ffbd2e; }
|
| 173 |
.green { background-color: #27c93f; }
|
| 174 |
|
| 175 |
-
/*
|
| 176 |
#chatbot {
|
| 177 |
background: transparent !important;
|
| 178 |
-
|
|
|
|
| 179 |
}
|
| 180 |
|
| 181 |
-
/*
|
| 182 |
.message.user {
|
| 183 |
-
background-color: #111827 !important;
|
| 184 |
color: white !important;
|
| 185 |
border-radius: 18px 18px 4px 18px !important;
|
| 186 |
}
|
| 187 |
.message.bot {
|
| 188 |
-
background-color: #ffffff !important;
|
| 189 |
color: #111827 !important;
|
| 190 |
border: 1px solid #e5e7eb !important;
|
| 191 |
border-radius: 18px 18px 18px 4px !important;
|
|
|
|
| 192 |
}
|
| 193 |
|
| 194 |
-
/* Input
|
| 195 |
.chat-input-area {
|
| 196 |
padding: 16px 24px 24px 24px;
|
| 197 |
display: flex; gap: 10px; align-items: center;
|
|
@@ -199,22 +202,55 @@ input[type=range] { accent-color: #111827; }
|
|
| 199 |
#msg-box textarea {
|
| 200 |
border-radius: 99px !important;
|
| 201 |
background: #ffffff !important;
|
| 202 |
-
|
|
|
|
|
|
|
| 203 |
}
|
| 204 |
#send-btn {
|
| 205 |
background: #111827 !important;
|
| 206 |
color: white !important;
|
| 207 |
border-radius: 50% !important;
|
| 208 |
-
width:
|
|
|
|
|
|
|
| 209 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
"""
|
| 211 |
|
| 212 |
-
|
|
|
|
| 213 |
|
| 214 |
-
with gr.Row():
|
| 215 |
-
|
| 216 |
-
# COLUMNA IZQUIERDA:
|
| 217 |
-
# -----------------------------------------------------------------
|
| 218 |
with gr.Column(scale=4):
|
| 219 |
gr.Markdown(
|
| 220 |
"""
|
|
@@ -228,68 +264,55 @@ with gr.Blocks(css=CSS, title="Custom AI Layout") as demo:
|
|
| 228 |
with gr.Group(elem_classes="config-card"):
|
| 229 |
gr.Markdown("### ⚙️ Configuración")
|
| 230 |
|
| 231 |
-
# Contexto
|
| 232 |
context_input = gr.Textbox(
|
| 233 |
label="Contexto (Data)",
|
| 234 |
-
placeholder="Pega aquí
|
| 235 |
-
lines=
|
| 236 |
)
|
| 237 |
|
| 238 |
-
# System Prompt
|
| 239 |
system_prompt_input = gr.Textbox(
|
| 240 |
label="System Prompt",
|
| 241 |
value=DEFAULT_SYSTEM_PROMPT,
|
| 242 |
lines=2
|
| 243 |
)
|
| 244 |
|
| 245 |
-
# Sliders
|
| 246 |
with gr.Row():
|
| 247 |
-
temp_slider = gr.Slider(
|
| 248 |
-
tokens_slider = gr.Slider(
|
| 249 |
|
| 250 |
-
top_p_slider = gr.Slider(
|
| 251 |
|
| 252 |
-
|
| 253 |
-
gr.HTML(TRUSTED_HTML)
|
| 254 |
|
| 255 |
-
# ------
|
| 256 |
-
# COLUMNA DERECHA: El Chatbot Estilo Ventana
|
| 257 |
-
# -----------------------------------------------------------------
|
| 258 |
with gr.Column(scale=6):
|
| 259 |
-
# Contenedor
|
| 260 |
with gr.Column(elem_classes="chat-window"):
|
| 261 |
-
|
| 262 |
-
gr.HTML(WINDOW_HEADER_HTML)
|
| 263 |
|
| 264 |
-
# 2. El Chatbot
|
| 265 |
chatbot = gr.Chatbot(
|
| 266 |
elem_id="chatbot",
|
| 267 |
show_label=False,
|
| 268 |
-
avatar_images=(None, "https://cdn-icons-png.flaticon.com/512/4712/4712027.png"),
|
| 269 |
-
height=
|
| 270 |
layout="bubble"
|
| 271 |
)
|
| 272 |
|
| 273 |
-
# 3. Área de input personalizada
|
| 274 |
with gr.Row(elem_classes="chat-input-area"):
|
| 275 |
msg = gr.Textbox(
|
| 276 |
show_label=False,
|
| 277 |
placeholder="Ask a question...",
|
| 278 |
-
container=False,
|
| 279 |
scale=9,
|
| 280 |
-
elem_id="msg-box"
|
|
|
|
|
|
|
| 281 |
)
|
| 282 |
send_btn = gr.Button("➝", scale=1, elem_id="send-btn")
|
| 283 |
|
| 284 |
-
# ------
|
| 285 |
-
# Eventos
|
| 286 |
-
# -----------------------------------------------------------------
|
| 287 |
inputs_list = [msg, chatbot, system_prompt_input, context_input, tokens_slider, temp_slider, top_p_slider]
|
| 288 |
|
| 289 |
-
# Al presionar Enter
|
| 290 |
msg.submit(chat_logic, inputs_list, [msg, chatbot])
|
| 291 |
-
|
| 292 |
-
# Al hacer click en el botón de enviar
|
| 293 |
send_btn.click(chat_logic, inputs_list, [msg, chatbot])
|
| 294 |
|
| 295 |
if __name__ == "__main__":
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 4 |
|
| 5 |
+
# ==========================================
|
| 6 |
+
# 1. CONFIGURACIÓN DEL MODELO
|
| 7 |
+
# ==========================================
|
| 8 |
|
| 9 |
MODEL_ID = "DavidBazaldua/llama3_finetuned_transformes"
|
| 10 |
+
DEVICE = "cpu" # Cambia a "cuda" si tienes GPU NVIDIA
|
| 11 |
DTYPE = torch.float32
|
| 12 |
|
| 13 |
+
print(f"Cargando modelo: {MODEL_ID}...")
|
| 14 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
|
| 15 |
model = AutoModelForCausalLM.from_pretrained(
|
| 16 |
MODEL_ID,
|
|
|
|
| 19 |
)
|
| 20 |
model.to(DEVICE)
|
| 21 |
model.eval()
|
| 22 |
+
print("Modelo cargado exitosamente.")
|
| 23 |
|
| 24 |
DEFAULT_SYSTEM_PROMPT = (
|
| 25 |
"You are a helpful, precise AI assistant. "
|
|
|
|
| 27 |
"Respond in English unless the user asks otherwise."
|
| 28 |
)
|
| 29 |
|
| 30 |
+
# ==========================================
|
| 31 |
+
# 2. LÓGICA DEL CHAT
|
| 32 |
+
# ==========================================
|
| 33 |
|
| 34 |
def build_prompt(system_prompt, context, history, user_message):
|
| 35 |
messages = []
|
| 36 |
+
# 1. System Prompt
|
| 37 |
if system_prompt and system_prompt.strip():
|
| 38 |
messages.append({"role": "system", "content": system_prompt})
|
| 39 |
|
| 40 |
+
# 2. Contexto Extra
|
| 41 |
if context and context.strip():
|
| 42 |
messages.append({
|
| 43 |
"role": "system",
|
| 44 |
"content": f"Use the following context if relevant:\n{context}"
|
| 45 |
})
|
| 46 |
|
| 47 |
+
# 3. Historial de conversación
|
| 48 |
for user, assistant in history:
|
| 49 |
messages.append({"role": "user", "content": user})
|
| 50 |
messages.append({"role": "assistant", "content": assistant})
|
| 51 |
|
| 52 |
+
# 4. Mensaje actual
|
| 53 |
messages.append({"role": "user", "content": user_message})
|
| 54 |
|
| 55 |
prompt = tokenizer.apply_chat_template(
|
|
|
|
| 60 |
return prompt
|
| 61 |
|
| 62 |
def chat_logic(message, history, system_prompt, context, max_tokens, temperature, top_p):
|
| 63 |
+
if not message:
|
| 64 |
+
return "", history
|
| 65 |
+
|
| 66 |
if history is None:
|
| 67 |
history = []
|
| 68 |
|
| 69 |
if not system_prompt:
|
| 70 |
system_prompt = DEFAULT_SYSTEM_PROMPT
|
| 71 |
|
| 72 |
+
# Configuración de seguridad
|
| 73 |
+
max_tokens = int(min(max_tokens, 1024))
|
| 74 |
|
| 75 |
prompt = build_prompt(system_prompt, context, history, message)
|
| 76 |
|
|
|
|
| 88 |
|
| 89 |
decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 90 |
|
| 91 |
+
# Limpiar la respuesta para no repetir el prompt
|
| 92 |
if decoded.startswith(prompt):
|
| 93 |
answer = decoded[len(prompt):].strip()
|
| 94 |
else:
|
| 95 |
+
# Fallback por si el modelo repite cosas raras
|
|
|
|
| 96 |
answer = decoded.split("assistant\n")[-1].strip()
|
| 97 |
|
| 98 |
history.append((message, answer))
|
| 99 |
return "", history
|
| 100 |
|
| 101 |
+
# ==========================================
|
| 102 |
+
# 3. INTERFAZ GRÁFICA (CSS + LAYOUT)
|
| 103 |
+
# ==========================================
|
| 104 |
|
| 105 |
+
# CSS corregido para forzar modo claro y estilo Glass
|
| 106 |
CSS = """
|
| 107 |
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700&display=swap');
|
| 108 |
|
| 109 |
+
/* --- FORZAR VARIABLES CLARAS (Anti-Dark Mode) --- */
|
| 110 |
:root, .dark, body, .gradio-container {
|
| 111 |
--body-text-color: #1f2937 !important;
|
| 112 |
--body-background-fill: transparent !important;
|
|
|
|
| 115 |
--block-background-fill: transparent !important;
|
| 116 |
--block-border-color: rgba(255,255,255, 0.4) !important;
|
| 117 |
--input-background-fill: rgba(255, 255, 255, 0.9) !important;
|
| 118 |
+
--input-border-color: #e5e7eb !important;
|
| 119 |
}
|
| 120 |
|
| 121 |
body {
|
| 122 |
font-family: 'Inter', sans-serif !important;
|
| 123 |
+
/* Gradiente Pastel de fondo */
|
| 124 |
background: radial-gradient(circle at 10% 10%, #ffeef8 0%, #edf6ff 50%, #f7f0ff 90%) !important;
|
| 125 |
color: #1f2937 !important;
|
| 126 |
margin: 0; padding: 0;
|
| 127 |
+
min-height: 100vh;
|
| 128 |
}
|
| 129 |
|
| 130 |
+
/* Tipografía */
|
| 131 |
+
h1 { font-weight: 700 !important; color: #111827 !important; letter-spacing: -0.02em; }
|
| 132 |
p, span, label { color: #4b5563 !important; }
|
| 133 |
|
| 134 |
+
/* --- TARJETA IZQUIERDA (Configuración) --- */
|
| 135 |
.config-card {
|
| 136 |
+
background: rgba(255, 255, 255, 0.5) !important;
|
| 137 |
+
border: 1px solid rgba(255, 255, 255, 0.6) !important;
|
| 138 |
backdrop-filter: blur(12px);
|
| 139 |
border-radius: 24px;
|
| 140 |
padding: 24px;
|
| 141 |
+
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.01);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
}
|
| 143 |
|
| 144 |
/* Inputs y Sliders */
|
| 145 |
+
textarea, input[type="text"], input[type="number"] {
|
| 146 |
+
background-color: rgba(255, 255, 255, 0.8) !important;
|
| 147 |
color: #111827 !important;
|
| 148 |
border: 1px solid #e5e7eb !important;
|
| 149 |
border-radius: 12px !important;
|
| 150 |
+
box-shadow: none !important;
|
| 151 |
}
|
| 152 |
input[type=range] { accent-color: #111827; }
|
| 153 |
|
| 154 |
+
/* --- VENTANA DE CHAT (Derecha) --- */
|
| 155 |
.chat-window {
|
| 156 |
+
background: rgba(255, 255, 255, 0.75) !important;
|
| 157 |
+
border: 1px solid rgba(255, 255, 255, 0.8);
|
| 158 |
backdrop-filter: blur(20px);
|
| 159 |
border-radius: 24px;
|
| 160 |
box-shadow: 0 20px 50px rgba(0,0,0,0.05);
|
|
|
|
| 164 |
|
| 165 |
/* Header tipo Mac */
|
| 166 |
.window-header {
|
|
|
|
| 167 |
display: flex; gap: 8px; align-items: center;
|
| 168 |
+
padding: 18px 24px 10px 24px;
|
| 169 |
+
background: transparent;
|
| 170 |
}
|
| 171 |
.dot { width: 12px; height: 12px; border-radius: 50%; }
|
| 172 |
.red { background-color: #ff5f56; }
|
| 173 |
.yellow { background-color: #ffbd2e; }
|
| 174 |
.green { background-color: #27c93f; }
|
| 175 |
|
| 176 |
+
/* Chatbot Area */
|
| 177 |
#chatbot {
|
| 178 |
background: transparent !important;
|
| 179 |
+
border: none !important;
|
| 180 |
+
height: 550px !important;
|
| 181 |
}
|
| 182 |
|
| 183 |
+
/* Burbujas del chat */
|
| 184 |
.message.user {
|
| 185 |
+
background-color: #111827 !important; /* Usuario: Oscuro */
|
| 186 |
color: white !important;
|
| 187 |
border-radius: 18px 18px 4px 18px !important;
|
| 188 |
}
|
| 189 |
.message.bot {
|
| 190 |
+
background-color: #ffffff !important; /* Bot: Blanco */
|
| 191 |
color: #111827 !important;
|
| 192 |
border: 1px solid #e5e7eb !important;
|
| 193 |
border-radius: 18px 18px 18px 4px !important;
|
| 194 |
+
box-shadow: 0 2px 5px rgba(0,0,0,0.02);
|
| 195 |
}
|
| 196 |
|
| 197 |
+
/* Input Area */
|
| 198 |
.chat-input-area {
|
| 199 |
padding: 16px 24px 24px 24px;
|
| 200 |
display: flex; gap: 10px; align-items: center;
|
|
|
|
| 202 |
#msg-box textarea {
|
| 203 |
border-radius: 99px !important;
|
| 204 |
background: #ffffff !important;
|
| 205 |
+
padding: 12px 20px !important;
|
| 206 |
+
border: 1px solid #e5e7eb !important;
|
| 207 |
+
color: #111827 !important;
|
| 208 |
}
|
| 209 |
#send-btn {
|
| 210 |
background: #111827 !important;
|
| 211 |
color: white !important;
|
| 212 |
border-radius: 50% !important;
|
| 213 |
+
width: 46px; height: 46px;
|
| 214 |
+
font-size: 1.2em; padding: 0 !important;
|
| 215 |
+
display: flex; align-items: center; justify-content: center;
|
| 216 |
}
|
| 217 |
+
|
| 218 |
+
/* Logos Trusted By */
|
| 219 |
+
.trusted-logos {
|
| 220 |
+
opacity: 0.5; filter: grayscale(100%);
|
| 221 |
+
margin-top: 30px; display: flex; gap: 20px;
|
| 222 |
+
font-weight: 600; font-size: 1.1rem; color: #9ca3af;
|
| 223 |
+
}
|
| 224 |
+
"""
|
| 225 |
+
|
| 226 |
+
# HTML Helpers
|
| 227 |
+
WINDOW_HEADER = """
|
| 228 |
+
<div class="window-header">
|
| 229 |
+
<div class="dot red"></div>
|
| 230 |
+
<div class="dot yellow"></div>
|
| 231 |
+
<div class="dot green"></div>
|
| 232 |
+
<span style="margin-left: 12px; font-size: 0.85rem; color: #6b7280; font-weight: 500;">Iris Assistant</span>
|
| 233 |
+
</div>
|
| 234 |
+
"""
|
| 235 |
+
|
| 236 |
+
TRUSTED_SECTION = """
|
| 237 |
+
<div style="margin-top: 40px;">
|
| 238 |
+
<p style="font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: #9ca3af; margin-bottom: 10px;">Trusted by</p>
|
| 239 |
+
<div class="trusted-logos">
|
| 240 |
+
<span>Pingdom</span>
|
| 241 |
+
<span>prismic</span>
|
| 242 |
+
<span>Unsplash</span>
|
| 243 |
+
<span>krisp</span>
|
| 244 |
+
</div>
|
| 245 |
+
</div>
|
| 246 |
"""
|
| 247 |
|
| 248 |
+
# Usamos theme=gr.themes.Soft() como base para evitar conflictos oscuros
|
| 249 |
+
with gr.Blocks(theme=gr.themes.Soft(), css=CSS, title="Custom AI") as demo:
|
| 250 |
|
| 251 |
+
with gr.Row(elem_id="main-container"):
|
| 252 |
+
|
| 253 |
+
# --- COLUMNA IZQUIERDA: Configuración ---
|
|
|
|
| 254 |
with gr.Column(scale=4):
|
| 255 |
gr.Markdown(
|
| 256 |
"""
|
|
|
|
| 264 |
with gr.Group(elem_classes="config-card"):
|
| 265 |
gr.Markdown("### ⚙️ Configuración")
|
| 266 |
|
|
|
|
| 267 |
context_input = gr.Textbox(
|
| 268 |
label="Contexto (Data)",
|
| 269 |
+
placeholder="Pega aquí documentos o notas para dar contexto...",
|
| 270 |
+
lines=5
|
| 271 |
)
|
| 272 |
|
|
|
|
| 273 |
system_prompt_input = gr.Textbox(
|
| 274 |
label="System Prompt",
|
| 275 |
value=DEFAULT_SYSTEM_PROMPT,
|
| 276 |
lines=2
|
| 277 |
)
|
| 278 |
|
|
|
|
| 279 |
with gr.Row():
|
| 280 |
+
temp_slider = gr.Slider(0.1, 1.5, value=0.7, step=0.1, label="Creatividad")
|
| 281 |
+
tokens_slider = gr.Slider(64, 1024, value=256, step=64, label="Max Tokens")
|
| 282 |
|
| 283 |
+
top_p_slider = gr.Slider(0.1, 1.0, value=0.9, step=0.05, label="Top-P")
|
| 284 |
|
| 285 |
+
gr.HTML(TRUSTED_SECTION)
|
|
|
|
| 286 |
|
| 287 |
+
# --- COLUMNA DERECHA: Chatbot ---
|
|
|
|
|
|
|
| 288 |
with gr.Column(scale=6):
|
| 289 |
+
# Contenedor estilo ventana de app
|
| 290 |
with gr.Column(elem_classes="chat-window"):
|
| 291 |
+
gr.HTML(WINDOW_HEADER)
|
|
|
|
| 292 |
|
|
|
|
| 293 |
chatbot = gr.Chatbot(
|
| 294 |
elem_id="chatbot",
|
| 295 |
show_label=False,
|
| 296 |
+
avatar_images=(None, "https://cdn-icons-png.flaticon.com/512/4712/4712027.png"),
|
| 297 |
+
height=550,
|
| 298 |
layout="bubble"
|
| 299 |
)
|
| 300 |
|
|
|
|
| 301 |
with gr.Row(elem_classes="chat-input-area"):
|
| 302 |
msg = gr.Textbox(
|
| 303 |
show_label=False,
|
| 304 |
placeholder="Ask a question...",
|
|
|
|
| 305 |
scale=9,
|
| 306 |
+
elem_id="msg-box",
|
| 307 |
+
container=False,
|
| 308 |
+
autofocus=True
|
| 309 |
)
|
| 310 |
send_btn = gr.Button("➝", scale=1, elem_id="send-btn")
|
| 311 |
|
| 312 |
+
# --- EVENTOS ---
|
|
|
|
|
|
|
| 313 |
inputs_list = [msg, chatbot, system_prompt_input, context_input, tokens_slider, temp_slider, top_p_slider]
|
| 314 |
|
|
|
|
| 315 |
msg.submit(chat_logic, inputs_list, [msg, chatbot])
|
|
|
|
|
|
|
| 316 |
send_btn.click(chat_logic, inputs_list, [msg, chatbot])
|
| 317 |
|
| 318 |
if __name__ == "__main__":
|