Nils Durner commited on
Commit
825811f
Β·
1 Parent(s): 142adef

improve cache management

Browse files
Files changed (1) hide show
  1. app.py +8 -0
app.py CHANGED
@@ -10,6 +10,8 @@ from doc2json import process_docx
10
  dump_controls = False
11
  log_to_console = False
12
 
 
 
13
  # constants
14
  image_embed_prefix = "πŸ–ΌοΈπŸ†™ "
15
  audio_embed_prefix = "πŸŽ™οΈπŸ†™ "
@@ -67,10 +69,14 @@ def add_file(history, files):
67
  fn = os.path.basename(file.name)
68
  history = history + [(f'```{fn}\n{content}\n```', None)]
69
 
 
 
70
  return history
71
 
72
  def add_img(history, files):
73
  for file in files:
 
 
74
  if log_to_console:
75
  print(f"add_img {file.name}")
76
 
@@ -78,6 +84,7 @@ def add_img(history, files):
78
  prefix = audio_embed_prefix
79
  else:
80
  prefix = image_embed_prefix
 
81
  history = history + [(prefix + file.name, None)]
82
 
83
  gr.Info(f"Media added as {file.name}")
@@ -366,4 +373,5 @@ with gr.Blocks(delete_cache=(86400, 86400)) as demo:
366
  """)
367
  import_button.upload(import_history, inputs=[chatbot, import_button], outputs=[chatbot, system_prompt])
368
 
 
369
  demo.queue().launch()
 
10
  dump_controls = False
11
  log_to_console = False
12
 
13
+ temp_files = []
14
+
15
  # constants
16
  image_embed_prefix = "πŸ–ΌοΈπŸ†™ "
17
  audio_embed_prefix = "πŸŽ™οΈπŸ†™ "
 
69
  fn = os.path.basename(file.name)
70
  history = history + [(f'```{fn}\n{content}\n```', None)]
71
 
72
+ os.remove(file.name)
73
+
74
  return history
75
 
76
  def add_img(history, files):
77
  for file in files:
78
+ temp_files.append(file.name)
79
+
80
  if log_to_console:
81
  print(f"add_img {file.name}")
82
 
 
84
  prefix = audio_embed_prefix
85
  else:
86
  prefix = image_embed_prefix
87
+
88
  history = history + [(prefix + file.name, None)]
89
 
90
  gr.Info(f"Media added as {file.name}")
 
373
  """)
374
  import_button.upload(import_history, inputs=[chatbot, import_button], outputs=[chatbot, system_prompt])
375
 
376
+ demo.unload(lambda: [os.remove(file) for file in temp_files])
377
  demo.queue().launch()