prernajeet14 commited on
Commit
bd83490
Β·
verified Β·
1 Parent(s): b7a9d4b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -96
app.py CHANGED
@@ -251,7 +251,7 @@ Provide a thorough and helpful response. If suggesting code changes, provide com
251
  # Initialize the copilot
252
  copilot = CodingCopilot()
253
 
254
- # COMPLETELY FIXED CSS - Proper scrolling and visibility
255
  fixed_css = """
256
  /* Reset and base styles */
257
  * {
@@ -261,13 +261,11 @@ fixed_css = """
261
  .gradio-container {
262
  max-width: none !important;
263
  width: 100% !important;
264
- height: 100vh !important;
265
- max-height: 100vh !important;
266
  background: #0a0a0a !important;
267
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif !important;
268
  color: #ffffff !important;
269
  padding: 1rem !important;
270
- overflow: hidden !important;
271
  }
272
 
273
  /* Header */
@@ -279,7 +277,6 @@ fixed_css = """
279
  margin-bottom: 1rem !important;
280
  box-shadow: 0 8px 32px rgba(220, 38, 38, 0.15) !important;
281
  text-align: center !important;
282
- flex-shrink: 0 !important;
283
  }
284
 
285
  .header-title {
@@ -300,19 +297,16 @@ fixed_css = """
300
  font-weight: 400 !important;
301
  }
302
 
303
- /* Main layout - FIXED with stable height */
304
  .main-layout {
305
  display: flex !important;
306
  flex-direction: row !important;
307
  gap: 1.5rem !important;
308
  width: 100% !important;
309
- height: calc(100vh - 200px) !important;
310
- max-height: calc(100vh - 200px) !important;
311
  min-height: calc(100vh - 200px) !important;
312
- flex-shrink: 0 !important;
313
  }
314
 
315
- /* Sidebar - FIXED width and scrolling */
316
  .sidebar {
317
  background: linear-gradient(180deg, #1a1a1a 0%, #0f0f0f 100%) !important;
318
  border: 1px solid #dc2626 !important;
@@ -321,14 +315,13 @@ fixed_css = """
321
  width: 320px !important;
322
  min-width: 320px !important;
323
  max-width: 320px !important;
324
- height: 100% !important;
325
- max-height: 100% !important;
326
- flex-shrink: 0 !important;
327
  box-shadow: 0 8px 32px rgba(220, 38, 38, 0.1) !important;
328
  overflow-y: auto !important;
 
 
329
  }
330
 
331
- /* Chat area - FIXED with stable height */
332
  .chat-area {
333
  background: linear-gradient(180deg, #111111 0%, #0a0a0a 100%) !important;
334
  border: 1px solid #262626 !important;
@@ -336,36 +329,26 @@ fixed_css = """
336
  flex: 1 !important;
337
  display: flex !important;
338
  flex-direction: column !important;
339
- overflow: hidden !important;
340
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3) !important;
341
- height: 100% !important;
342
- max-height: 100% !important;
343
- min-height: 100% !important;
344
  }
345
 
346
- /* Chat content area - FIXED height */
347
  .chat-content {
348
  flex: 1 !important;
349
- overflow-y: auto !important;
350
  padding: 1.5rem !important;
351
- height: calc(100% - 280px) !important;
352
- max-height: calc(100% - 280px) !important;
353
- min-height: 300px !important;
354
  }
355
 
356
- /* Input section - FIXED height to prevent movement */
357
  .input-section {
358
- flex-shrink: 0 !important;
359
  background: #1a1a1a !important;
360
  border-top: 1px solid #262626 !important;
361
  padding: 1.5rem !important;
362
- display: flex !important;
363
- flex-direction: column !important;
364
- gap: 1rem !important;
365
- height: 280px !important;
366
- max-height: 280px !important;
367
- min-height: 280px !important;
368
- overflow-y: auto !important;
369
  }
370
 
371
  /* Quick Actions */
@@ -442,7 +425,6 @@ fixed_css = """
442
  border-radius: 8px !important;
443
  padding: 1rem !important;
444
  margin-bottom: 1rem !important;
445
- flex-shrink: 0 !important;
446
  }
447
 
448
  /* File upload */
@@ -453,8 +435,6 @@ fixed_css = """
453
  padding: 1rem !important;
454
  margin-bottom: 1rem !important;
455
  transition: all 0.3s ease !important;
456
- width: 100% !important;
457
- flex-shrink: 0 !important;
458
  }
459
 
460
  .file-upload:hover {
@@ -462,7 +442,7 @@ fixed_css = """
462
  background: #262626 !important;
463
  }
464
 
465
- /* Message input - FIXED size */
466
  .msg-input {
467
  background: #262626 !important;
468
  border: 1px solid #404040 !important;
@@ -475,10 +455,7 @@ fixed_css = """
475
  transition: all 0.3s ease !important;
476
  width: 100% !important;
477
  margin-bottom: 1rem !important;
478
- height: 80px !important;
479
- max-height: 120px !important;
480
- min-height: 60px !important;
481
- flex-shrink: 0 !important;
482
  }
483
 
484
  .msg-input:focus {
@@ -491,13 +468,12 @@ fixed_css = """
491
  color: #6b7280 !important;
492
  }
493
 
494
- /* Buttons - FIXED positioning */
495
  .btn-row {
496
  display: flex !important;
497
  gap: 1rem !important;
498
  align-items: center !important;
499
  justify-content: flex-end !important;
500
- flex-shrink: 0 !important;
501
  }
502
 
503
  .btn-primary {
@@ -514,7 +490,6 @@ fixed_css = """
514
  text-transform: uppercase !important;
515
  letter-spacing: 0.5px !important;
516
  min-width: 80px !important;
517
- flex-shrink: 0 !important;
518
  }
519
 
520
  .btn-primary:hover {
@@ -536,7 +511,6 @@ fixed_css = """
536
  letter-spacing: 0.5px !important;
537
  font-size: 0.9rem !important;
538
  min-width: 80px !important;
539
- flex-shrink: 0 !important;
540
  }
541
 
542
  .btn-secondary:hover {
@@ -544,18 +518,15 @@ fixed_css = """
544
  border-color: #dc2626 !important;
545
  }
546
 
547
- /* Chatbot - FIXED container */
548
  .chatbot-container {
549
- height: 100% !important;
550
- min-height: 100% !important;
551
- max-height: 100% !important;
552
  border: none !important;
553
  background: transparent !important;
554
  overflow-y: auto !important;
555
  scroll-behavior: smooth !important;
556
  }
557
 
558
- /* Footer - FIXED positioning */
559
  .footer {
560
  background: #0a0a0a !important;
561
  border-top: 1px solid #262626 !important;
@@ -564,8 +535,7 @@ fixed_css = """
564
  color: #6b7280 !important;
565
  border-radius: 8px !important;
566
  font-size: 0.8rem !important;
567
- flex-shrink: 0 !important;
568
- margin-top: auto !important;
569
  }
570
 
571
  .footer strong {
@@ -609,38 +579,26 @@ code {
609
  font-size: 0.85rem !important;
610
  }
611
 
612
- /* Ensure all elements are visible */
613
- .gradio-container * {
614
- visibility: visible !important;
615
- opacity: 1 !important;
616
- }
617
-
618
  /* Responsive design */
619
  @media (max-width: 768px) {
620
  .main-layout {
621
  flex-direction: column !important;
622
- height: calc(100vh - 150px) !important;
623
- max-height: calc(100vh - 150px) !important;
624
  }
625
 
626
  .sidebar {
627
  width: 100% !important;
628
  max-width: none !important;
629
  min-width: auto !important;
630
- height: 300px !important;
631
- max-height: 300px !important;
632
- }
633
-
634
- .chat-area {
635
- height: calc(100% - 340px) !important;
636
- max-height: calc(100% - 340px) !important;
637
  }
638
 
639
  .header-title {
640
  font-size: 1.8rem !important;
641
  }
642
- }
643
  """
 
644
  def process_chat_message(message, files, history):
645
  """Process a new chat message with download support."""
646
  if not message.strip() and not files:
@@ -663,7 +621,7 @@ def process_chat_message(message, files, history):
663
  # Return download file info
664
  download_info = ""
665
  if download_file:
666
- download_info = "πŸ“₯ **Code generated successfully!** Download button available below."
667
 
668
  return history, history, "", download_file, download_info
669
 
@@ -671,12 +629,23 @@ def clear_chat():
671
  """Clear the chat history."""
672
  return [], [], None, ""
673
 
674
- def quick_action(action_text):
675
- """Handle quick action buttons."""
676
- return action_text
 
 
 
 
 
 
 
 
 
 
 
677
 
678
- # Create the main interface with COMPLETELY FIXED layout
679
- with gr.Blocks(css=fixed_css, title="Coding Copilot Pro - Desktop", theme=gr.themes.Base()) as app:
680
 
681
  # Header
682
  gr.HTML("""
@@ -686,10 +655,10 @@ with gr.Blocks(css=fixed_css, title="Coding Copilot Pro - Desktop", theme=gr.the
686
  </div>
687
  """)
688
 
689
- # Main content container - COMPLETELY FIXED
690
  with gr.Row(elem_classes=["main-layout"]):
691
 
692
- # Left Sidebar - FIXED
693
  with gr.Column(elem_classes=["sidebar"], scale=0):
694
 
695
  # Quick Actions Section
@@ -728,10 +697,10 @@ with gr.Blocks(css=fixed_css, title="Coding Copilot Pro - Desktop", theme=gr.the
728
  </div>
729
  """)
730
 
731
- # Right Chat Container - COMPLETELY FIXED
732
  with gr.Column(elem_classes=["chat-area"], scale=1):
733
 
734
- # Chat Messages Area - FIXED
735
  with gr.Column(elem_classes=["chat-content"]):
736
  chatbot = gr.Chatbot(
737
  height=400,
@@ -741,18 +710,22 @@ with gr.Blocks(css=fixed_css, title="Coding Copilot Pro - Desktop", theme=gr.the
741
  elem_classes=["chatbot-container"]
742
  )
743
 
744
- # Input Section - COMPLETELY FIXED AND VISIBLE
745
  with gr.Column(elem_classes=["input-section"]):
746
 
747
- # Download section
748
- download_status = gr.HTML("", elem_classes=["download-section"])
749
- download_file = gr.File(
750
- label="πŸ“₯ Download Generated Code",
751
- visible=False,
752
- elem_classes=["download-section"]
753
- )
754
 
755
- # File upload - FIXED
 
 
 
 
 
 
 
 
756
  files = gr.File(
757
  label="πŸ“Ž Upload Code Files (.py, .ipynb)",
758
  file_count="multiple",
@@ -760,17 +733,17 @@ with gr.Blocks(css=fixed_css, title="Coding Copilot Pro - Desktop", theme=gr.the
760
  elem_classes=["file-upload"]
761
  )
762
 
763
- # Message input - FIXED
764
  msg = gr.Textbox(
765
- label="",
766
  placeholder="Describe what you want to build, analyze, or improve... Type 'continue' to extend previous code.",
767
- show_label=False,
768
- lines=3,
769
- max_lines=6,
770
  elem_classes=["msg-input"]
771
  )
772
 
773
- # Button row - FIXED
774
  with gr.Row(elem_classes=["btn-row"]):
775
  clear = gr.Button(
776
  "CLEAR",
@@ -791,7 +764,7 @@ with gr.Blocks(css=fixed_css, title="Coding Copilot Pro - Desktop", theme=gr.the
791
  result = process_chat_message(message, files, history)
792
  return result
793
 
794
- # Quick actions - ALL WORKING
795
  quick_generate.click(
796
  lambda: "Please generate a complete, production-ready application based on the requirements. Include all necessary components, error handling, documentation, and best practices.",
797
  outputs=msg
@@ -822,13 +795,13 @@ with gr.Blocks(css=fixed_css, title="Coding Copilot Pro - Desktop", theme=gr.the
822
  outputs=msg
823
  )
824
 
825
- # Main chat functionality - ALL WORKING
826
  submit.click(
827
  handle_submit,
828
  inputs=[msg, files, chat_history],
829
  outputs=[chatbot, chat_history, msg, download_file, download_status]
830
  ).then(
831
- lambda: None,
832
  outputs=files
833
  )
834
 
@@ -837,7 +810,7 @@ with gr.Blocks(css=fixed_css, title="Coding Copilot Pro - Desktop", theme=gr.the
837
  inputs=[msg, files, chat_history],
838
  outputs=[chatbot, chat_history, msg, download_file, download_status]
839
  ).then(
840
- lambda: None,
841
  outputs=files
842
  )
843
 
 
251
  # Initialize the copilot
252
  copilot = CodingCopilot()
253
 
254
+ # FIXED CSS - Proper layout and visible input area
255
  fixed_css = """
256
  /* Reset and base styles */
257
  * {
 
261
  .gradio-container {
262
  max-width: none !important;
263
  width: 100% !important;
 
 
264
  background: #0a0a0a !important;
265
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif !important;
266
  color: #ffffff !important;
267
  padding: 1rem !important;
268
+ min-height: 100vh !important;
269
  }
270
 
271
  /* Header */
 
277
  margin-bottom: 1rem !important;
278
  box-shadow: 0 8px 32px rgba(220, 38, 38, 0.15) !important;
279
  text-align: center !important;
 
280
  }
281
 
282
  .header-title {
 
297
  font-weight: 400 !important;
298
  }
299
 
300
+ /* Main layout */
301
  .main-layout {
302
  display: flex !important;
303
  flex-direction: row !important;
304
  gap: 1.5rem !important;
305
  width: 100% !important;
 
 
306
  min-height: calc(100vh - 200px) !important;
 
307
  }
308
 
309
+ /* Sidebar */
310
  .sidebar {
311
  background: linear-gradient(180deg, #1a1a1a 0%, #0f0f0f 100%) !important;
312
  border: 1px solid #dc2626 !important;
 
315
  width: 320px !important;
316
  min-width: 320px !important;
317
  max-width: 320px !important;
 
 
 
318
  box-shadow: 0 8px 32px rgba(220, 38, 38, 0.1) !important;
319
  overflow-y: auto !important;
320
+ height: fit-content !important;
321
+ max-height: calc(100vh - 200px) !important;
322
  }
323
 
324
+ /* Chat area */
325
  .chat-area {
326
  background: linear-gradient(180deg, #111111 0%, #0a0a0a 100%) !important;
327
  border: 1px solid #262626 !important;
 
329
  flex: 1 !important;
330
  display: flex !important;
331
  flex-direction: column !important;
 
332
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3) !important;
333
+ min-height: 600px !important;
 
 
334
  }
335
 
336
+ /* Chat content area */
337
  .chat-content {
338
  flex: 1 !important;
 
339
  padding: 1.5rem !important;
340
+ overflow-y: auto !important;
341
+ min-height: 400px !important;
342
+ max-height: 500px !important;
343
  }
344
 
345
+ /* Input section - FIXED to be visible */
346
  .input-section {
 
347
  background: #1a1a1a !important;
348
  border-top: 1px solid #262626 !important;
349
  padding: 1.5rem !important;
350
+ border-radius: 0 0 16px 16px !important;
351
+ min-height: 300px !important;
 
 
 
 
 
352
  }
353
 
354
  /* Quick Actions */
 
425
  border-radius: 8px !important;
426
  padding: 1rem !important;
427
  margin-bottom: 1rem !important;
 
428
  }
429
 
430
  /* File upload */
 
435
  padding: 1rem !important;
436
  margin-bottom: 1rem !important;
437
  transition: all 0.3s ease !important;
 
 
438
  }
439
 
440
  .file-upload:hover {
 
442
  background: #262626 !important;
443
  }
444
 
445
+ /* Message input */
446
  .msg-input {
447
  background: #262626 !important;
448
  border: 1px solid #404040 !important;
 
455
  transition: all 0.3s ease !important;
456
  width: 100% !important;
457
  margin-bottom: 1rem !important;
458
+ min-height: 100px !important;
 
 
 
459
  }
460
 
461
  .msg-input:focus {
 
468
  color: #6b7280 !important;
469
  }
470
 
471
+ /* Button row */
472
  .btn-row {
473
  display: flex !important;
474
  gap: 1rem !important;
475
  align-items: center !important;
476
  justify-content: flex-end !important;
 
477
  }
478
 
479
  .btn-primary {
 
490
  text-transform: uppercase !important;
491
  letter-spacing: 0.5px !important;
492
  min-width: 80px !important;
 
493
  }
494
 
495
  .btn-primary:hover {
 
511
  letter-spacing: 0.5px !important;
512
  font-size: 0.9rem !important;
513
  min-width: 80px !important;
 
514
  }
515
 
516
  .btn-secondary:hover {
 
518
  border-color: #dc2626 !important;
519
  }
520
 
521
+ /* Chatbot container */
522
  .chatbot-container {
 
 
 
523
  border: none !important;
524
  background: transparent !important;
525
  overflow-y: auto !important;
526
  scroll-behavior: smooth !important;
527
  }
528
 
529
+ /* Footer */
530
  .footer {
531
  background: #0a0a0a !important;
532
  border-top: 1px solid #262626 !important;
 
535
  color: #6b7280 !important;
536
  border-radius: 8px !important;
537
  font-size: 0.8rem !important;
538
+ margin-top: 2rem !important;
 
539
  }
540
 
541
  .footer strong {
 
579
  font-size: 0.85rem !important;
580
  }
581
 
 
 
 
 
 
 
582
  /* Responsive design */
583
  @media (max-width: 768px) {
584
  .main-layout {
585
  flex-direction: column !important;
 
 
586
  }
587
 
588
  .sidebar {
589
  width: 100% !important;
590
  max-width: none !important;
591
  min-width: auto !important;
592
+ height: auto !important;
593
+ max-height: 400px !important;
 
 
 
 
 
594
  }
595
 
596
  .header-title {
597
  font-size: 1.8rem !important;
598
  }
599
+ }
600
  """
601
+
602
  def process_chat_message(message, files, history):
603
  """Process a new chat message with download support."""
604
  if not message.strip() and not files:
 
621
  # Return download file info
622
  download_info = ""
623
  if download_file:
624
+ download_info = "πŸŽ‰ **Code generated successfully!** Click the download button below to save your code."
625
 
626
  return history, history, "", download_file, download_info
627
 
 
629
  """Clear the chat history."""
630
  return [], [], None, ""
631
 
632
+ def update_download_file(response, history):
633
+ """Update download file when new response is generated."""
634
+ if not response:
635
+ return None, ""
636
+
637
+ # Extract code blocks from the latest response
638
+ code_blocks = copilot.extract_code_blocks(response)
639
+ if code_blocks:
640
+ combined_code = "\n\n".join(code_blocks)
641
+ if len(combined_code.strip()) > 50:
642
+ download_file = copilot.create_download_file(combined_code)
643
+ return download_file, "πŸŽ‰ **Code generated!** Download available below."
644
+
645
+ return None, ""
646
 
647
+ # Create the main interface
648
+ with gr.Blocks(css=fixed_css, title="Coding Copilot Pro", theme=gr.themes.Base()) as app:
649
 
650
  # Header
651
  gr.HTML("""
 
655
  </div>
656
  """)
657
 
658
+ # Main content container
659
  with gr.Row(elem_classes=["main-layout"]):
660
 
661
+ # Left Sidebar
662
  with gr.Column(elem_classes=["sidebar"], scale=0):
663
 
664
  # Quick Actions Section
 
697
  </div>
698
  """)
699
 
700
+ # Right Chat Container
701
  with gr.Column(elem_classes=["chat-area"], scale=1):
702
 
703
+ # Chat Messages Area
704
  with gr.Column(elem_classes=["chat-content"]):
705
  chatbot = gr.Chatbot(
706
  height=400,
 
710
  elem_classes=["chatbot-container"]
711
  )
712
 
713
+ # Input Section - COMPLETELY VISIBLE NOW
714
  with gr.Column(elem_classes=["input-section"]):
715
 
716
+ # Download section - Show status and file
717
+ with gr.Row():
718
+ download_status = gr.HTML("", elem_classes=["download-section"])
 
 
 
 
719
 
720
+ with gr.Row():
721
+ download_file = gr.File(
722
+ label="πŸ“₯ Download Generated Code",
723
+ visible=True,
724
+ interactive=False,
725
+ elem_classes=["download-section"]
726
+ )
727
+
728
+ # File upload
729
  files = gr.File(
730
  label="πŸ“Ž Upload Code Files (.py, .ipynb)",
731
  file_count="multiple",
 
733
  elem_classes=["file-upload"]
734
  )
735
 
736
+ # Message input
737
  msg = gr.Textbox(
738
+ label="Your Message",
739
  placeholder="Describe what you want to build, analyze, or improve... Type 'continue' to extend previous code.",
740
+ show_label=True,
741
+ lines=4,
742
+ max_lines=8,
743
  elem_classes=["msg-input"]
744
  )
745
 
746
+ # Button row
747
  with gr.Row(elem_classes=["btn-row"]):
748
  clear = gr.Button(
749
  "CLEAR",
 
764
  result = process_chat_message(message, files, history)
765
  return result
766
 
767
+ # Quick action button handlers
768
  quick_generate.click(
769
  lambda: "Please generate a complete, production-ready application based on the requirements. Include all necessary components, error handling, documentation, and best practices.",
770
  outputs=msg
 
795
  outputs=msg
796
  )
797
 
798
+ # Main chat functionality
799
  submit.click(
800
  handle_submit,
801
  inputs=[msg, files, chat_history],
802
  outputs=[chatbot, chat_history, msg, download_file, download_status]
803
  ).then(
804
+ lambda: None, # Clear files after processing
805
  outputs=files
806
  )
807
 
 
810
  inputs=[msg, files, chat_history],
811
  outputs=[chatbot, chat_history, msg, download_file, download_status]
812
  ).then(
813
+ lambda: None, # Clear files after processing
814
  outputs=files
815
  )
816