lucalp commited on
Commit
426e2a5
·
1 Parent(s): e4544df

lru cache & run on load

Browse files
Files changed (1) hide show
  1. app.py +16 -0
app.py CHANGED
@@ -1,5 +1,6 @@
1
  from collections import defaultdict
2
  import spaces
 
3
  import math
4
  import os
5
  import gradio as gr
@@ -463,6 +464,7 @@ except Exception as e:
463
 
464
  # --- Main Processing Function ---
465
 
 
466
  @spaces.GPU
467
  def process_text(prompt: str) -> Tuple[
468
  Optional[matplotlib.figure.Figure], List[Tuple[str, str]], int, # BLT
@@ -620,6 +622,20 @@ with gr.Blocks(theme=Config.GRADIO_THEME) as iface:
620
  status_output
621
  ]
622
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
623
 
624
  # --- Launch the Gradio App ---
625
  if __name__ == "__main__":
 
1
  from collections import defaultdict
2
  import spaces
3
+ import functools
4
  import math
5
  import os
6
  import gradio as gr
 
464
 
465
  # --- Main Processing Function ---
466
 
467
+ @functools.lru_cache(maxsize=8)
468
  @spaces.GPU
469
  def process_text(prompt: str) -> Tuple[
470
  Optional[matplotlib.figure.Figure], List[Tuple[str, str]], int, # BLT
 
622
  status_output
623
  ]
624
  )
625
+ iface.load(
626
+ fn=process_text,
627
+ inputs=prompt_input,
628
+ outputs=[
629
+ plot_output,
630
+ highlighted_output_bl,
631
+ bl_count_output,
632
+ highlighted_output_tk,
633
+ tk_count_output,
634
+ highlighted_output_llama,
635
+ llama_count_output,
636
+ status_output
637
+ ]
638
+ )
639
 
640
  # --- Launch the Gradio App ---
641
  if __name__ == "__main__":