Anton Bushuiev commited on
Commit
54cdebc
·
1 Parent(s): bee03d0
Files changed (1) hide show
  1. app.py +20 -9
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
  import spaces
3
  import urllib.request
4
- import os
5
  from datetime import datetime
6
  from functools import partial
7
  import matplotlib.pyplot as plt
@@ -141,11 +141,27 @@ def setup():
141
  print("Setup complete")
142
 
143
 
144
- def _predict_gpu(msdata):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
  embs = dreams_embeddings(msdata)
 
146
  return embs
147
 
148
- @spaces.GPU
149
  def _predict_core(lib_pth, in_pth, progress):
150
  """Core prediction function without error handling"""
151
  in_pth = Path(in_pth)
@@ -155,13 +171,8 @@ def _predict_core(lib_pth, in_pth, progress):
155
  msdata_lib = MSData.load(lib_pth)
156
  embs_lib = msdata_lib[DREAMS_EMBEDDING]
157
  print('Shape of the library embeddings:', embs_lib.shape)
158
-
159
- progress(0.1, desc="Loading spectra data...")
160
- msdata = MSData.load(in_pth)
161
 
162
- progress(0.2, desc="Computing DreaMS embeddings...")
163
- embs = _predict_gpu(msdata)
164
- print('Shape of the query embeddings:', embs.shape)
165
 
166
  progress(0.4, desc="Computing similarity matrix...")
167
  sims = cosine_similarity(embs, embs_lib)
 
1
  import gradio as gr
2
  import spaces
3
  import urllib.request
4
+ import torch
5
  from datetime import datetime
6
  from functools import partial
7
  import matplotlib.pyplot as plt
 
141
  print("Setup complete")
142
 
143
 
144
+ @spaces.GPU
145
+ def _predict_gpu(in_pth, progress):
146
+ # Check GPU availability and print details
147
+ print("\nGPU Information:")
148
+ print(f"CUDA Available: {torch.cuda.is_available()}")
149
+ if torch.cuda.is_available():
150
+ print(f"Current Device: {torch.cuda.current_device()}")
151
+ print(f"Device Name: {torch.cuda.get_device_name()}")
152
+ print(f"Device Count: {torch.cuda.device_count()}")
153
+ print(f"Memory Allocated: {torch.cuda.memory_allocated()/1024**2:.2f} MB")
154
+ print(f"Memory Reserved: {torch.cuda.memory_reserved()/1024**2:.2f} MB\n")
155
+ else:
156
+ print("No GPU available")
157
+ progress(0.1, desc="Loading spectra data...")
158
+ msdata = MSData.load(in_pth)
159
+ progress(0.2, desc="Computing DreaMS embeddings...")
160
  embs = dreams_embeddings(msdata)
161
+ print('Shape of the query embeddings:', embs.shape)
162
  return embs
163
 
164
+
165
  def _predict_core(lib_pth, in_pth, progress):
166
  """Core prediction function without error handling"""
167
  in_pth = Path(in_pth)
 
171
  msdata_lib = MSData.load(lib_pth)
172
  embs_lib = msdata_lib[DREAMS_EMBEDDING]
173
  print('Shape of the library embeddings:', embs_lib.shape)
 
 
 
174
 
175
+ embs = _predict_gpu(in_pth, progress)
 
 
176
 
177
  progress(0.4, desc="Computing similarity matrix...")
178
  sims = cosine_similarity(embs, embs_lib)