shukdevdattaEX commited on
Commit
1f64ebe
·
verified ·
1 Parent(s): 71df579

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +87 -23
app.py CHANGED
@@ -238,7 +238,7 @@ def process_audio_input(audio_file, user_question: str, api_key_status: str) ->
238
  combined_input = f"Transcribed audio: '{transcribed_text}'\n\nUser question: {user_question}"
239
  return nexus_ai.generate_response(combined_input, "audio", transcribed_text)
240
  else:
241
- return nexus_ai.generate_response("Please help me with this audio content", "audio", transcribed_text)
242
 
243
  def process_code_input(code_input: str, language: str, action: str, api_key_status: str) -> str:
244
  """Process code input"""
@@ -281,6 +281,22 @@ def clear_conversation_history() -> str:
281
  nexus_ai.memory.clear_history()
282
  return "✅ Conversation history has been cleared!"
283
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
284
  def create_nexus_interface():
285
  with gr.Blocks(
286
  theme=gr.themes.Soft(),
@@ -317,7 +333,6 @@ def create_nexus_interface():
317
  transform: translateY(-2px) !important;
318
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2) !important;
319
  }
320
-
321
  .primary-button2 {
322
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
323
  border: none !important;
@@ -461,11 +476,17 @@ def create_nexus_interface():
461
  lines=4,
462
  elem_classes=["scrollable-textarea"]
463
  )
464
- text_btn = gr.Button(
465
- "Send Message",
466
- variant="primary",
467
- elem_classes=["primary-button"]
468
- )
 
 
 
 
 
 
469
 
470
  with gr.Column(scale=1, elem_classes=["output-card"]):
471
  text_output = gr.Textbox(
@@ -488,11 +509,17 @@ def create_nexus_interface():
488
  lines=3,
489
  elem_classes=["scrollable-textarea"]
490
  )
491
- pdf_btn = gr.Button(
492
- "Analyze PDF",
493
- variant="primary",
494
- elem_classes=["primary-button"]
495
- )
 
 
 
 
 
 
496
 
497
  with gr.Column(scale=1, elem_classes=["output-card"]):
498
  pdf_output = gr.Textbox(
@@ -507,7 +534,8 @@ def create_nexus_interface():
507
  with gr.Column(scale=1, elem_classes=["input-card"]):
508
  audio_file = gr.Audio(
509
  label="Upload Audio",
510
- type="filepath"
 
511
  )
512
  audio_question = gr.Textbox(
513
  label="Additional Question (optional)",
@@ -515,11 +543,17 @@ def create_nexus_interface():
515
  lines=3,
516
  elem_classes=["scrollable-textarea"]
517
  )
518
- audio_btn = gr.Button(
519
- "Process Audio",
520
- variant="primary",
521
- elem_classes=["primary-button"]
522
- )
 
 
 
 
 
 
523
 
524
  with gr.Column(scale=1, elem_classes=["output-card"]):
525
  audio_output = gr.Textbox(
@@ -550,11 +584,17 @@ def create_nexus_interface():
550
  label="Action",
551
  scale=1
552
  )
553
- code_btn = gr.Button(
554
- "Process Code",
555
- variant="primary",
556
- elem_classes=["primary-button"]
557
- )
 
 
 
 
 
 
558
 
559
  with gr.Column(scale=1, elem_classes=["output-card"]):
560
  code_output = gr.Textbox(
@@ -609,24 +649,48 @@ def create_nexus_interface():
609
  outputs=[text_output]
610
  )
611
 
 
 
 
 
 
 
612
  pdf_btn.click(
613
  fn=process_pdf_input,
614
  inputs=[pdf_file, pdf_question, api_key_state],
615
  outputs=[pdf_output]
616
  )
617
 
 
 
 
 
 
 
618
  audio_btn.click(
619
  fn=process_audio_input,
620
  inputs=[audio_file, audio_question, api_key_state],
621
  outputs=[audio_output]
622
  )
623
 
 
 
 
 
 
 
624
  code_btn.click(
625
  fn=process_code_input,
626
  inputs=[code_input, language_select, code_action, api_key_state],
627
  outputs=[code_output]
628
  )
629
 
 
 
 
 
 
 
630
  history_btn.click(
631
  fn=show_conversation_history,
632
  outputs=[history_output]
 
238
  combined_input = f"Transcribed audio: '{transcribed_text}'\n\nUser question: {user_question}"
239
  return nexus_ai.generate_response(combined_input, "audio", transcribed_text)
240
  else:
241
+ return nexus_ai.generate_response("Please help me with this audio içeriği", "audio", transcribed_text)
242
 
243
  def process_code_input(code_input: str, language: str, action: str, api_key_status: str) -> str:
244
  """Process code input"""
 
281
  nexus_ai.memory.clear_history()
282
  return "✅ Conversation history has been cleared!"
283
 
284
+ def clear_text_inputs():
285
+ """Clear text input and output"""
286
+ return "", ""
287
+
288
+ def clear_pdf_inputs():
289
+ """Clear PDF input and output"""
290
+ return None, "", ""
291
+
292
+ def clear_audio_inputs():
293
+ """Clear audio input and output"""
294
+ return None, "", ""
295
+
296
+ def clear_code_inputs():
297
+ """Clear code input and output"""
298
+ return "", "", "python", "Execute Code"
299
+
300
  def create_nexus_interface():
301
  with gr.Blocks(
302
  theme=gr.themes.Soft(),
 
333
  transform: translateY(-2px) !important;
334
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2) !important;
335
  }
 
336
  .primary-button2 {
337
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
338
  border: none !important;
 
476
  lines=4,
477
  elem_classes=["scrollable-textarea"]
478
  )
479
+ with gr.Row():
480
+ text_btn = gr.Button(
481
+ "Send Message",
482
+ variant="primary",
483
+ elem_classes=["primary-button"]
484
+ )
485
+ text_clear_btn = gr.Button(
486
+ "Clear",
487
+ variant="secondary",
488
+ elem_classes=["danger-button"]
489
+ )
490
 
491
  with gr.Column(scale=1, elem_classes=["output-card"]):
492
  text_output = gr.Textbox(
 
509
  lines=3,
510
  elem_classes=["scrollable-textarea"]
511
  )
512
+ with gr.Row():
513
+ pdf_btn = gr.Button(
514
+ "Analyze PDF",
515
+ variant="primary",
516
+ elem_classes=["primary-button"]
517
+ )
518
+ pdf_clear_btn = gr.Button(
519
+ "Clear",
520
+ variant="secondary",
521
+ elem_classes=["danger-button"]
522
+ )
523
 
524
  with gr.Column(scale=1, elem_classes=["output-card"]):
525
  pdf_output = gr.Textbox(
 
534
  with gr.Column(scale=1, elem_classes=["input-card"]):
535
  audio_file = gr.Audio(
536
  label="Upload Audio",
537
+ type="filepath",
538
+ file_types=[".wav", ".mp3", ".ogg", ".flac", ".aac", ".m4a"]
539
  )
540
  audio_question = gr.Textbox(
541
  label="Additional Question (optional)",
 
543
  lines=3,
544
  elem_classes=["scrollable-textarea"]
545
  )
546
+ with gr.Row():
547
+ audio_btn = gr.Button(
548
+ "Process Audio",
549
+ variant="primary",
550
+ elem_classes=["primary-button"]
551
+ )
552
+ audio_clear_btn = gr.Button(
553
+ "Clear",
554
+ variant="secondary",
555
+ elem_classes=["danger-button"]
556
+ )
557
 
558
  with gr.Column(scale=1, elem_classes=["output-card"]):
559
  audio_output = gr.Textbox(
 
584
  label="Action",
585
  scale=1
586
  )
587
+ with gr.Row():
588
+ code_btn = gr.Button(
589
+ "Process Code",
590
+ variant="primary",
591
+ elem_classes=["primary-button"]
592
+ )
593
+ code_clear_btn = gr.Button(
594
+ "Clear",
595
+ variant="secondary",
596
+ elem_classes=["danger-button"]
597
+ )
598
 
599
  with gr.Column(scale=1, elem_classes=["output-card"]):
600
  code_output = gr.Textbox(
 
649
  outputs=[text_output]
650
  )
651
 
652
+ text_clear_btn.click(
653
+ fn=clear_text_inputs,
654
+ inputs=[],
655
+ outputs=[text_input, text_output]
656
+ )
657
+
658
  pdf_btn.click(
659
  fn=process_pdf_input,
660
  inputs=[pdf_file, pdf_question, api_key_state],
661
  outputs=[pdf_output]
662
  )
663
 
664
+ pdf_clear_btn.click(
665
+ fn=clear_pdf_inputs,
666
+ inputs=[],
667
+ outputs=[pdf_file, pdf_question, pdf_output]
668
+ )
669
+
670
  audio_btn.click(
671
  fn=process_audio_input,
672
  inputs=[audio_file, audio_question, api_key_state],
673
  outputs=[audio_output]
674
  )
675
 
676
+ audio_clear_btn.click(
677
+ fn=clear_audio_inputs,
678
+ inputs=[],
679
+ outputs=[audio_file, audio_question, audio_output]
680
+ )
681
+
682
  code_btn.click(
683
  fn=process_code_input,
684
  inputs=[code_input, language_select, code_action, api_key_state],
685
  outputs=[code_output]
686
  )
687
 
688
+ code_clear_btn.click(
689
+ fn=clear_code_inputs,
690
+ inputs=[],
691
+ outputs=[code_input, code_output, language_select, code_action]
692
+ )
693
+
694
  history_btn.click(
695
  fn=show_conversation_history,
696
  outputs=[history_output]