prernajeet14 commited on
Commit
3b8f432
·
verified ·
1 Parent(s): 58d315d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -396
app.py CHANGED
@@ -1,33 +1,3 @@
1
- import gradio as gr
2
- import boto3
3
- import json
4
- import os
5
- from typing import Optional, Tuple, List
6
- import nbformat
7
- from io import StringIO
8
- import sys
9
- import tempfile
10
- import zipfile
11
- from datetime import datetime
12
- import re
13
-
14
- class CodingCopilot:
15
- def __init__(self):
16
- """Initialize the coding copilot with AWS Bedrock client."""
17
- self.setup_aws_client()
18
-
19
- def setup_aws_client(self):
20
- """Setup AWS Bedrock client with credentials from environment variables."""
21
- try:
22
- self.bedrock_client = boto3.client(
23
- 'bedrock-runtime',
24
- aws_access_key_id=os.getenv('AWS_ACCESS_KEY_ID'),
25
- aws_secret_access_key=os.getenv('AWS_SECRET_ACCESS_KEY'),
26
- region_name='us-east-1'
27
- )
28
- except Exception as e:
29
- print(f"Error setting up AWS client: {e}")
30
- self.bedrock_client = None
31
 
32
  def call_claude(self, prompt: str, max_tokens: int = 8000) -> str:
33
  """Call Claude 3 Haiku via AWS Bedrock with increased token limit."""
@@ -360,378 +330,12 @@ desktop_css = """
360
  color: #dc2626 !important;
361
  font-weight: 700 !important;
362
  font-size: 1.1rem !important;
363
- margin-bottom: 1rem !important;
364
- text-transform: uppercase !important;
365
- letter-spacing: 0.5px !important;
366
- display: flex !important;
367
- align-items: center !important;
368
- gap: 0.5rem !important;
369
- }
370
 
371
- .capabilities-list {
372
- color: #d1d5db !important;
373
- font-size: 0.85rem !important;
374
- line-height: 1.5 !important;
375
- }
376
 
377
- .capabilities-list strong {
378
- color: #ffffff !important;
379
- display: block !important;
380
- margin-bottom: 0.3rem !important;
381
- }
382
 
383
- .capability-item {
384
- margin-bottom: 1rem !important;
385
- padding: 0.5rem 0 !important;
386
- border-bottom: 1px solid #262626 !important;
387
- }
388
 
389
- .capability-item:last-child {
390
- border-bottom: none !important;
391
- }
392
-
393
- /* Quick Action Buttons */
394
- .quick-action-button {
395
- background: #1a1a1a !important;
396
- color: #dc2626 !important;
397
- border: 1px solid #dc2626 !important;
398
- border-radius: 8px !important;
399
- padding: 0.6rem 0.8rem !important;
400
- font-weight: 500 !important;
401
- cursor: pointer !important;
402
- transition: all 0.3s ease !important;
403
- margin-bottom: 0.4rem !important;
404
- width: 100% !important;
405
- text-align: left !important;
406
- font-size: 0.8rem !important;
407
- display: flex !important;
408
- align-items: center !important;
409
- gap: 0.4rem !important;
410
- }
411
-
412
- .quick-action-button:hover {
413
- background: #dc2626 !important;
414
- color: #ffffff !important;
415
- transform: translateX(3px) !important;
416
- box-shadow: 0 4px 12px rgba(220, 38, 38, 0.2) !important;
417
- }
418
-
419
- /* Chat Container Layout */
420
- .chat-main {
421
- flex: 1 !important;
422
- display: flex !important;
423
- flex-direction: column !important;
424
- height: 100% !important;
425
- overflow: hidden !important;
426
- }
427
 
428
- .chat-messages {
429
- flex: 1 !important;
430
- overflow-y: auto !important;
431
- padding: 1rem !important;
432
- height: 0 !important; /* Force flex child to respect parent height */
433
- }
434
-
435
- .chat-input-area {
436
- flex-shrink: 0 !important;
437
- background: #1a1a1a !important;
438
- border-top: 1px solid #262626 !important;
439
- padding: 1rem !important;
440
- }
441
-
442
- /* File Upload Styling */
443
- .file-upload-area {
444
- background: #1a1a1a !important;
445
- border: 1px dashed #404040 !important;
446
- border-radius: 8px !important;
447
- padding: 0.8rem !important;
448
- margin-bottom: 1rem !important;
449
- transition: all 0.3s ease !important;
450
- }
451
-
452
- .file-upload-area:hover {
453
- border-color: #dc2626 !important;
454
- background: #262626 !important;
455
- }
456
-
457
- /* Input Styling */
458
- .message-input {
459
- background: #262626 !important;
460
- border: 1px solid #404040 !important;
461
- border-radius: 8px !important;
462
- color: #ffffff !important;
463
- padding: 0.75rem !important;
464
- font-size: 0.9rem !important;
465
- line-height: 1.4 !important;
466
- resize: vertical !important;
467
- transition: all 0.3s ease !important;
468
- width: 100% !important;
469
- margin-bottom: 0.8rem !important;
470
- }
471
-
472
- .message-input:focus {
473
- outline: none !important;
474
- border-color: #dc2626 !important;
475
- box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.1) !important;
476
- }
477
-
478
- .message-input::placeholder {
479
- color: #6b7280 !important;
480
- }
481
-
482
- /* Button Row */
483
- .button-row {
484
- display: flex !important;
485
- gap: 0.75rem !important;
486
- align-items: center !important;
487
- justify-content: flex-end !important;
488
- }
489
-
490
- /* Buttons */
491
- .primary-button {
492
- background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%) !important;
493
- color: white !important;
494
- border: none !important;
495
- border-radius: 8px !important;
496
- padding: 0.7rem 1.2rem !important;
497
- font-weight: 600 !important;
498
- font-size: 0.85rem !important;
499
- cursor: pointer !important;
500
- transition: all 0.3s ease !important;
501
- box-shadow: 0 4px 16px rgba(220, 38, 38, 0.2) !important;
502
- text-transform: uppercase !important;
503
- letter-spacing: 0.5px !important;
504
- min-width: 70px !important;
505
- }
506
-
507
- .primary-button:hover {
508
- background: linear-gradient(135deg, #b91c1c 0%, #991b1b 100%) !important;
509
- transform: translateY(-1px) !important;
510
- box-shadow: 0 6px 20px rgba(220, 38, 38, 0.3) !important;
511
- }
512
 
513
- .secondary-button {
514
- background: #262626 !important;
515
- color: #ffffff !important;
516
- border: 1px solid #404040 !important;
517
- border-radius: 8px !important;
518
- padding: 0.7rem 1.2rem !important;
519
- font-weight: 500 !important;
520
- cursor: pointer !important;
521
- transition: all 0.3s ease !important;
522
- text-transform: uppercase !important;
523
- letter-spacing: 0.5px !important;
524
- font-size: 0.85rem !important;
525
- min-width: 70px !important;
526
- }
527
-
528
- .secondary-button:hover {
529
- background: #404040 !important;
530
- border-color: #dc2626 !important;
531
- }
532
-
533
- /* Download Section */
534
- .download-section {
535
- background: #1a1a1a !important;
536
- border: 1px solid #dc2626 !important;
537
- border-radius: 8px !important;
538
- padding: 0.8rem !important;
539
- margin-bottom: 1rem !important;
540
- }
541
-
542
- /* Scrollbar */
543
- ::-webkit-scrollbar {
544
- width: 4px !important;
545
- height: 4px !important;
546
- }
547
-
548
- ::-webkit-scrollbar-track {
549
- background: #1a1a1a !important;
550
- }
551
-
552
- ::-webkit-scrollbar-thumb {
553
- background: #404040 !important;
554
- border-radius: 2px !important;
555
- }
556
-
557
- ::-webkit-scrollbar-thumb:hover {
558
- background: #dc2626 !important;
559
- }
560
-
561
- /* Force no mobile responsiveness for desktop view */
562
- @media (min-width: 1px) {
563
- .desktop-layout {
564
- flex-direction: row !important;
565
- }
566
-
567
- .desktop-sidebar {
568
- width: 320px !important;
569
- min-width: 320px !important;
570
- max-width: 320px !important;
571
- }
572
-
573
- .desktop-chat {
574
- flex: 1 !important;
575
- }
576
- }
577
-
578
- /* Footer */
579
- .footer {
580
- background: #0a0a0a !important;
581
- border-top: 1px solid #262626 !important;
582
- padding: 1rem !important;
583
- text-align: center !important;
584
- color: #6b7280 !important;
585
- margin-top: 1rem !important;
586
- border-radius: 8px !important;
587
- font-size: 0.8rem !important;
588
- }
589
-
590
- .footer strong {
591
- color: #dc2626 !important;
592
- }
593
-
594
- /* Override any Gradio responsive behavior */
595
- .gradio-container .block {
596
- width: auto !important;
597
- }
598
-
599
- .gradio-container .contain {
600
- padding: 0 !important;
601
- }
602
- """
603
-
604
- def process_chat_message(message, files, history):
605
- """Process a new chat message with download support."""
606
- if not message.strip() and not files:
607
- return history, history, "", None, ""
608
-
609
- if history is None:
610
- history = []
611
-
612
- user_msg = message
613
- if files:
614
- file_names = [os.path.basename(f.name) for f in files]
615
- user_msg += f" 📁 *[Files: {', '.join(file_names)}]*"
616
-
617
- # Get AI response with potential download file
618
- ai_response, download_file = copilot.process_message(message, files, history)
619
-
620
- # Add to history
621
- history.append([user_msg, ai_response])
622
-
623
- # Return download file info
624
- download_info = ""
625
- if download_file:
626
- download_info = "📥 **Code generated successfully!** Download button available below."
627
-
628
- return history, history, "", download_file, download_info
629
-
630
- def clear_chat():
631
- """Clear the chat history."""
632
- return [], [], None, ""
633
-
634
- def quick_action(action_text):
635
- """Handle quick action buttons."""
636
- return action_text
637
-
638
- # Create the main interface with FORCED desktop layout
639
- with gr.Blocks(css=desktop_css, title="Coding Copilot Pro - Desktop", theme=gr.themes.Base()) as app:
640
-
641
- # Header
642
- gr.HTML("""
643
- <div class="header-container">
644
- <h1 class="header-title">🚀 CODING COPILOT PRO</h1>
645
- <p class="header-subtitle">Advanced AI-Powered Development Assistant • Powered by Claude 3 Haiku</p>
646
- </div>
647
- """)
648
-
649
- # FORCE Desktop Layout - Critical Structure
650
- with gr.Row(elem_classes=["desktop-layout"]):
651
-
652
- # Left Sidebar - FORCED width and position
653
- with gr.Column(elem_classes=["desktop-sidebar"], scale=0, min_width=320):
654
-
655
- # Capabilities Section
656
- gr.HTML('<h3 class="sidebar-title"><span class="emoji-icon">🎯</span>CAPABILITIES</h3>')
657
-
658
- gr.HTML("""
659
- <div class="capabilities-list">
660
- <div class="capability-item">
661
- <strong>💻 Code Generation</strong>
662
- Complete applications, modules, algorithms & APIs
663
- </div>
664
- <div class="capability-item">
665
- <strong>🔍 Code Analysis</strong>
666
- Reviews, optimization, security & architecture
667
- </div>
668
- <div class="capability-item">
669
- <strong>🐛 Debug & Test</strong>
670
- Error fixes, unit tests & refactoring
671
- </div>
672
- <div class="capability-item">
673
- <strong>📚 Documentation</strong>
674
- Docstrings, API docs & explanations
675
- </div>
676
- </div>
677
- """)
678
-
679
- # Quick Actions Section
680
- gr.HTML('<h3 class="sidebar-title"><span class="emoji-icon">⚡</span>QUICK ACTIONS</h3>')
681
-
682
- quick_review = gr.Button("📋 Code Review", elem_classes=["quick-action-button"])
683
- quick_debug = gr.Button("🐛 Debug & Fix", elem_classes=["quick-action-button"])
684
- quick_optimize = gr.Button("⚡ Optimize", elem_classes=["quick-action-button"])
685
- quick_explain = gr.Button("📖 Explain", elem_classes=["quick-action-button"])
686
- quick_generate = gr.Button("🔥 Generate", elem_classes=["quick-action-button"])
687
- quick_test = gr.Button("🧪 Create Tests", elem_classes=["quick-action-button"])
688
-
689
- # Right Chat Container - FORCED to take remaining space
690
- with gr.Column(elem_classes=["desktop-chat"], scale=1):
691
-
692
- with gr.Column(elem_classes=["chat-main"]):
693
- # Chat messages area
694
- chatbot = gr.Chatbot(
695
- height=400,
696
- show_label=False,
697
- container=False,
698
- bubble_full_width=False,
699
- avatar_images=("👨‍💻", "🤖"),
700
- elem_classes=["chat-messages"]
701
- )
702
-
703
- # Input area at bottom
704
- with gr.Column(elem_classes=["chat-input-area"]):
705
- # File upload
706
- files = gr.File(
707
- label="📎 Upload Code Files (.py, .ipynb)",
708
- file_count="multiple",
709
- file_types=[".py", ".ipynb"],
710
- container=True,
711
- elem_classes=["file-upload-area"]
712
- )
713
-
714
- # Download status
715
- download_status = gr.HTML("", visible=True)
716
- download_file = gr.File(label="📥 Download Generated Code", visible=False)
717
-
718
- # Message input
719
- msg = gr.Textbox(
720
- label="",
721
- placeholder="Describe what you want to build, analyze, or improve... Type 'continue' to extend previous code.",
722
- show_label=False,
723
- lines=2,
724
- max_lines=4,
725
- elem_classes=["message-input"]
726
- )
727
-
728
- # Button row
729
- with gr.Row(elem_classes=["button-row"]):
730
- clear = gr.Button("CLEAR", variant="secondary", elem_classes=["secondary-button"])
731
- submit = gr.Button("SEND", variant="primary", elem_classes=["primary-button"])
732
-
733
- # Hidden state
734
- chat_history = gr.State([])
735
 
736
  # Event handlers
737
  def handle_submit(message, files, history):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
 
2
  def call_claude(self, prompt: str, max_tokens: int = 8000) -> str:
3
  """Call Claude 3 Haiku via AWS Bedrock with increased token limit."""
 
330
  color: #dc2626 !important;
331
  font-weight: 700 !important;
332
  font-size: 1.1rem !important;
 
 
 
 
 
 
 
333
 
 
 
 
 
 
334
 
 
 
 
 
 
335
 
 
 
 
 
 
336
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
337
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
338
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
339
 
340
  # Event handlers
341
  def handle_submit(message, files, history):