msmaje commited on
Commit
1e20ca4
Β·
verified Β·
1 Parent(s): fc0e6fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +191 -23
app.py CHANGED
@@ -55,12 +55,25 @@ def clear_chat():
55
  """Clear chat history"""
56
  return [], ""
57
 
58
- # Custom CSS for better styling
59
  css = """
 
60
  .gradio-container {
61
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
 
 
 
 
 
 
 
 
 
 
 
62
  }
63
 
 
64
  .chat-message {
65
  padding: 10px;
66
  margin: 5px 0;
@@ -69,25 +82,168 @@ css = """
69
 
70
  .user-message {
71
  background-color: #e3f2fd;
72
- margin-left: 20%;
73
  }
74
 
75
  .bot-message {
76
  background-color: #f5f5f5;
77
- margin-right: 20%;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  }
79
 
80
- #component-0 {
81
- max-height: 600px;
 
 
82
  }
83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  .footer {
85
  text-align: center;
86
  margin-top: 20px;
87
- padding: 10px;
88
  font-size: 14px;
89
  color: #666;
90
  }
 
 
 
 
 
 
 
91
  """
92
 
93
  # Create Gradio interface
@@ -95,42 +251,52 @@ with gr.Blocks(css=css, title="πŸ€– Codestral AI Chat", theme=gr.themes.Soft())
95
 
96
  # Header
97
  gr.HTML("""
98
- <div style="text-align: center; padding: 20px;">
99
  <h1>πŸ€– Codestral AI Chat with LangChain</h1>
100
- <p style="font-size: 18px; color: #666;">
101
  Powered by <strong>Codestral AI</strong> from Mistral AI | Built with <strong>LangChain</strong> & <strong>Gradio</strong>
102
  </p>
103
  </div>
104
  """)
105
 
 
106
  with gr.Row():
107
  # Main chat area
108
- with gr.Column(scale=4):
109
  chatbot = gr.Chatbot(
110
  label="πŸ’¬ Chat with Codestral AI",
111
  height=500,
112
  show_label=True,
113
  container=True,
114
- bubble_full_width=False
 
115
  )
116
 
117
- with gr.Row():
 
118
  msg = gr.Textbox(
119
  label="Your Message",
120
  placeholder="Type your question here...",
121
  lines=2,
122
- max_lines=5,
123
  scale=4,
124
- container=True
 
 
 
 
 
 
 
125
  )
126
- send_btn = gr.Button("Send πŸš€", variant="primary", scale=1)
127
 
 
128
  with gr.Row():
129
  clear_btn = gr.Button("πŸ—‘οΈ Clear Chat", variant="secondary")
130
 
131
- # Settings sidebar
132
- with gr.Column(scale=1, min_width=250):
133
- gr.HTML("<h3>βš™οΈ Model Settings</h3>")
134
 
135
  temperature = gr.Slider(
136
  minimum=0.0,
@@ -150,10 +316,11 @@ with gr.Blocks(css=css, title="πŸ€– Codestral AI Chat", theme=gr.themes.Soft())
150
  info="Maximum response length"
151
  )
152
 
 
153
  gr.HTML("""
154
- <div style="margin-top: 30px; padding: 15px; background-color: #f8f9fa; border-radius: 10px;">
155
- <h4>πŸ’‘ Tips:</h4>
156
- <ul style="font-size: 14px; margin: 10px 0;">
157
  <li>Ask coding questions</li>
158
  <li>Request explanations</li>
159
  <li>Get creative writing help</li>
@@ -162,10 +329,11 @@ with gr.Blocks(css=css, title="πŸ€– Codestral AI Chat", theme=gr.themes.Soft())
162
  </div>
163
  """)
164
 
 
165
  gr.HTML("""
166
- <div style="margin-top: 20px; padding: 15px; background-color: #e8f5e8; border-radius: 10px;">
167
- <h4>πŸ”§ Features:</h4>
168
- <ul style="font-size: 14px; margin: 10px 0;">
169
  <li>βœ… Codestral AI Model</li>
170
  <li>βœ… LangChain Integration</li>
171
  <li>βœ… Real-time Responses</li>
 
55
  """Clear chat history"""
56
  return [], ""
57
 
58
+ # Responsive CSS with mobile-first approach
59
  css = """
60
+ /* Base styles - Mobile first */
61
  .gradio-container {
62
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
63
+ max-width: 100%;
64
+ margin: 0 auto;
65
+ padding: 10px;
66
+ }
67
+
68
+ /* Large screens - center content with max width */
69
+ @media (min-width: 1200px) {
70
+ .gradio-container {
71
+ max-width: 1400px;
72
+ padding: 20px;
73
+ }
74
  }
75
 
76
+ /* Chat message styling */
77
  .chat-message {
78
  padding: 10px;
79
  margin: 5px 0;
 
82
 
83
  .user-message {
84
  background-color: #e3f2fd;
85
+ margin-left: 10%;
86
  }
87
 
88
  .bot-message {
89
  background-color: #f5f5f5;
90
+ margin-right: 10%;
91
+ }
92
+
93
+ /* Responsive layout adjustments */
94
+ @media (max-width: 768px) {
95
+ .user-message {
96
+ margin-left: 5%;
97
+ }
98
+ .bot-message {
99
+ margin-right: 5%;
100
+ }
101
+ }
102
+
103
+ /* Chatbot container responsive height */
104
+ .chatbot-container {
105
+ height: 400px;
106
+ }
107
+
108
+ @media (min-width: 768px) {
109
+ .chatbot-container {
110
+ height: 500px;
111
+ }
112
+ }
113
+
114
+ @media (min-width: 1024px) {
115
+ .chatbot-container {
116
+ height: 600px;
117
+ }
118
+ }
119
+
120
+ /* Input row responsive behavior */
121
+ .input-row {
122
+ display: flex;
123
+ gap: 10px;
124
+ align-items: flex-end;
125
+ flex-wrap: nowrap;
126
+ }
127
+
128
+ @media (max-width: 480px) {
129
+ .input-row {
130
+ flex-direction: column;
131
+ gap: 8px;
132
+ }
133
+
134
+ .input-row .textbox {
135
+ width: 100% !important;
136
+ }
137
+
138
+ .input-row .button {
139
+ width: 100% !important;
140
+ min-width: unset !important;
141
+ }
142
+ }
143
+
144
+ /* Button responsive sizing */
145
+ .send-button {
146
+ min-width: 80px;
147
+ white-space: nowrap;
148
+ }
149
+
150
+ @media (max-width: 480px) {
151
+ .send-button {
152
+ min-width: unset;
153
+ padding: 8px 16px;
154
+ }
155
+ }
156
+
157
+ /* Settings panel responsive behavior */
158
+ .settings-panel {
159
+ min-width: 200px;
160
+ }
161
+
162
+ @media (max-width: 1024px) {
163
+ .settings-panel {
164
+ min-width: 180px;
165
+ }
166
  }
167
 
168
+ @media (max-width: 768px) {
169
+ .settings-panel {
170
+ min-width: 160px;
171
+ }
172
  }
173
 
174
+ /* Info boxes responsive */
175
+ .info-box {
176
+ margin-top: 20px;
177
+ padding: 15px;
178
+ border-radius: 10px;
179
+ font-size: 14px;
180
+ }
181
+
182
+ @media (max-width: 768px) {
183
+ .info-box {
184
+ margin-top: 15px;
185
+ padding: 12px;
186
+ font-size: 13px;
187
+ }
188
+ }
189
+
190
+ @media (max-width: 480px) {
191
+ .info-box {
192
+ margin-top: 10px;
193
+ padding: 10px;
194
+ font-size: 12px;
195
+ }
196
+ }
197
+
198
+ /* Header responsive */
199
+ .header {
200
+ text-align: center;
201
+ padding: 20px;
202
+ }
203
+
204
+ @media (max-width: 768px) {
205
+ .header {
206
+ padding: 15px 10px;
207
+ }
208
+
209
+ .header h1 {
210
+ font-size: 24px;
211
+ }
212
+
213
+ .header p {
214
+ font-size: 16px;
215
+ }
216
+ }
217
+
218
+ @media (max-width: 480px) {
219
+ .header {
220
+ padding: 10px 5px;
221
+ }
222
+
223
+ .header h1 {
224
+ font-size: 20px;
225
+ }
226
+
227
+ .header p {
228
+ font-size: 14px;
229
+ }
230
+ }
231
+
232
+ /* Footer responsive */
233
  .footer {
234
  text-align: center;
235
  margin-top: 20px;
236
+ padding: 15px;
237
  font-size: 14px;
238
  color: #666;
239
  }
240
+
241
+ @media (max-width: 768px) {
242
+ .footer {
243
+ font-size: 12px;
244
+ padding: 10px;
245
+ }
246
+ }
247
  """
248
 
249
  # Create Gradio interface
 
251
 
252
  # Header
253
  gr.HTML("""
254
+ <div class="header">
255
  <h1>πŸ€– Codestral AI Chat with LangChain</h1>
256
+ <p style="color: #666;">
257
  Powered by <strong>Codestral AI</strong> from Mistral AI | Built with <strong>LangChain</strong> & <strong>Gradio</strong>
258
  </p>
259
  </div>
260
  """)
261
 
262
+ # Main layout - responsive row
263
  with gr.Row():
264
  # Main chat area
265
+ with gr.Column(scale=3, min_width=300):
266
  chatbot = gr.Chatbot(
267
  label="πŸ’¬ Chat with Codestral AI",
268
  height=500,
269
  show_label=True,
270
  container=True,
271
+ bubble_full_width=False,
272
+ elem_classes=["chatbot-container"]
273
  )
274
 
275
+ # Input row with responsive design
276
+ with gr.Row(elem_classes=["input-row"]):
277
  msg = gr.Textbox(
278
  label="Your Message",
279
  placeholder="Type your question here...",
280
  lines=2,
281
+ max_lines=4,
282
  scale=4,
283
+ container=True,
284
+ elem_classes=["textbox"]
285
+ )
286
+ send_btn = gr.Button(
287
+ "Send πŸš€",
288
+ variant="primary",
289
+ scale=1,
290
+ elem_classes=["button", "send-button"]
291
  )
 
292
 
293
+ # Clear button row
294
  with gr.Row():
295
  clear_btn = gr.Button("πŸ—‘οΈ Clear Chat", variant="secondary")
296
 
297
+ # Settings sidebar - responsive
298
+ with gr.Column(scale=1, min_width=200, elem_classes=["settings-panel"]):
299
+ gr.HTML("<h3 style='margin-bottom: 15px;'>βš™οΈ Model Settings</h3>")
300
 
301
  temperature = gr.Slider(
302
  minimum=0.0,
 
316
  info="Maximum response length"
317
  )
318
 
319
+ # Tips box
320
  gr.HTML("""
321
+ <div class="info-box" style="background-color: #f8f9fa;">
322
+ <h4 style="margin-top: 0;">πŸ’‘ Tips:</h4>
323
+ <ul style="margin: 10px 0; padding-left: 20px;">
324
  <li>Ask coding questions</li>
325
  <li>Request explanations</li>
326
  <li>Get creative writing help</li>
 
329
  </div>
330
  """)
331
 
332
+ # Features box
333
  gr.HTML("""
334
+ <div class="info-box" style="background-color: #e8f5e8;">
335
+ <h4 style="margin-top: 0;">πŸ”§ Features:</h4>
336
+ <ul style="margin: 10px 0; padding-left: 20px;">
337
  <li>βœ… Codestral AI Model</li>
338
  <li>βœ… LangChain Integration</li>
339
  <li>βœ… Real-time Responses</li>