Sarath0x8f commited on
Commit
eaf4284
·
verified ·
1 Parent(s): 81f8f31

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -328
app.py CHANGED
@@ -65,351 +65,39 @@ def respond(
65
 
66
  print(f"{datetime.datetime.now()}::{messages[-1]['content']}->{response}\n")
67
 
 
68
  # Encode image to base64
69
  def encode_image(image_path):
70
  with open(image_path, "rb") as image_file:
71
  return base64.b64encode(image_file.read()).decode('utf-8')
72
 
 
73
  # Load and encode logos
74
  github_logo_encoded = encode_image("Images/github-logo.png")
75
  linkedin_logo_encoded = encode_image("Images/linkedin-logo.png")
76
  website_logo_encoded = encode_image("Images/ai-logo.png")
77
 
78
- # Custom CSS for enhanced UI
79
- custom_css = """
80
- :root {
81
- --primary-color: #2563eb;
82
- --secondary-color: #1e40af;
83
- --accent-color: #3b82f6;
84
- --background-color: #f8fafc;
85
- --text-color: #1e293b;
86
- --border-radius: 12px;
87
- --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
88
- }
89
-
90
- body {
91
- font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
92
- background-color: var(--background-color);
93
- color: var(--text-color);
94
- }
95
-
96
- .container {
97
- max-width: 1200px;
98
- margin: 0 auto;
99
- padding: 2rem;
100
- }
101
-
102
- .header {
103
- text-align: center;
104
- margin-bottom: 2rem;
105
- padding: 1.5rem;
106
- background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
107
- border-radius: var(--border-radius);
108
- color: white;
109
- box-shadow: var(--shadow);
110
- }
111
-
112
- .header h1 {
113
- font-size: 2.5rem;
114
- margin-bottom: 0.5rem;
115
- font-weight: 700;
116
- }
117
-
118
- .header p {
119
- font-size: 1.1rem;
120
- opacity: 0.9;
121
- }
122
-
123
- .tabs {
124
- margin-bottom: 1.5rem;
125
- }
126
-
127
- .tab-button {
128
- padding: 0.75rem 1.5rem;
129
- font-size: 1rem;
130
- font-weight: 600;
131
- border: none;
132
- background-color: transparent;
133
- color: var(--text-color);
134
- cursor: pointer;
135
- transition: all 0.3s ease;
136
- border-bottom: 3px solid transparent;
137
- }
138
-
139
- .tab-button.active {
140
- color: var(--primary-color);
141
- border-bottom: 3px solid var(--primary-color);
142
- }
143
-
144
- .chatbot-container {
145
- background-color: white;
146
- border-radius: var(--border-radius);
147
- box-shadow: var(--shadow);
148
- overflow: hidden;
149
- }
150
-
151
- .chatbot-header {
152
- background-color: var(--primary-color);
153
- color: white;
154
- padding: 1rem;
155
- font-weight: 600;
156
- display: flex;
157
- align-items: center;
158
- }
159
-
160
- .chatbot-header .status {
161
- width: 10px;
162
- height: 10px;
163
- background-color: #10b981;
164
- border-radius: 50%;
165
- margin-right: 8px;
166
- }
167
-
168
- .chatbot-messages {
169
- height: 500px;
170
- overflow-y: auto;
171
- padding: 1rem;
172
- }
173
-
174
- .message {
175
- margin-bottom: 1rem;
176
- max-width: 80%;
177
- }
178
-
179
- .message.user {
180
- margin-left: auto;
181
- background-color: var(--primary-color);
182
- color: white;
183
- border-radius: 18px 18px 0 18px;
184
- padding: 0.75rem 1rem;
185
- }
186
-
187
- .message.bot {
188
- background-color: #f1f5f9;
189
- border-radius: 18px 18px 18px 0;
190
- padding: 0.75rem 1rem;
191
- }
192
-
193
- .chatbot-input {
194
- display: flex;
195
- padding: 1rem;
196
- border-top: 1px solid #e2e8f0;
197
- }
198
-
199
- .chatbot-input input {
200
- flex: 1;
201
- padding: 0.75rem 1rem;
202
- border: 1px solid #e2e8f0;
203
- border-radius: 24px;
204
- font-size: 1rem;
205
- }
206
-
207
- .chatbot-input button {
208
- background-color: var(--primary-color);
209
- color: white;
210
- border: none;
211
- border-radius: 24px;
212
- padding: 0.75rem 1.5rem;
213
- margin-left: 0.5rem;
214
- font-weight: 600;
215
- cursor: pointer;
216
- transition: background-color 0.3s ease;
217
- }
218
-
219
- .chatbot-input button:hover {
220
- background-color: var(--secondary-color);
221
- }
222
-
223
- .resume-container {
224
- background-color: white;
225
- border-radius: var(--border-radius);
226
- box-shadow: var(--shadow);
227
- padding: 2rem;
228
- }
229
-
230
- .resume-section {
231
- margin-bottom: 1.5rem;
232
- }
233
-
234
- .resume-section h2 {
235
- color: var(--primary-color);
236
- border-bottom: 2px solid #e2e8f0;
237
- padding-bottom: 0.5rem;
238
- margin-bottom: 1rem;
239
- }
240
-
241
- .footer {
242
- margin-top: 2rem;
243
- text-align: center;
244
- padding: 1.5rem;
245
- background-color: white;
246
- border-radius: var(--border-radius);
247
- box-shadow: var(--shadow);
248
- }
249
-
250
- .social-links {
251
- display: flex;
252
- justify-content: center;
253
- gap: 1.5rem;
254
- margin-top: 1rem;
255
- }
256
-
257
- .social-link {
258
- display: flex;
259
- align-items: center;
260
- gap: 0.5rem;
261
- text-decoration: none;
262
- color: var(--text-color);
263
- font-weight: 500;
264
- transition: color 0.3s ease;
265
- }
266
-
267
- .social-link:hover {
268
- color: var(--primary-color);
269
- }
270
-
271
- .social-link img {
272
- width: 24px;
273
- height: 24px;
274
- border-radius: 50%;
275
- }
276
-
277
- .examples-container {
278
- margin-top: 1.5rem;
279
- }
280
-
281
- .example-button {
282
- background-color: #f1f5f9;
283
- border: 1px solid #e2e8f0;
284
- border-radius: 24px;
285
- padding: 0.5rem 1rem;
286
- margin: 0.25rem;
287
- font-size: 0.9rem;
288
- cursor: pointer;
289
- transition: all 0.3s ease;
290
- }
291
-
292
- .example-button:hover {
293
- background-color: #e2e8f0;
294
- }
295
-
296
- /* Gradio overrides */
297
- footer {visibility: hidden !important;}
298
- .gradio-container {
299
- max-width: 100% !important;
300
- padding: 0 !important;
301
- }
302
- .tabs > div:first-child {
303
- border-bottom: 1px solid #e2e8f0;
304
- padding-bottom: 0.5rem;
305
- }
306
- .tabs > div:first-child button {
307
- font-weight: 600;
308
- }
309
- .chat-bot-container .message-wrap {
310
- padding: 0.75rem !important;
311
- }
312
- .chat-bot-container .user-message {
313
- background-color: var(--primary-color) !important;
314
- border-radius: 18px 18px 0 18px !important;
315
- }
316
- .chat-bot-container .bot-message {
317
- background-color: #f1f5f9 !important;
318
- border-radius: 18px 18px 18px 0 !important;
319
- }
320
- """
321
-
322
- # Gradio interface with enhanced UI
323
- with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="blue"), css=custom_css) as main:
324
- with gr.Row():
325
- with gr.Column():
326
- gr.HTML("""
327
- <div class="header">
328
- <h1>SARATH's Interactive Portfolio</h1>
329
- <p>BTech Final Year Student | AI & ML Enthusiast | Job Seeker</p>
330
- </div>
331
- """)
332
-
333
- with gr.Tabs() as tabs:
334
- with gr.TabItem("Chat with SARATH", id="chat-tab"):
335
- with gr.Row():
336
- with gr.Column():
337
- gr.HTML("""
338
- <div class="chatbot-header">
339
- <div class="status"></div>
340
- <span>SARATH's AI Assistant</span>
341
- </div>
342
- """)
343
-
344
- chatbot = gr.Chatbot(
345
- height=500,
346
- bubble=True,
347
- avatar_images=("Images/user-avatar.png", "Images/sarath-avatar.png"),
348
- show_label=False,
349
- elem_classes="chat-bot-container"
350
- )
351
-
352
- with gr.Row():
353
- msg = gr.Textbox(
354
- placeholder="Ask me anything about SARATH's skills, projects, or experience...",
355
- show_label=False,
356
- container=False
357
- )
358
- submit_btn = gr.Button("Send", variant="primary")
359
-
360
- gr.HTML("""
361
- <div class="examples-container">
362
- <h3>Try asking about:</h3>
363
- </div>
364
- """)
365
-
366
- examples = gr.Examples(
367
  examples=[
368
  "Tell me about yourself",
369
  'Can you walk me through some of your recent projects and explain the role you played in each?',
370
  "What specific skills do you bring to the table that would benefit our company's AI/ML initiatives?",
371
  "How do you stay updated with the latest trends and advancements in AI and Machine Learning?",
372
- ],
373
- inputs=msg,
374
- label="Example Questions"
375
  )
 
376
 
377
- submit_btn.click(respond, [msg, chatbot], [chatbot])
378
- msg.submit(respond, [msg, chatbot], [chatbot])
379
-
380
- gr.HTML(md.description)
381
-
382
- with gr.TabItem("Resume", id="resume-tab"):
383
- with gr.Row():
384
- with gr.Column():
385
- gr.HTML(f"""
386
- <div class="resume-container">
387
- <div class="resume-section">
388
- {data}
389
- </div>
390
- </div>
391
- """)
392
 
393
- gr.HTML(f"""
394
- <div class="footer">
395
- <p>Connect with SARATH</p>
396
- <div class="social-links">
397
- <a href="#" class="social-link">
398
- <img src="data:image/png;base64,{github_logo_encoded}" alt="GitHub">
399
- <span>GitHub</span>
400
- </a>
401
- <a href="#" class="social-link">
402
- <img src="data:image/png;base64,{linkedin_logo_encoded}" alt="LinkedIn">
403
- <span>LinkedIn</span>
404
- </a>
405
- <a href="#" class="social-link">
406
- <img src="data:image/png;base64,{website_logo_encoded}" alt="Website">
407
- <span>Portfolio</span>
408
- </a>
409
- </div>
410
- <p class="copyright">© {datetime.datetime.now().year} SARATH. All rights reserved.</p>
411
- </div>
412
- """)
413
 
414
  if __name__ == "__main__":
415
- main.launch(share=True)
 
65
 
66
  print(f"{datetime.datetime.now()}::{messages[-1]['content']}->{response}\n")
67
 
68
+
69
  # Encode image to base64
70
  def encode_image(image_path):
71
  with open(image_path, "rb") as image_file:
72
  return base64.b64encode(image_file.read()).decode('utf-8')
73
 
74
+
75
  # Load and encode logos
76
  github_logo_encoded = encode_image("Images/github-logo.png")
77
  linkedin_logo_encoded = encode_image("Images/linkedin-logo.png")
78
  website_logo_encoded = encode_image("Images/ai-logo.png")
79
 
80
+ # Gradio interface
81
+ with gr.Blocks(theme=gr.themes.Ocean(font=[gr.themes.GoogleFont("Roboto Mono")]), css='footer {visibility: hidden}') as main:
82
+ gr.Markdown(md.title)
83
+ with gr.Tabs():
84
+ with gr.TabItem("My2.0", visible=True, interactive=True):
85
+ gr.ChatInterface(
86
+ respond,
87
+ chatbot=gr.Chatbot(height=500),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  examples=[
89
  "Tell me about yourself",
90
  'Can you walk me through some of your recent projects and explain the role you played in each?',
91
  "What specific skills do you bring to the table that would benefit our company's AI/ML initiatives?",
92
  "How do you stay updated with the latest trends and advancements in AI and Machine Learning?",
93
+ ]
 
 
94
  )
95
+ gr.Markdown(md.description)
96
 
97
+ with gr.TabItem("Resume", visible=True, interactive=True):
98
+ gr.Markdown(data)
 
 
 
 
 
 
 
 
 
 
 
 
 
99
 
100
+ gr.HTML(md.footer.format(github_logo_encoded, linkedin_logo_encoded, website_logo_encoded))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
 
102
  if __name__ == "__main__":
103
+ main.launch(share=True)