milwright commited on
Commit
49f544a
·
1 Parent(s): e6ff6e7

fix: move store_and_generate_response to module scope

Browse files
Files changed (1) hide show
  1. app.py +28 -28
app.py CHANGED
@@ -507,6 +507,34 @@ class AccessControl:
507
  access_control = AccessControl()
508
 
509
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
510
  def create_interface() -> gr.Blocks:
511
  """Create the main Gradio interface"""
512
  # API key validation
@@ -612,34 +640,6 @@ def create_interface() -> gr.Blocks:
612
  # Track current history for export
613
  current_history = gr.State([])
614
 
615
- def store_and_generate_response(message, history, *args):
616
- """Store history and generate response"""
617
- # Convert history to expected format
618
- formatted_history = []
619
- for h in history:
620
- if isinstance(h, dict):
621
- formatted_history.append(h)
622
- elif isinstance(h, (list, tuple)) and len(h) == 2:
623
- formatted_history.append({"role": "user", "content": h[0]})
624
- if h[1]:
625
- formatted_history.append({"role": "assistant", "content": h[1]})
626
-
627
- # Handle file uploads if enabled
628
- files = None
629
- if ENABLE_FILE_UPLOAD and args:
630
- files = args[0]
631
-
632
- response = generate_response(message, formatted_history, files)
633
-
634
- # Update stored history
635
- new_history = formatted_history + [
636
- {"role": "user", "content": message},
637
- {"role": "assistant", "content": response}
638
- ]
639
- current_history.value = new_history
640
-
641
- return response
642
-
643
  # Export handler
644
  def prepare_export(history):
645
  """Prepare conversation for export"""
 
507
  access_control = AccessControl()
508
 
509
 
510
+ def store_and_generate_response(message, history, *args):
511
+ """Store history and generate response"""
512
+ # Convert history to expected format
513
+ formatted_history = []
514
+ for h in history:
515
+ if isinstance(h, dict):
516
+ formatted_history.append(h)
517
+ elif isinstance(h, (list, tuple)) and len(h) == 2:
518
+ formatted_history.append({"role": "user", "content": h[0]})
519
+ if h[1]:
520
+ formatted_history.append({"role": "assistant", "content": h[1]})
521
+
522
+ # Handle file uploads if enabled
523
+ files = None
524
+ if ENABLE_FILE_UPLOAD and args:
525
+ files = args[0]
526
+
527
+ response = generate_response(message, formatted_history, files)
528
+
529
+ # Update stored history
530
+ new_history = formatted_history + [
531
+ {"role": "user", "content": message},
532
+ {"role": "assistant", "content": response}
533
+ ]
534
+
535
+ return response
536
+
537
+
538
  def create_interface() -> gr.Blocks:
539
  """Create the main Gradio interface"""
540
  # API key validation
 
640
  # Track current history for export
641
  current_history = gr.State([])
642
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
643
  # Export handler
644
  def prepare_export(history):
645
  """Prepare conversation for export"""