DavidBazaldua commited on
Commit
bb0be1c
·
verified ·
1 Parent(s): 0ff34ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -24
app.py CHANGED
@@ -3,14 +3,14 @@ import gradio as gr
3
  from transformers import AutoModelForCausalLM, AutoTokenizer
4
 
5
  # ==========================================
6
- # 1. MODEL CONFIGURATION
7
  # ==========================================
8
 
9
  MODEL_ID = "DavidBazaldua/llama3_finetuned_transformes"
10
  DEVICE = "cpu"
11
  DTYPE = torch.float32
12
 
13
- print(f"Loading model: {MODEL_ID}...")
14
  tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
15
  model = AutoModelForCausalLM.from_pretrained(
16
  MODEL_ID,
@@ -19,7 +19,7 @@ model = AutoModelForCausalLM.from_pretrained(
19
  )
20
  model.to(DEVICE)
21
  model.eval()
22
- print("Model loaded.")
23
 
24
  DEFAULT_SYSTEM_PROMPT = (
25
  "You are a helpful, precise AI assistant. "
@@ -28,7 +28,7 @@ DEFAULT_SYSTEM_PROMPT = (
28
  )
29
 
30
  # ==========================================
31
- # 2. CHAT LOGIC
32
  # ==========================================
33
 
34
  def build_prompt(system_prompt, context, history, user_message):
@@ -79,7 +79,7 @@ def chat_logic(message, history, system_prompt, context, max_tokens, temperature
79
  return "", history
80
 
81
  # ==========================================
82
- # 3. UI DESIGN (FINAL CLEAN MONOCHROME)
83
  # ==========================================
84
 
85
  CSS = """
@@ -95,7 +95,7 @@ CSS = """
95
  --block-border-color: transparent !important;
96
  --input-background-fill: #ffffff !important;
97
 
98
- /* KILL PURPLE VARIABLES */
99
  --primary-500: #000000 !important;
100
  --primary-600: #000000 !important;
101
  --secondary-500: #000000 !important;
@@ -112,7 +112,7 @@ body {
112
  h1 { font-weight: 700 !important; color: #000000 !important; letter-spacing: -0.02em; }
113
  p, span, label { color: #374151 !important; }
114
 
115
- /* --- LEFT PANEL --- */
116
  .config-card {
117
  background: rgba(255, 255, 255, 0.4) !important;
118
  border: 1px solid rgba(255, 255, 255, 0.5) !important;
@@ -121,7 +121,6 @@ p, span, label { color: #374151 !important; }
121
  padding: 24px !important;
122
  }
123
 
124
- /* Make everything inside config-card transparent */
125
  .config-card div, .config-card .gr-form, .config-card .gr-box,
126
  .config-card .gr-group, .config-card .gr-block, .config-card .gr-panel {
127
  background: transparent !important;
@@ -129,8 +128,7 @@ p, span, label { color: #374151 !important; }
129
  box-shadow: none !important;
130
  }
131
 
132
- /* ANTI-PURPLE FIX FOR LABELS */
133
- /* This forces the labels to be transparent and black text */
134
  .config-card label span,
135
  .config-card .label-wrap span,
136
  .config-card .block-title {
@@ -144,7 +142,7 @@ p, span, label { color: #374151 !important; }
144
  padding: 0 !important;
145
  }
146
 
147
- /* Inputs: White & Clean */
148
  .config-card textarea,
149
  .config-card input[type="text"],
150
  .config-card input[type="number"] {
@@ -155,13 +153,13 @@ p, span, label { color: #374151 !important; }
155
  box-shadow: 0 1px 2px rgba(0,0,0,0.05) !important;
156
  }
157
 
158
- /* Sliders: Force Black */
159
  input[type=range] {
160
  accent-color: #000000 !important;
161
- filter: grayscale(100%) brightness(0) !important; /* Forces it to be black regardless of theme */
162
  }
163
 
164
- /* --- RIGHT PANEL: CHAT WINDOW --- */
165
  .chat-window {
166
  background: rgba(255, 255, 255, 0.95) !important;
167
  border: 1px solid rgba(255, 255, 255, 0.9);
@@ -181,17 +179,27 @@ input[type=range] {
181
  .yellow { background-color: #ffbd2e; }
182
  .green { background-color: #27c93f; }
183
 
184
- /* Chatbot */
185
  #chatbot {
186
  background: transparent !important;
187
  border: none !important;
188
  height: 550px !important;
189
  }
 
 
 
 
190
  .message.user {
191
  background-color: #000000 !important;
192
- color: white !important;
193
  border-radius: 18px 18px 4px 18px !important;
 
 
 
 
 
194
  }
 
 
195
  .message.bot {
196
  background-color: #ffffff !important;
197
  color: #000000 !important;
@@ -200,20 +208,25 @@ input[type=range] {
200
  box-shadow: 0 2px 5px rgba(0,0,0,0.02);
201
  }
202
 
203
- /* Input Area */
204
  .chat-input-area {
205
  padding: 16px 24px 24px 24px;
206
- display: flex; gap: 10px; align-items: center;
207
  }
 
208
  #msg-box textarea {
209
- border-radius: 99px !important;
210
  background: #ffffff !important;
211
- padding: 12px 20px !important;
212
  border: 1px solid #e5e7eb !important;
213
  color: #000000 !important;
 
 
 
 
 
214
  }
215
 
216
- /* Button: Minimalist Black Arrow */
217
  #send-btn {
218
  background: transparent !important;
219
  color: #000000 !important;
@@ -222,6 +235,7 @@ input[type=range] {
222
  font-size: 1.6rem;
223
  padding: 0 10px !important;
224
  width: auto !important;
 
225
  }
226
  #send-btn:hover {
227
  transform: translateX(3px);
@@ -261,7 +275,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=CSS, title="Custom AI") as demo:
261
 
262
  with gr.Row(elem_id="main-container"):
263
 
264
- # --- LEFT PANEL ---
265
  with gr.Column(scale=4):
266
  gr.Markdown(
267
  """
@@ -295,7 +309,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=CSS, title="Custom AI") as demo:
295
 
296
  gr.HTML(TRUSTED_SECTION)
297
 
298
- # --- RIGHT PANEL ---
299
  with gr.Column(scale=6):
300
  with gr.Column(elem_classes="chat-window"):
301
  gr.HTML(WINDOW_HEADER)
@@ -315,7 +329,8 @@ with gr.Blocks(theme=gr.themes.Soft(), css=CSS, title="Custom AI") as demo:
315
  scale=9,
316
  elem_id="msg-box",
317
  container=False,
318
- autofocus=True
 
319
  )
320
  send_btn = gr.Button("➝", scale=1, elem_id="send-btn")
321
 
 
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"
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.")
23
 
24
  DEFAULT_SYSTEM_PROMPT = (
25
  "You are a helpful, precise AI assistant. "
 
28
  )
29
 
30
  # ==========================================
31
+ # 2. LÓGICA DEL CHAT
32
  # ==========================================
33
 
34
  def build_prompt(system_prompt, context, history, user_message):
 
79
  return "", history
80
 
81
  # ==========================================
82
+ # 3. DISEÑO UI (FINAL)
83
  # ==========================================
84
 
85
  CSS = """
 
95
  --block-border-color: transparent !important;
96
  --input-background-fill: #ffffff !important;
97
 
98
+ /* ELIMINAR MORADOS */
99
  --primary-500: #000000 !important;
100
  --primary-600: #000000 !important;
101
  --secondary-500: #000000 !important;
 
112
  h1 { font-weight: 700 !important; color: #000000 !important; letter-spacing: -0.02em; }
113
  p, span, label { color: #374151 !important; }
114
 
115
+ /* --- PANEL IZQUIERDO --- */
116
  .config-card {
117
  background: rgba(255, 255, 255, 0.4) !important;
118
  border: 1px solid rgba(255, 255, 255, 0.5) !important;
 
121
  padding: 24px !important;
122
  }
123
 
 
124
  .config-card div, .config-card .gr-form, .config-card .gr-box,
125
  .config-card .gr-group, .config-card .gr-block, .config-card .gr-panel {
126
  background: transparent !important;
 
128
  box-shadow: none !important;
129
  }
130
 
131
+ /* Etiquetas en negro */
 
132
  .config-card label span,
133
  .config-card .label-wrap span,
134
  .config-card .block-title {
 
142
  padding: 0 !important;
143
  }
144
 
145
+ /* Inputs configuración */
146
  .config-card textarea,
147
  .config-card input[type="text"],
148
  .config-card input[type="number"] {
 
153
  box-shadow: 0 1px 2px rgba(0,0,0,0.05) !important;
154
  }
155
 
156
+ /* Sliders negros */
157
  input[type=range] {
158
  accent-color: #000000 !important;
159
+ filter: grayscale(100%) brightness(0) !important;
160
  }
161
 
162
+ /* --- PANEL DERECHO: CHAT --- */
163
  .chat-window {
164
  background: rgba(255, 255, 255, 0.95) !important;
165
  border: 1px solid rgba(255, 255, 255, 0.9);
 
179
  .yellow { background-color: #ffbd2e; }
180
  .green { background-color: #27c93f; }
181
 
 
182
  #chatbot {
183
  background: transparent !important;
184
  border: none !important;
185
  height: 550px !important;
186
  }
187
+
188
+ /* --- BURBUJAS DE CHAT --- */
189
+
190
+ /* Usuario: Negro con Texto BLANCO */
191
  .message.user {
192
  background-color: #000000 !important;
193
+ color: #ffffff !important; /* TEXTO BLANCO FORZADO */
194
  border-radius: 18px 18px 4px 18px !important;
195
+ font-weight: 500;
196
+ }
197
+ /* Asegurar que cualquier texto dentro de la burbuja user sea blanco */
198
+ .message.user p, .message.user span {
199
+ color: #ffffff !important;
200
  }
201
+
202
+ /* Bot: Blanco con Texto Negro */
203
  .message.bot {
204
  background-color: #ffffff !important;
205
  color: #000000 !important;
 
208
  box-shadow: 0 2px 5px rgba(0,0,0,0.02);
209
  }
210
 
211
+ /* --- CAJITA DE INPUT CON SCROLLBAR ("SLICER") --- */
212
  .chat-input-area {
213
  padding: 16px 24px 24px 24px;
214
+ display: flex; gap: 10px; align-items: flex-end; /* Alinear abajo para que se vea bien */
215
  }
216
+
217
  #msg-box textarea {
 
218
  background: #ffffff !important;
219
+ padding: 12px 18px !important;
220
  border: 1px solid #e5e7eb !important;
221
  color: #000000 !important;
222
+
223
+ /* AQUÍ ESTÁ EL TRUCO DEL "SLICER" */
224
+ max-height: 120px !important; /* Altura máxima fija */
225
+ overflow-y: auto !important; /* Aparece scrollbar si te pasas */
226
+ border-radius: 24px !important; /* Un poco menos redondo para que quepa el scroll */
227
  }
228
 
229
+ /* Flecha enviar */
230
  #send-btn {
231
  background: transparent !important;
232
  color: #000000 !important;
 
235
  font-size: 1.6rem;
236
  padding: 0 10px !important;
237
  width: auto !important;
238
+ margin-bottom: 8px; /* Ajuste para alinear con el textbox */
239
  }
240
  #send-btn:hover {
241
  transform: translateX(3px);
 
275
 
276
  with gr.Row(elem_id="main-container"):
277
 
278
+ # --- IZQUIERDA ---
279
  with gr.Column(scale=4):
280
  gr.Markdown(
281
  """
 
309
 
310
  gr.HTML(TRUSTED_SECTION)
311
 
312
+ # --- DERECHA ---
313
  with gr.Column(scale=6):
314
  with gr.Column(elem_classes="chat-window"):
315
  gr.HTML(WINDOW_HEADER)
 
329
  scale=9,
330
  elem_id="msg-box",
331
  container=False,
332
+ autofocus=True,
333
+ lines=1 # Empieza con 1 línea
334
  )
335
  send_btn = gr.Button("➝", scale=1, elem_id="send-btn")
336