Ultronprime commited on
Commit
09c1ee0
·
verified ·
1 Parent(s): e2228da

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -15
app.py CHANGED
@@ -9,7 +9,7 @@ from datetime import datetime
9
  from pathlib import Path
10
  import gc
11
  import torch
12
- from torch.cuda.amp import autocast
13
  from transformers import AutoModel, AutoTokenizer
14
  from sentence_transformers import SentenceTransformer
15
  import numpy as np
@@ -78,7 +78,7 @@ def initialize_model():
78
  def handle_gpu_operation(func):
79
  try:
80
  start_time = datetime.now()
81
- with autocast(enabled=torch.cuda.is_available()):
82
  result = func()
83
  end_time = datetime.now()
84
  duration = (end_time - start_time).total_seconds()
@@ -230,20 +230,18 @@ def browse_outputs():
230
  return "Error opening file browser"
231
 
232
  def download_results():
 
 
 
 
 
 
233
  try:
234
- output_files = [
235
- os.path.join(OUTPUTS_DIR, "embeddings.npy"),
236
- os.path.join(OUTPUTS_DIR, "chunks.txt")
237
- ]
238
-
239
- # Create a temporary zip file
240
- with tempfile.TemporaryDirectory() as temp_dir:
241
- zip_path = os.path.join(temp_dir, "results.zip")
242
- with zipfile.ZipFile(zip_path, 'w') as zipf:
243
- for file in output_files:
244
- if os.path.exists(file):
245
- zipf.write(file, os.path.basename(file))
246
- return zip_path
247
  except Exception as e:
248
  logger.error(f"Error creating download: {str(e)}")
249
  return None
 
9
  from pathlib import Path
10
  import gc
11
  import torch
12
+ from torch.amp import autocast
13
  from transformers import AutoModel, AutoTokenizer
14
  from sentence_transformers import SentenceTransformer
15
  import numpy as np
 
78
  def handle_gpu_operation(func):
79
  try:
80
  start_time = datetime.now()
81
+ with autocast(device_type='cuda', dtype=torch.float16):
82
  result = func()
83
  end_time = datetime.now()
84
  duration = (end_time - start_time).total_seconds()
 
230
  return "Error opening file browser"
231
 
232
  def download_results():
233
+ required_files = ["embeddings.npy", "chunks.txt"]
234
+ missing = [f for f in required_files if not os.path.exists(os.path.join(OUTPUTS_DIR, f))]
235
+ if missing:
236
+ logger.error(f"Missing files: {missing}")
237
+ return None
238
+
239
  try:
240
+ zip_path = os.path.join(OUTPUTS_DIR, "results.zip")
241
+ with zipfile.ZipFile(zip_path, 'w') as zipf:
242
+ for file in required_files:
243
+ zipf.write(os.path.join(OUTPUTS_DIR, file), file)
244
+ return zip_path
 
 
 
 
 
 
 
 
245
  except Exception as e:
246
  logger.error(f"Error creating download: {str(e)}")
247
  return None