Maximofn commited on
Commit
9f65115
·
1 Parent(s): da45c08

Refactor Gradio app structure for improved control and user experience; enhance description styling in CSS for better visibility and aesthetics.

Browse files
Files changed (2) hide show
  1. app.py +43 -20
  2. style.css +56 -20
app.py CHANGED
@@ -350,28 +350,51 @@ def respond(message, history: list[tuple[str, str]]):
350
  _flush_langsmith()
351
 
352
 
353
- chat = gr.ChatInterface(
354
- fn=respond,
355
- # default type keeps string message, keeps compatibility across versions
356
- title="Gmail & Outlook API Helper",
357
- description='<div class="app-description">🤖 Este chatbot te guía <strong>paso a paso</strong> para crear credenciales de API de <strong>Gmail</strong> (Google Cloud) ☁️ o <strong>OneDrive</strong> (Microsoft Entra ID) 🔑. Puedes enviar 📸 <strong>capturas de pantalla</strong> para recibir ayuda visual personalizada. El asistente te dará <strong>una instrucción a la vez</strong> para que no te abrumes ✨</div>',
358
- textbox=gr.MultimodalTextbox(
359
- file_types=["image", ".png", ".jpg", ".jpeg", ".webp", ".gif"],
360
- placeholder="Escribe o pega (⌘/Ctrl+V) una imagen o arrástrala aquí",
361
- file_count="multiple",
362
- ),
363
- multimodal=True,
364
- fill_height=True,
365
- examples=[
366
- "¿Cómo creo una API Key de Gmail?",
367
- "Guíame para obtener credenciales de OneDrive",
368
- ],
369
- theme=gr.themes.Monochrome(),
370
- css=style,
371
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
372
 
373
 
374
  if __name__ == "__main__":
375
- chat.launch()
376
 
377
 
 
350
  _flush_langsmith()
351
 
352
 
353
+ # Create the Gradio app with Blocks for better control
354
+ with gr.Blocks(theme=gr.themes.Monochrome(), css=style, fill_height=True) as demo:
355
+ # Description component that can be hidden
356
+ description = gr.HTML(
357
+ value='<div class="app-description">🤖 Este chatbot te guía <strong>paso a paso</strong> para crear credenciales de API de <strong>Gmail</strong> (Google Cloud) ☁️ o <strong>OneDrive</strong> (Microsoft Entra ID) 🔑. Puedes enviar 📸 <strong>capturas de pantalla</strong> para recibir ayuda visual personalizada. El asistente te dará <strong>una instrucción a la vez</strong> para que no te abrumes ✨</div>',
358
+ visible=True
359
+ )
360
+
361
+ # State to track if first message has been sent
362
+ first_message_sent = gr.State(False)
363
+
364
+ # ChatInterface without description (handled separately above)
365
+ chat = gr.ChatInterface(
366
+ fn=respond,
367
+ title="Gmail & Outlook API Helper",
368
+ description="",
369
+ textbox=gr.MultimodalTextbox(
370
+ file_types=["image", ".png", ".jpg", ".jpeg", ".webp", ".gif"],
371
+ placeholder="Escribe o pega (⌘/Ctrl+V) una imagen o arrástrala aquí",
372
+ file_count="multiple",
373
+ ),
374
+ multimodal=True,
375
+ fill_height=True,
376
+ examples=[
377
+ "¿Cómo creo una API Key de Gmail?",
378
+ "Guíame para obtener credenciales de OneDrive",
379
+ ],
380
+ )
381
+
382
+ # Hide description on first message
383
+ def hide_description_on_first_message(message, is_sent):
384
+ if not is_sent:
385
+ return gr.update(visible=False), True
386
+ return gr.update(), is_sent
387
+
388
+ # Connect the event to hide description when user submits first message
389
+ chat.textbox.submit(
390
+ fn=hide_description_on_first_message,
391
+ inputs=[chat.textbox, first_message_sent],
392
+ outputs=[description, first_message_sent],
393
+ queue=False
394
+ )
395
 
396
 
397
  if __name__ == "__main__":
398
+ demo.launch()
399
 
400
 
style.css CHANGED
@@ -85,7 +85,8 @@
85
 
86
  /* Description styling - Target markdown div (not paragraphs which are used in chat) */
87
  /* The description is rendered as: .prose > .md > div */
88
- .prose .md > div {
 
89
  font-size: 1rem !important;
90
  font-weight: 400 !important;
91
  line-height: 1.6 !important;
@@ -93,42 +94,76 @@
93
  margin: 0.75rem auto 1.5rem auto !important;
94
  padding: 1.25rem 1.5rem !important;
95
  max-width: 700px !important;
96
- color: var(--text-light-secondary) !important;
97
- background: var(--bg-light-secondary) !important;
98
  border-radius: 16px !important;
99
- box-shadow: var(--card-shadow-light) !important;
100
  display: block !important;
101
  position: relative !important;
102
 
103
  /* Multi-color gradient border */
104
- border: 1px solid transparent !important;
105
- background-image:
106
- linear-gradient(var(--bg-light-secondary), var(--bg-light-secondary)),
107
  linear-gradient(
108
  90deg,
109
- var(--primary-purple) 0%,
110
- var(--secondary-pink) 14%,
111
- var(--accent-salmon) 28%,
112
- var(--accent-orange) 42%,
113
- var(--accent-yellow) 57%,
114
- var(--accent-green) 71%,
115
- var(--accent-teal) 85%,
116
- var(--primary-purple-light) 100%
117
  ) !important;
118
  background-origin: border-box !important;
119
  background-clip: padding-box, border-box !important;
120
  }
121
 
122
  /* Bold text styling within description */
123
- .prose .md > div strong {
 
124
  color: var(--primary-purple) !important;
125
  font-weight: 600 !important;
126
  }
127
 
128
  /* Dark theme description */
129
- .dark .prose .md > div {
130
- color: var(--text-dark-secondary) !important;
131
- box-shadow: var(--card-shadow-dark) !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
 
133
  /* Multi-color gradient border for dark theme */
134
  background-image:
@@ -147,7 +182,8 @@
147
  }
148
 
149
  /* Dark theme bold text in description */
150
- .dark .prose .md > div strong {
 
151
  color: var(--primary-purple-light) !important;
152
  }
153
 
 
85
 
86
  /* Description styling - Target markdown div (not paragraphs which are used in chat) */
87
  /* The description is rendered as: .prose > .md > div */
88
+ .prose .md > div,
89
+ .app-description {
90
  font-size: 1rem !important;
91
  font-weight: 400 !important;
92
  line-height: 1.6 !important;
 
94
  margin: 0.75rem auto 1.5rem auto !important;
95
  padding: 1.25rem 1.5rem !important;
96
  max-width: 700px !important;
97
+ color: #4B5563 !important;
98
+ background-color: #F9FAFB !important;
99
  border-radius: 16px !important;
100
+ box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06) !important;
101
  display: block !important;
102
  position: relative !important;
103
 
104
  /* Multi-color gradient border */
105
+ border: 2px solid transparent !important;
106
+ background-image:
107
+ linear-gradient(#F9FAFB, #F9FAFB),
108
  linear-gradient(
109
  90deg,
110
+ #7C3AED 0%,
111
+ #EC4899 14%,
112
+ #FF8F8F 28%,
113
+ #FB923C 42%,
114
+ #FBBF24 57%,
115
+ #10B981 71%,
116
+ #14B8A6 85%,
117
+ #8B5CF6 100%
118
  ) !important;
119
  background-origin: border-box !important;
120
  background-clip: padding-box, border-box !important;
121
  }
122
 
123
  /* Bold text styling within description */
124
+ .prose .md > div strong,
125
+ .app-description strong {
126
  color: var(--primary-purple) !important;
127
  font-weight: 600 !important;
128
  }
129
 
130
  /* Dark theme description */
131
+ @media (prefers-color-scheme: dark) {
132
+ .prose .md > div,
133
+ .app-description {
134
+ color: #E5E7EB !important;
135
+ background-color: #1E293B !important;
136
+ box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2) !important;
137
+
138
+ /* Multi-color gradient border for dark theme */
139
+ background-image:
140
+ linear-gradient(#1E293B, #1E293B),
141
+ linear-gradient(
142
+ 90deg,
143
+ #7C3AED 0%,
144
+ #EC4899 14%,
145
+ #FF8F8F 28%,
146
+ #FB923C 42%,
147
+ #FBBF24 57%,
148
+ #10B981 71%,
149
+ #14B8A6 85%,
150
+ #8B5CF6 100%
151
+ ) !important;
152
+ }
153
+
154
+ /* Dark theme bold text in description */
155
+ .prose .md > div strong,
156
+ .app-description strong {
157
+ color: #A78BFA !important;
158
+ }
159
+ }
160
+
161
+ /* Also support .dark class for manual theme switching */
162
+ .dark .prose .md > div,
163
+ .dark .app-description {
164
+ color: #E5E7EB !important;
165
+ background-color: #1E293B !important;
166
+ box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2) !important;
167
 
168
  /* Multi-color gradient border for dark theme */
169
  background-image:
 
182
  }
183
 
184
  /* Dark theme bold text in description */
185
+ .dark .prose .md > div strong,
186
+ .dark .app-description strong {
187
  color: var(--primary-purple-light) !important;
188
  }
189