prernajeet14 commited on
Commit
473b6b7
Β·
verified Β·
1 Parent(s): ebeb1f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +414 -331
app.py CHANGED
@@ -9,6 +9,7 @@ import sys
9
  import tempfile
10
  import zipfile
11
  from datetime import datetime
 
12
 
13
  class CodingCopilot:
14
  def __init__(self):
@@ -113,8 +114,26 @@ class CodingCopilot:
113
 
114
  return combined_content, status
115
 
116
- def process_message(self, message: str, files: List = None, history: List = None) -> str:
117
- """Process user message with advanced context handling for long code generation."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
  if history is None:
119
  history = []
120
 
@@ -132,12 +151,10 @@ class CodingCopilot:
132
  context = ""
133
  if history:
134
  if is_continuation:
135
- # For continuation, include more context (last 5 exchanges)
136
  context = "\n\nFull conversation context for continuation:\n"
137
  for i, (user_msg, assistant_msg) in enumerate(history[-5:]):
138
  context += f"Exchange {i+1}:\nUser: {user_msg}\nAssistant: {assistant_msg}\n\n"
139
  else:
140
- # For new topics, include recent context (last 3 exchanges)
141
  context = "\n\nRecent conversation context:\n"
142
  for i, (user_msg, assistant_msg) in enumerate(history[-3:]):
143
  context += f"User: {user_msg}\nAssistant: {assistant_msg}\n\n"
@@ -171,7 +188,6 @@ User's continuation request: {message}
171
  {final_instruction}"""
172
 
173
  else:
174
- # Determine if this is a code generation request
175
  generation_keywords = ['create', 'generate', 'build', 'make', 'develop', 'write code', 'implement', 'design']
176
  is_generation = any(keyword in message.lower() for keyword in generation_keywords)
177
 
@@ -204,7 +220,6 @@ User's request: {message}
204
  {final_instruction}"""
205
 
206
  else:
207
- # Regular analysis/chat prompt
208
  file_content_section = f"\nCode files content:\n```\n{file_content}\n```" if file_content else ""
209
 
210
  prompt = f"""You are an advanced coding assistant. Provide detailed, comprehensive responses.
@@ -219,511 +234,578 @@ User's request: {message}
219
 
220
  Provide a thorough and helpful response. If suggesting code changes, provide complete implementations."""
221
 
222
- return self.call_claude(prompt, max_tokens=8000)
223
-
224
- def create_download_file(self, content: str, filename: str = "code_output.py") -> str:
225
- """Create a downloadable file with the given content."""
226
- timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
227
- filename = f"{timestamp}_{filename}"
228
 
229
- temp_file = tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False)
230
- temp_file.write(content)
231
- temp_file.close()
232
 
233
- return temp_file.name
 
 
 
 
 
234
 
235
  # Initialize the copilot
236
  copilot = CodingCopilot()
237
 
238
- # Professional ChatGPT-style CSS
239
- chatgpt_css = """
240
  /* Global Styles */
 
 
 
 
241
  .gradio-container {
242
- max-width: 1200px !important;
243
  margin: 0 auto !important;
244
- background: #ffffff !important;
245
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif !important;
 
246
  }
247
 
248
  /* Header Styles */
249
  .header-container {
250
- background: linear-gradient(90deg, #10a37f 0%, #1a7f64 100%) !important;
251
- padding: 1rem 2rem !important;
252
- margin: -1rem -1rem 1rem -1rem !important;
253
- border-radius: 0 !important;
 
 
254
  }
255
 
256
  .header-title {
257
- color: white !important;
258
- font-size: 1.5rem !important;
259
- font-weight: 600 !important;
260
  margin: 0 !important;
261
  text-align: center !important;
 
 
 
 
262
  }
263
 
264
  .header-subtitle {
265
- color: rgba(255, 255, 255, 0.9) !important;
266
- font-size: 0.9rem !important;
267
  text-align: center !important;
268
  margin: 0.5rem 0 0 0 !important;
 
269
  }
270
 
271
- /* Chat Interface */
272
- .chat-container {
273
- background: #ffffff !important;
274
- border-radius: 8px !important;
275
- border: 1px solid #e5e5e5 !important;
276
- max-height: 600px !important;
277
- overflow-y: auto !important;
278
- padding: 0 !important;
279
  }
280
 
281
- .chatbot {
282
- background: transparent !important;
283
- border: none !important;
 
 
 
 
284
  }
285
 
286
- .message {
287
- padding: 1rem 1.5rem !important;
288
- border-bottom: 1px solid #f0f0f0 !important;
 
 
 
 
289
  }
290
 
291
- .message:last-child {
292
- border-bottom: none !important;
 
 
293
  }
294
 
295
- .user-message {
296
- background: #f8f9fa !important;
297
- margin: 0.5rem 0 !important;
298
- padding: 0.75rem 1rem !important;
299
- border-radius: 8px !important;
300
- border: 1px solid #e9ecef !important;
301
  }
302
 
303
- .bot-message {
 
 
 
 
 
 
 
 
 
 
304
  background: transparent !important;
305
- margin: 0.5rem 0 !important;
306
- padding: 0.75rem 1rem !important;
307
  }
308
 
309
  /* Input Area */
310
- .input-container {
311
- background: #ffffff !important;
312
- border: 1px solid #d1d5db !important;
313
- border-radius: 12px !important;
314
- padding: 0.5rem !important;
315
- margin-top: 1rem !important;
316
  }
317
 
318
  .input-row {
319
  display: flex !important;
 
320
  align-items: flex-end !important;
321
- gap: 0.5rem !important;
322
  }
323
 
324
- .chat-input {
325
- flex: 1 !important;
326
- border: none !important;
327
- background: transparent !important;
328
- resize: vertical !important;
329
- min-height: 24px !important;
330
- padding: 0.5rem !important;
331
  font-size: 1rem !important;
332
  line-height: 1.5 !important;
 
 
333
  }
334
 
335
- .chat-input:focus {
336
  outline: none !important;
337
- box-shadow: none !important;
 
 
 
 
 
338
  }
339
 
340
  /* Buttons */
341
- .send-button {
342
- background: #10a37f !important;
343
  color: white !important;
344
  border: none !important;
345
- border-radius: 8px !important;
346
- padding: 0.5rem 1rem !important;
347
- font-weight: 500 !important;
 
348
  cursor: pointer !important;
349
- transition: background-color 0.2s ease !important;
350
- min-width: 80px !important;
351
- }
352
-
353
- .send-button:hover {
354
- background: #0d8c6c !important;
355
  }
356
 
357
- .send-button:disabled {
358
- background: #9ca3af !important;
359
- cursor: not-allowed !important;
 
360
  }
361
 
362
  .secondary-button {
363
- background: #f3f4f6 !important;
364
- color: #374151 !important;
365
- border: 1px solid #d1d5db !important;
366
- border-radius: 8px !important;
367
- padding: 0.5rem 1rem !important;
368
  font-weight: 500 !important;
369
  cursor: pointer !important;
370
- transition: all 0.2s ease !important;
 
 
 
371
  }
372
 
373
  .secondary-button:hover {
374
- background: #e5e7eb !important;
375
- border-color: #9ca3af !important;
 
376
  }
377
 
378
- /* File Upload Area */
379
- .file-upload-area {
380
- background: #f9fafb !important;
381
- border: 2px dashed #d1d5db !important;
382
  border-radius: 8px !important;
383
- padding: 1rem !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
384
  text-align: center !important;
385
- transition: all 0.2s ease !important;
386
- margin-bottom: 1rem !important;
387
  }
388
 
389
- .file-upload-area:hover {
390
- border-color: #10a37f !important;
391
- background: #f0fdf4 !important;
392
  }
393
 
394
  .file-upload-text {
395
- color: #6b7280 !important;
396
  font-size: 0.9rem !important;
397
  }
398
 
399
- /* Status and Info */
400
- .status-message {
401
- background: #f0f9ff !important;
402
- border: 1px solid #7dd3fc !important;
403
- border-radius: 6px !important;
404
- padding: 0.75rem !important;
405
- margin: 0.5rem 0 !important;
406
- font-size: 0.9rem !important;
407
- color: #0c4a6e !important;
408
  }
409
 
410
- .error-message {
411
- background: #fef2f2 !important;
412
- border: 1px solid #fecaca !important;
413
- border-radius: 6px !important;
414
- padding: 0.75rem !important;
 
 
 
 
 
 
 
 
 
 
415
  margin: 0.5rem 0 !important;
 
 
 
 
 
 
 
 
416
  font-size: 0.9rem !important;
417
- color: #991b1b !important;
418
  }
419
 
420
- /* Code blocks */
421
- .code-block {
422
- background: #f8f9fa !important;
423
- border: 1px solid #e9ecef !important;
424
- border-radius: 6px !important;
425
  padding: 1rem !important;
426
- font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace !important;
 
427
  font-size: 0.9rem !important;
428
  line-height: 1.4 !important;
429
  overflow-x: auto !important;
430
  }
431
 
432
- /* Sidebar */
433
- .sidebar {
434
- background: #f8f9fa !important;
435
- border-right: 1px solid #e5e5e5 !important;
436
- padding: 1rem !important;
437
- height: 100vh !important;
438
- overflow-y: auto !important;
439
  }
440
 
441
- .sidebar-title {
442
- font-weight: 600 !important;
443
- color: #374151 !important;
444
- margin-bottom: 1rem !important;
445
- font-size: 1.1rem !important;
 
 
 
 
 
 
 
 
 
 
 
 
446
  }
447
 
448
  /* Mobile Responsiveness */
449
  @media (max-width: 768px) {
450
  .gradio-container {
451
- margin: 0 !important;
452
- padding: 0.5rem !important;
453
  }
454
 
455
- .header-container {
456
- margin: -0.5rem -0.5rem 1rem -0.5rem !important;
457
- padding: 1rem !important;
458
  }
459
 
460
- .chat-container {
461
- max-height: 500px !important;
 
462
  }
463
 
464
  .input-row {
465
  flex-direction: column !important;
466
- gap: 0.75rem !important;
467
  }
468
 
469
- .send-button {
470
  width: 100% !important;
471
  }
472
  }
473
 
474
- /* Loading animation */
475
- .loading {
476
- display: inline-block !important;
477
- width: 20px !important;
478
- height: 20px !important;
479
- border: 3px solid #f3f3f3 !important;
480
- border-top: 3px solid #10a37f !important;
481
- border-radius: 50% !important;
482
- animation: spin 1s linear infinite !important;
483
  }
484
 
485
- @keyframes spin {
486
- 0% { transform: rotate(0deg); }
487
- 100% { transform: rotate(360deg); }
488
  }
489
 
490
- /* Hide default gradio elements */
491
- .gradio-container .gr-button {
492
- transition: all 0.2s ease !important;
493
- }
494
-
495
- /* Custom scrollbar */
496
- .chat-container::-webkit-scrollbar {
497
- width: 6px !important;
498
- }
499
-
500
- .chat-container::-webkit-scrollbar-track {
501
- background: #f1f1f1 !important;
502
- }
503
-
504
- .chat-container::-webkit-scrollbar-thumb {
505
- background: #c1c1c1 !important;
506
- border-radius: 3px !important;
507
  }
508
 
509
- .chat-container::-webkit-scrollbar-thumb:hover {
510
- background: #a1a1a1 !important;
511
  }
512
  """
513
 
514
  def process_chat_message(message, files, history):
515
- """Process a new chat message with advanced continuation support."""
516
  if not message.strip() and not files:
517
- return history, history, ""
518
 
519
- # Add user message to history
520
  if history is None:
521
  history = []
522
 
523
  user_msg = message
524
  if files:
525
  file_names = [os.path.basename(f.name) for f in files]
526
- user_msg += f" πŸ“ *[Uploaded: {', '.join(file_names)}]*"
527
 
528
- # Special handling for continuation requests
529
- continue_keywords = ['continue', 'continue the code', 'continue from where', 'keep going', 'add more', 'extend', 'complete the']
530
- is_continuation = any(keyword in message.lower() for keyword in continue_keywords)
531
 
532
- if is_continuation and history:
533
- # For continuation, show a status message to user
534
- status_msg = "πŸ”„ **Continuing from previous code...** (Analyzing context and extending the implementation)"
535
- temp_history = history + [[user_msg, status_msg]]
536
-
537
- # Get AI response with full context
538
- ai_response = copilot.process_message(message, files, history)
539
-
540
- # Add both messages to history
541
- history.append([user_msg, ai_response])
542
-
543
- return history, history, ""
544
- else:
545
- # Regular processing
546
- ai_response = copilot.process_message(message, files, history)
547
-
548
- # Add both messages to history
549
- history.append([user_msg, ai_response])
550
-
551
- return history, history, ""
552
-
553
- def smart_continue_suggestion(history):
554
- """Suggest continuation if the last response seems incomplete."""
555
- if not history:
556
- return ""
557
 
558
- last_response = history[-1][1] if history else ""
 
 
 
559
 
560
- # Check if response might be incomplete
561
- incomplete_indicators = [
562
- "```" in last_response and last_response.count("```") % 2 != 0, # Unclosed code block
563
- last_response.endswith("..."),
564
- "# TODO" in last_response,
565
- "# Continue" in last_response.lower(),
566
- len(last_response) > 3000 # Very long response might be cut off
567
- ]
568
-
569
- if any(incomplete_indicators):
570
- return "πŸ’‘ **Tip**: Type 'continue' to extend this code or add more functionality!"
571
-
572
- return ""
573
 
574
  def clear_chat():
575
  """Clear the chat history."""
576
- return [], []
577
-
578
- def create_download_from_message(message):
579
- """Create a downloadable file from the current message if it contains code."""
580
- if "```" in message:
581
- # Extract code blocks
582
- import re
583
- code_blocks = re.findall(r'```(?:\w+)?\n(.*?)\n```', message, re.DOTALL)
584
- if code_blocks:
585
- combined_code = "\n\n".join(code_blocks)
586
- return copilot.create_download_file(combined_code)
587
- return None
588
 
589
  # Create the main interface
590
- with gr.Blocks(css=chatgpt_css, title="Coding Copilot Pro") as app:
 
591
  # Header
592
  gr.HTML("""
593
  <div class="header-container">
594
- <h1 class="header-title">πŸ€– Coding Copilot Pro</h1>
595
- <p class="header-subtitle">Your AI-powered coding assistant β€’ Powered by Claude 3 Haiku</p>
596
  </div>
597
  """)
598
 
599
- # Main chat interface
600
- with gr.Row():
601
- with gr.Column(scale=1, min_width=250):
602
- # Sidebar with features
603
- gr.HTML('<h3 class="sidebar-title">✨ Features</h3>')
 
 
604
  gr.Markdown("""
605
- **πŸ’¬ Chat Features:**
606
- β€’ Long code generation (1000+ lines)
607
- β€’ Smart continuation support
608
- β€’ Code analysis & review
609
- β€’ Bug detection & fixes
610
- β€’ Code optimization
611
- β€’ Architecture advice
612
- β€’ Best practices
 
 
 
 
 
 
 
 
 
 
 
613
 
614
- **πŸ“ File Support:**
615
- β€’ Python files (.py)
616
- β€’ Jupyter notebooks (.ipynb)
617
- β€’ Multiple file upload
 
618
 
619
- **πŸ› οΈ Capabilities:**
620
- β€’ Generate complete applications
621
- β€’ Continue incomplete code
622
- β€’ Debug existing code
623
- β€’ Explain complex algorithms
624
- β€’ Refactor & optimize
625
- β€’ Add comprehensive documentation
626
 
627
- **πŸ’‘ Pro Tips:**
628
- β€’ Say "continue" to extend code
629
- β€’ Upload files for context
630
- β€’ Ask for "complete implementation"
631
- β€’ Request "production-ready code"
632
- """)
633
 
634
- # Quick actions
635
- gr.HTML('<h3 class="sidebar-title">πŸš€ Quick Actions</h3>')
636
  with gr.Column():
637
- quick_review = gr.Button("πŸ“‹ Code Review", size="sm", variant="secondary")
638
- quick_debug = gr.Button("πŸ› Debug Code", size="sm", variant="secondary")
639
- quick_optimize = gr.Button("⚑ Optimize", size="sm", variant="secondary")
640
- quick_explain = gr.Button("πŸ“– Explain Code", size="sm", variant="secondary")
 
 
 
 
641
 
 
642
  with gr.Column(scale=3):
 
 
643
  # Chat interface
644
  chatbot = gr.Chatbot(
645
- height=500,
646
  show_label=False,
647
- container=True,
648
  bubble_full_width=False,
649
- avatar_images=("πŸ‘€", "πŸ€–")
 
650
  )
651
 
652
- # Input area
 
 
 
 
 
 
 
653
  with gr.Row():
654
- with gr.Column(scale=1):
655
- # File upload
656
- files = gr.File(
657
- label="πŸ“Ž Attach Files",
658
- file_count="multiple",
659
- file_types=[".py", ".ipynb"],
660
- show_label=False,
661
- container=False
662
- )
663
-
664
- with gr.Column(scale=4):
665
- # Message input
666
- msg = gr.Textbox(
667
- label="Message",
668
- placeholder="Ask me anything about coding... Type 'continue' to extend previous code, or request 'complete implementation' for long code generation",
669
- show_label=False,
670
- lines=1,
671
- max_lines=5
672
- )
673
 
674
- with gr.Column(scale=1, min_width=100):
675
- # Send and clear buttons
676
- with gr.Row():
677
- submit = gr.Button("Send", variant="primary", scale=2)
678
- clear = gr.Button("πŸ—‘οΈ", variant="secondary", scale=1)
 
679
 
680
- # Hidden state for chat history
681
  chat_history = gr.State([])
682
 
683
  # Event handlers
684
- def quick_action(action_type):
685
- return f"Please {action_type.lower()} the uploaded code files."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
686
 
687
- # Quick action buttons
688
- quick_review.click(lambda: "Please perform a comprehensive code review of the uploaded files, including quality assessment, potential bugs, performance improvements, and security considerations.", outputs=msg)
689
- quick_debug.click(lambda: "Please debug the uploaded code thoroughly and identify any issues, bugs, or potential problems with detailed fixes.", outputs=msg)
690
- quick_optimize.click(lambda: "Please optimize the uploaded code for better performance, readability, and maintainability. Provide the complete optimized version.", outputs=msg)
691
- quick_explain.click(lambda: "Please provide a detailed explanation of what this code does, how it works, and its key components with examples.", outputs=msg)
692
 
693
- # Enhanced continuation support
694
- def handle_submit_with_continuation(message, files, history):
695
- result_history, result_state, cleared_msg = process_chat_message(message, files, history)
696
- suggestion = smart_continue_suggestion(result_history)
697
- return result_history, result_state, cleared_msg, suggestion
698
 
699
- # Main chat functionality with continuation support
 
 
 
 
 
700
  submit.click(
701
- handle_submit_with_continuation,
702
  inputs=[msg, files, chat_history],
703
- outputs=[chatbot, chat_history, msg, gr.HTML(visible=False)]
704
  ).then(
705
- lambda: [None, None], # Clear files after sending
706
- outputs=[files, msg]
707
  )
708
 
709
- # Enter key submission with continuation support
710
  msg.submit(
711
- handle_submit_with_continuation,
712
  inputs=[msg, files, chat_history],
713
- outputs=[chatbot, chat_history, msg, gr.HTML(visible=False)]
714
  ).then(
715
- lambda: [None, None],
716
- outputs=[files, msg]
717
  )
718
 
719
- # Clear chat
720
- clear.click(clear_chat, outputs=[chatbot, chat_history])
 
 
721
 
722
  # Footer
723
  gr.HTML("""
724
- <div style="text-align: center; padding: 2rem 0; color: #6b7280; font-size: 0.9rem; border-top: 1px solid #e5e7eb; margin-top: 2rem;">
725
- <p><strong>Coding Copilot Pro</strong> β€’ Built with Claude 3 Haiku via AWS Bedrock</p>
726
- <p>Upload your code files and start chatting for intelligent analysis, debugging, and optimization</p>
727
  </div>
728
  """)
729
 
@@ -734,5 +816,6 @@ if __name__ == "__main__":
734
  server_port=7860,
735
  share=True,
736
  show_error=True,
737
- show_api=False
 
738
  )
 
9
  import tempfile
10
  import zipfile
11
  from datetime import datetime
12
+ import re
13
 
14
  class CodingCopilot:
15
  def __init__(self):
 
114
 
115
  return combined_content, status
116
 
117
+ def extract_code_blocks(self, text: str) -> List[str]:
118
+ """Extract code blocks from response text."""
119
+ code_blocks = re.findall(r'```(?:\w+)?\n(.*?)\n```', text, re.DOTALL)
120
+ return code_blocks
121
+
122
+ def create_download_file(self, content: str, filename: str = "generated_code.py") -> str:
123
+ """Create a downloadable file with the given content."""
124
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
125
+ base_name = os.path.splitext(filename)[0]
126
+ extension = os.path.splitext(filename)[1] or '.py'
127
+ filename = f"{base_name}_{timestamp}{extension}"
128
+
129
+ temp_file = tempfile.NamedTemporaryFile(mode='w', suffix=extension, delete=False)
130
+ temp_file.write(content)
131
+ temp_file.close()
132
+
133
+ return temp_file.name
134
+
135
+ def process_message(self, message: str, files: List = None, history: List = None) -> Tuple[str, Optional[str]]:
136
+ """Process user message and return response with optional download file."""
137
  if history is None:
138
  history = []
139
 
 
151
  context = ""
152
  if history:
153
  if is_continuation:
 
154
  context = "\n\nFull conversation context for continuation:\n"
155
  for i, (user_msg, assistant_msg) in enumerate(history[-5:]):
156
  context += f"Exchange {i+1}:\nUser: {user_msg}\nAssistant: {assistant_msg}\n\n"
157
  else:
 
158
  context = "\n\nRecent conversation context:\n"
159
  for i, (user_msg, assistant_msg) in enumerate(history[-3:]):
160
  context += f"User: {user_msg}\nAssistant: {assistant_msg}\n\n"
 
188
  {final_instruction}"""
189
 
190
  else:
 
191
  generation_keywords = ['create', 'generate', 'build', 'make', 'develop', 'write code', 'implement', 'design']
192
  is_generation = any(keyword in message.lower() for keyword in generation_keywords)
193
 
 
220
  {final_instruction}"""
221
 
222
  else:
 
223
  file_content_section = f"\nCode files content:\n```\n{file_content}\n```" if file_content else ""
224
 
225
  prompt = f"""You are an advanced coding assistant. Provide detailed, comprehensive responses.
 
234
 
235
  Provide a thorough and helpful response. If suggesting code changes, provide complete implementations."""
236
 
237
+ # Get response from Claude
238
+ response = self.call_claude(prompt, max_tokens=8000)
 
 
 
 
239
 
240
+ # Extract code blocks for download
241
+ code_blocks = self.extract_code_blocks(response)
242
+ download_file = None
243
 
244
+ if code_blocks:
245
+ combined_code = "\n\n".join(code_blocks)
246
+ if len(combined_code.strip()) > 50: # Only create download if substantial code
247
+ download_file = self.create_download_file(combined_code)
248
+
249
+ return response, download_file
250
 
251
  # Initialize the copilot
252
  copilot = CodingCopilot()
253
 
254
+ # Professional Black & Red CSS Theme
255
+ professional_css = """
256
  /* Global Styles */
257
+ * {
258
+ box-sizing: border-box;
259
+ }
260
+
261
  .gradio-container {
262
+ max-width: 1400px !important;
263
  margin: 0 auto !important;
264
+ background: #0a0a0a !important;
265
+ font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif !important;
266
+ color: #ffffff !important;
267
  }
268
 
269
  /* Header Styles */
270
  .header-container {
271
+ background: linear-gradient(135deg, #1a1a1a 0%, #2d1b1b 50%, #1a1a1a 100%) !important;
272
+ border: 1px solid #dc2626 !important;
273
+ border-radius: 12px !important;
274
+ padding: 2rem !important;
275
+ margin-bottom: 2rem !important;
276
+ box-shadow: 0 8px 32px rgba(220, 38, 38, 0.1) !important;
277
  }
278
 
279
  .header-title {
280
+ color: #ffffff !important;
281
+ font-size: 2.5rem !important;
282
+ font-weight: 700 !important;
283
  margin: 0 !important;
284
  text-align: center !important;
285
+ background: linear-gradient(135deg, #ffffff 0%, #dc2626 100%) !important;
286
+ -webkit-background-clip: text !important;
287
+ -webkit-text-fill-color: transparent !important;
288
+ background-clip: text !important;
289
  }
290
 
291
  .header-subtitle {
292
+ color: #a1a1aa !important;
293
+ font-size: 1.1rem !important;
294
  text-align: center !important;
295
  margin: 0.5rem 0 0 0 !important;
296
+ font-weight: 400 !important;
297
  }
298
 
299
+ /* Main Layout */
300
+ .main-container {
301
+ background: #111111 !important;
302
+ border-radius: 16px !important;
303
+ border: 1px solid #262626 !important;
304
+ overflow: hidden !important;
305
+ box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3) !important;
 
306
  }
307
 
308
+ /* Sidebar */
309
+ .sidebar {
310
+ background: linear-gradient(180deg, #1a1a1a 0%, #0f0f0f 100%) !important;
311
+ border-right: 1px solid #dc2626 !important;
312
+ padding: 2rem !important;
313
+ height: 100% !important;
314
+ min-height: 700px !important;
315
  }
316
 
317
+ .sidebar-title {
318
+ color: #dc2626 !important;
319
+ font-weight: 700 !important;
320
+ font-size: 1.2rem !important;
321
+ margin-bottom: 1.5rem !important;
322
+ text-transform: uppercase !important;
323
+ letter-spacing: 0.5px !important;
324
  }
325
 
326
+ .sidebar-content {
327
+ color: #d1d5db !important;
328
+ font-size: 0.9rem !important;
329
+ line-height: 1.6 !important;
330
  }
331
 
332
+ .sidebar-content strong {
333
+ color: #ffffff !important;
 
 
 
 
334
  }
335
 
336
+ /* Chat Interface */
337
+ .chat-container {
338
+ background: #0f0f0f !important;
339
+ border-radius: 0 !important;
340
+ border: none !important;
341
+ min-height: 600px !important;
342
+ max-height: 600px !important;
343
+ overflow-y: auto !important;
344
+ }
345
+
346
+ .chatbot {
347
  background: transparent !important;
348
+ border: none !important;
 
349
  }
350
 
351
  /* Input Area */
352
+ .input-section {
353
+ background: #1a1a1a !important;
354
+ border-top: 1px solid #262626 !important;
355
+ padding: 1.5rem !important;
 
 
356
  }
357
 
358
  .input-row {
359
  display: flex !important;
360
+ gap: 1rem !important;
361
  align-items: flex-end !important;
 
362
  }
363
 
364
+ .message-input {
365
+ background: #262626 !important;
366
+ border: 1px solid #404040 !important;
367
+ border-radius: 12px !important;
368
+ color: #ffffff !important;
369
+ padding: 1rem !important;
 
370
  font-size: 1rem !important;
371
  line-height: 1.5 !important;
372
+ resize: vertical !important;
373
+ transition: all 0.3s ease !important;
374
  }
375
 
376
+ .message-input:focus {
377
  outline: none !important;
378
+ border-color: #dc2626 !important;
379
+ box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1) !important;
380
+ }
381
+
382
+ .message-input::placeholder {
383
+ color: #6b7280 !important;
384
  }
385
 
386
  /* Buttons */
387
+ .primary-button {
388
+ background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%) !important;
389
  color: white !important;
390
  border: none !important;
391
+ border-radius: 12px !important;
392
+ padding: 1rem 2rem !important;
393
+ font-weight: 600 !important;
394
+ font-size: 1rem !important;
395
  cursor: pointer !important;
396
+ transition: all 0.3s ease !important;
397
+ box-shadow: 0 4px 16px rgba(220, 38, 38, 0.2) !important;
398
+ text-transform: uppercase !important;
399
+ letter-spacing: 0.5px !important;
 
 
400
  }
401
 
402
+ .primary-button:hover {
403
+ background: linear-gradient(135deg, #b91c1c 0%, #991b1b 100%) !important;
404
+ transform: translateY(-2px) !important;
405
+ box-shadow: 0 8px 24px rgba(220, 38, 38, 0.3) !important;
406
  }
407
 
408
  .secondary-button {
409
+ background: #262626 !important;
410
+ color: #ffffff !important;
411
+ border: 1px solid #404040 !important;
412
+ border-radius: 12px !important;
413
+ padding: 0.75rem 1.5rem !important;
414
  font-weight: 500 !important;
415
  cursor: pointer !important;
416
+ transition: all 0.3s ease !important;
417
+ text-transform: uppercase !important;
418
+ letter-spacing: 0.5px !important;
419
+ font-size: 0.9rem !important;
420
  }
421
 
422
  .secondary-button:hover {
423
+ background: #404040 !important;
424
+ border-color: #dc2626 !important;
425
+ transform: translateY(-1px) !important;
426
  }
427
 
428
+ .quick-action-button {
429
+ background: #1a1a1a !important;
430
+ color: #dc2626 !important;
431
+ border: 1px solid #dc2626 !important;
432
  border-radius: 8px !important;
433
+ padding: 0.75rem 1rem !important;
434
+ font-weight: 500 !important;
435
+ cursor: pointer !important;
436
+ transition: all 0.3s ease !important;
437
+ margin-bottom: 0.5rem !important;
438
+ width: 100% !important;
439
+ text-align: left !important;
440
+ font-size: 0.9rem !important;
441
+ }
442
+
443
+ .quick-action-button:hover {
444
+ background: #dc2626 !important;
445
+ color: #ffffff !important;
446
+ transform: translateX(4px) !important;
447
+ }
448
+
449
+ /* File Upload */
450
+ .file-upload {
451
+ background: #1a1a1a !important;
452
+ border: 2px dashed #404040 !important;
453
+ border-radius: 12px !important;
454
+ padding: 1.5rem !important;
455
  text-align: center !important;
456
+ transition: all 0.3s ease !important;
457
+ color: #d1d5db !important;
458
  }
459
 
460
+ .file-upload:hover {
461
+ border-color: #dc2626 !important;
462
+ background: #262626 !important;
463
  }
464
 
465
  .file-upload-text {
466
+ color: #9ca3af !important;
467
  font-size: 0.9rem !important;
468
  }
469
 
470
+ /* Download Section */
471
+ .download-section {
472
+ background: #1a1a1a !important;
473
+ border: 1px solid #262626 !important;
474
+ border-radius: 12px !important;
475
+ padding: 1rem !important;
476
+ margin-top: 1rem !important;
 
 
477
  }
478
 
479
+ .download-title {
480
+ color: #dc2626 !important;
481
+ font-weight: 600 !important;
482
+ margin-bottom: 0.5rem !important;
483
+ font-size: 1rem !important;
484
+ }
485
+
486
+ /* Status Messages */
487
+ .status-success {
488
+ background: linear-gradient(135deg, #065f46 0%, #047857 100%) !important;
489
+ border: 1px solid #10b981 !important;
490
+ border-radius: 8px !important;
491
+ padding: 1rem !important;
492
+ color: #ffffff !important;
493
+ font-size: 0.9rem !important;
494
  margin: 0.5rem 0 !important;
495
+ }
496
+
497
+ .status-error {
498
+ background: linear-gradient(135deg, #7f1d1d 0%, #991b1b 100%) !important;
499
+ border: 1px solid #dc2626 !important;
500
+ border-radius: 8px !important;
501
+ padding: 1rem !important;
502
+ color: #ffffff !important;
503
  font-size: 0.9rem !important;
504
+ margin: 0.5rem 0 !important;
505
  }
506
 
507
+ /* Code Blocks */
508
+ pre {
509
+ background: #0a0a0a !important;
510
+ border: 1px solid #262626 !important;
511
+ border-radius: 8px !important;
512
  padding: 1rem !important;
513
+ color: #ffffff !important;
514
+ font-family: 'JetBrains Mono', 'Fira Code', monospace !important;
515
  font-size: 0.9rem !important;
516
  line-height: 1.4 !important;
517
  overflow-x: auto !important;
518
  }
519
 
520
+ code {
521
+ background: #1a1a1a !important;
522
+ color: #dc2626 !important;
523
+ padding: 0.2rem 0.4rem !important;
524
+ border-radius: 4px !important;
525
+ font-family: 'JetBrains Mono', 'Fira Code', monospace !important;
526
+ font-size: 0.9rem !important;
527
  }
528
 
529
+ /* Scrollbar */
530
+ ::-webkit-scrollbar {
531
+ width: 8px !important;
532
+ height: 8px !important;
533
+ }
534
+
535
+ ::-webkit-scrollbar-track {
536
+ background: #1a1a1a !important;
537
+ }
538
+
539
+ ::-webkit-scrollbar-thumb {
540
+ background: #404040 !important;
541
+ border-radius: 4px !important;
542
+ }
543
+
544
+ ::-webkit-scrollbar-thumb:hover {
545
+ background: #dc2626 !important;
546
  }
547
 
548
  /* Mobile Responsiveness */
549
  @media (max-width: 768px) {
550
  .gradio-container {
551
+ padding: 1rem !important;
 
552
  }
553
 
554
+ .header-title {
555
+ font-size: 2rem !important;
 
556
  }
557
 
558
+ .sidebar {
559
+ min-height: auto !important;
560
+ padding: 1rem !important;
561
  }
562
 
563
  .input-row {
564
  flex-direction: column !important;
565
+ gap: 1rem !important;
566
  }
567
 
568
+ .primary-button {
569
  width: 100% !important;
570
  }
571
  }
572
 
573
+ /* Animations */
574
+ @keyframes fadeIn {
575
+ from { opacity: 0; transform: translateY(10px); }
576
+ to { opacity: 1; transform: translateY(0); }
 
 
 
 
 
577
  }
578
 
579
+ .chat-message {
580
+ animation: fadeIn 0.3s ease-out !important;
 
581
  }
582
 
583
+ /* Footer */
584
+ .footer {
585
+ background: #0a0a0a !important;
586
+ border-top: 1px solid #262626 !important;
587
+ padding: 2rem !important;
588
+ text-align: center !important;
589
+ color: #6b7280 !important;
590
+ margin-top: 2rem !important;
 
 
 
 
 
 
 
 
 
591
  }
592
 
593
+ .footer strong {
594
+ color: #dc2626 !important;
595
  }
596
  """
597
 
598
  def process_chat_message(message, files, history):
599
+ """Process a new chat message with download support."""
600
  if not message.strip() and not files:
601
+ return history, history, "", None, ""
602
 
 
603
  if history is None:
604
  history = []
605
 
606
  user_msg = message
607
  if files:
608
  file_names = [os.path.basename(f.name) for f in files]
609
+ user_msg += f" πŸ“ *[Files: {', '.join(file_names)}]*"
610
 
611
+ # Get AI response with potential download file
612
+ ai_response, download_file = copilot.process_message(message, files, history)
 
613
 
614
+ # Add to history
615
+ history.append([user_msg, ai_response])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
616
 
617
+ # Return download file info
618
+ download_info = ""
619
+ if download_file:
620
+ download_info = "πŸ“₯ **Code generated successfully!** Download button available below."
621
 
622
+ return history, history, "", download_file, download_info
 
 
 
 
 
 
 
 
 
 
 
 
623
 
624
  def clear_chat():
625
  """Clear the chat history."""
626
+ return [], [], None, ""
627
+
628
+ def quick_action(action_text):
629
+ """Handle quick action buttons."""
630
+ return action_text
 
 
 
 
 
 
 
631
 
632
  # Create the main interface
633
+ with gr.Blocks(css=professional_css, title="Coding Copilot Pro", theme=gr.themes.Base()) as app:
634
+
635
  # Header
636
  gr.HTML("""
637
  <div class="header-container">
638
+ <h1 class="header-title">⚑ CODING COPILOT PRO</h1>
639
+ <p class="header-subtitle">Advanced AI-Powered Development Assistant β€’ Powered by Claude 3 Haiku</p>
640
  </div>
641
  """)
642
 
643
+ # Main interface
644
+ with gr.Row(equal_height=True):
645
+ # Sidebar
646
+ with gr.Column(scale=1, min_width=300):
647
+ gr.HTML('<div class="sidebar">')
648
+
649
+ gr.HTML('<h3 class="sidebar-title">πŸš€ CAPABILITIES</h3>')
650
  gr.Markdown("""
651
+ <div class="sidebar-content">
652
+
653
+ **πŸ’» Code Generation:**
654
+ β€’ Complete applications & modules
655
+ β€’ Production-ready implementations
656
+ β€’ Custom algorithms & data structures
657
+ β€’ API integrations & web services
658
+
659
+ **πŸ”§ Code Analysis:**
660
+ β€’ Comprehensive code reviews
661
+ β€’ Performance optimization
662
+ β€’ Security vulnerability detection
663
+ β€’ Architecture recommendations
664
+
665
+ **πŸ› Debugging & Testing:**
666
+ β€’ Error detection & fixes
667
+ β€’ Unit test generation
668
+ β€’ Code refactoring
669
+ β€’ Best practices enforcement
670
 
671
+ **πŸ“š Documentation:**
672
+ β€’ Comprehensive docstrings
673
+ β€’ API documentation
674
+ β€’ Code explanations
675
+ β€’ Technical specifications
676
 
677
+ </div>
678
+ """, elem_classes=["sidebar-content"])
 
 
 
 
 
679
 
680
+ gr.HTML('<h3 class="sidebar-title">⚑ QUICK ACTIONS</h3>')
 
 
 
 
 
681
 
 
 
682
  with gr.Column():
683
+ quick_review = gr.Button("πŸ“‹ COMPREHENSIVE REVIEW", elem_classes=["quick-action-button"])
684
+ quick_debug = gr.Button("πŸ› DEBUG & FIX", elem_classes=["quick-action-button"])
685
+ quick_optimize = gr.Button("⚑ OPTIMIZE CODE", elem_classes=["quick-action-button"])
686
+ quick_explain = gr.Button("πŸ“– EXPLAIN & DOCUMENT", elem_classes=["quick-action-button"])
687
+ quick_generate = gr.Button("πŸ”₯ GENERATE NEW CODE", elem_classes=["quick-action-button"])
688
+ quick_test = gr.Button("πŸ§ͺ CREATE TESTS", elem_classes=["quick-action-button"])
689
+
690
+ gr.HTML('</div>')
691
 
692
+ # Main chat area
693
  with gr.Column(scale=3):
694
+ gr.HTML('<div class="main-container">')
695
+
696
  # Chat interface
697
  chatbot = gr.Chatbot(
698
+ height=600,
699
  show_label=False,
700
+ container=False,
701
  bubble_full_width=False,
702
+ avatar_images=("πŸ‘¨β€πŸ’»", "πŸ€–"),
703
+ elem_classes=["chat-container"]
704
  )
705
 
706
+ # Download section
707
+ download_status = gr.HTML("", visible=True)
708
+ download_file = gr.File(label="πŸ“₯ Download Generated Code", visible=False)
709
+
710
+ # Input section
711
+ gr.HTML('<div class="input-section">')
712
+
713
+ # File upload
714
  with gr.Row():
715
+ files = gr.File(
716
+ label="πŸ“Ž Upload Code Files (.py, .ipynb)",
717
+ file_count="multiple",
718
+ file_types=[".py", ".ipynb"],
719
+ elem_classes=["file-upload"]
720
+ )
721
+
722
+ # Message input and buttons
723
+ with gr.Row(elem_classes=["input-row"]):
724
+ msg = gr.Textbox(
725
+ label="",
726
+ placeholder="Describe what you want to build, analyze, or improve... Type 'continue' to extend previous code.",
727
+ show_label=False,
728
+ lines=2,
729
+ max_lines=4,
730
+ scale=4,
731
+ elem_classes=["message-input"]
732
+ )
 
733
 
734
+ with gr.Column(scale=1):
735
+ submit = gr.Button("SEND", variant="primary", elem_classes=["primary-button"])
736
+ clear = gr.Button("CLEAR", variant="secondary", elem_classes=["secondary-button"])
737
+
738
+ gr.HTML('</div>')
739
+ gr.HTML('</div>')
740
 
741
+ # Hidden state
742
  chat_history = gr.State([])
743
 
744
  # Event handlers
745
+ def handle_submit(message, files, history):
746
+ result = process_chat_message(message, files, history)
747
+ return result
748
+
749
+ # Quick actions
750
+ quick_review.click(
751
+ lambda: "Please perform a comprehensive code review of the uploaded files. Analyze code quality, identify potential bugs, suggest performance improvements, check for security vulnerabilities, and provide detailed recommendations with examples.",
752
+ outputs=msg
753
+ )
754
+
755
+ quick_debug.click(
756
+ lambda: "Please debug the uploaded code thoroughly. Identify any errors, bugs, logical issues, or potential runtime problems. Provide detailed explanations and complete fixed versions of the code.",
757
+ outputs=msg
758
+ )
759
+
760
+ quick_optimize.click(
761
+ lambda: "Please optimize the uploaded code for better performance, memory usage, and readability. Provide the complete optimized version with explanations of the improvements made.",
762
+ outputs=msg
763
+ )
764
 
765
+ quick_explain.click(
766
+ lambda: "Please provide a detailed explanation of the uploaded code. Break down its functionality, explain the algorithms used, document all functions and classes, and create comprehensive documentation.",
767
+ outputs=msg
768
+ )
 
769
 
770
+ quick_generate.click(
771
+ lambda: "Please generate a complete, production-ready application based on the requirements. Include all necessary components, error handling, documentation, and best practices.",
772
+ outputs=msg
773
+ )
 
774
 
775
+ quick_test.click(
776
+ lambda: "Please create comprehensive unit tests for the uploaded code. Include test cases for all functions, edge cases, error handling, and integration tests where applicable.",
777
+ outputs=msg
778
+ )
779
+
780
+ # Main functionality
781
  submit.click(
782
+ handle_submit,
783
  inputs=[msg, files, chat_history],
784
+ outputs=[chatbot, chat_history, msg, download_file, download_status]
785
  ).then(
786
+ lambda: None,
787
+ outputs=files
788
  )
789
 
 
790
  msg.submit(
791
+ handle_submit,
792
  inputs=[msg, files, chat_history],
793
+ outputs=[chatbot, chat_history, msg, download_file, download_status]
794
  ).then(
795
+ lambda: None,
796
+ outputs=files
797
  )
798
 
799
+ clear.click(
800
+ clear_chat,
801
+ outputs=[chatbot, chat_history, download_file, download_status]
802
+ )
803
 
804
  # Footer
805
  gr.HTML("""
806
+ <div class="footer">
807
+ <p><strong>CODING COPILOT PRO</strong> β€’ Professional Development Assistant</p>
808
+ <p>Upload your code files and start building β€’ Advanced AI β€’ Secure & Private</p>
809
  </div>
810
  """)
811
 
 
816
  server_port=7860,
817
  share=True,
818
  show_error=True,
819
+ show_api=False,
820
+ inbrowser=True
821
  )