Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,6 @@
|
|
1 |
import os
|
|
|
|
|
2 |
#os.system("pip uninstall -y gradio")
|
3 |
#os.system("pip install --upgrade gradio")
|
4 |
#os.system("pip install datamapplot==0.3.0")
|
@@ -65,6 +67,7 @@ import umap
|
|
65 |
|
66 |
|
67 |
|
|
|
68 |
|
69 |
|
70 |
|
@@ -171,6 +174,8 @@ def get_pub(x):
|
|
171 |
|
172 |
|
173 |
|
|
|
|
|
174 |
#device = torch.device("mps" if torch.backends.mps.is_available() else "cuda")
|
175 |
#print(f"Using device: {device}")
|
176 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
@@ -230,6 +235,9 @@ def create_embeddings(texts_to_embedd):
|
|
230 |
|
231 |
|
232 |
|
|
|
|
|
|
|
233 |
|
234 |
def predict(text_input, sample_size_slider, reduce_sample_checkbox, progress=gr.Progress()):
|
235 |
|
@@ -243,13 +251,14 @@ def predict(text_input, sample_size_slider, reduce_sample_checkbox, progress=gr.
|
|
243 |
records = []
|
244 |
total_pages = (query_length + 199) // 200 # Calculate total number of pages
|
245 |
per_page = 0.3 / total_pages
|
246 |
-
|
247 |
for i, record in enumerate(chain(*query.paginate(per_page=200))):
|
248 |
records.append(record)
|
249 |
|
250 |
|
251 |
# Update progress bar
|
252 |
-
progress(
|
|
|
253 |
|
254 |
|
255 |
|
@@ -434,7 +443,8 @@ with gr.Blocks() as block:
|
|
434 |
|
435 |
def setup_basemap_data():
|
436 |
# get data.
|
437 |
-
print("
|
|
|
438 |
#basedata_df = load("100k_filtered_OA_sample_cluster_and_positions.bz")
|
439 |
basedata_df =pickle.load(open('100k_filtered_OA_sample_cluster_and_positions.pkl', 'rb'))
|
440 |
print(basedata_df)
|
@@ -443,7 +453,7 @@ def setup_basemap_data():
|
|
443 |
|
444 |
|
445 |
def setup_mapper():
|
446 |
-
print("
|
447 |
|
448 |
params_new = pickle.load(open('umap_mapper_300k_random_OA_specter_2_params.pkl', 'rb'))
|
449 |
print("setting up mapper...")
|
@@ -467,6 +477,8 @@ def setup_mapper():
|
|
467 |
|
468 |
basedata_df = setup_basemap_data()
|
469 |
mapper = setup_mapper()
|
|
|
|
|
470 |
|
471 |
|
472 |
# mount Gradio app to FastAPI app
|
|
|
1 |
import os
|
2 |
+
import time
|
3 |
+
print(f"Starting up: {time.strftime('%Y-%m-%d %H:%M:%S')}")
|
4 |
#os.system("pip uninstall -y gradio")
|
5 |
#os.system("pip install --upgrade gradio")
|
6 |
#os.system("pip install datamapplot==0.3.0")
|
|
|
67 |
|
68 |
|
69 |
|
70 |
+
print(f"Imports are done: {time.strftime('%Y-%m-%d %H:%M:%S')}")
|
71 |
|
72 |
|
73 |
|
|
|
174 |
|
175 |
|
176 |
|
177 |
+
print(f"Setting up language model: {time.strftime('%Y-%m-%d %H:%M:%S')}")
|
178 |
+
|
179 |
#device = torch.device("mps" if torch.backends.mps.is_available() else "cuda")
|
180 |
#print(f"Using device: {device}")
|
181 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
|
235 |
|
236 |
|
237 |
|
238 |
+
print(f"Language model is set up: {time.strftime('%Y-%m-%d %H:%M:%S')}")
|
239 |
+
|
240 |
+
|
241 |
|
242 |
def predict(text_input, sample_size_slider, reduce_sample_checkbox, progress=gr.Progress()):
|
243 |
|
|
|
251 |
records = []
|
252 |
total_pages = (query_length + 199) // 200 # Calculate total number of pages
|
253 |
per_page = 0.3 / total_pages
|
254 |
+
progress_counter = 0
|
255 |
for i, record in enumerate(chain(*query.paginate(per_page=200))):
|
256 |
records.append(record)
|
257 |
|
258 |
|
259 |
# Update progress bar
|
260 |
+
progress(progress_counter * per_page, desc="Getting queried data...")
|
261 |
+
progress_counter += 1
|
262 |
|
263 |
|
264 |
|
|
|
443 |
|
444 |
def setup_basemap_data():
|
445 |
# get data.
|
446 |
+
print(f"Getting basemap data: {time.strftime('%Y-%m-%d %H:%M:%S')}")
|
447 |
+
|
448 |
#basedata_df = load("100k_filtered_OA_sample_cluster_and_positions.bz")
|
449 |
basedata_df =pickle.load(open('100k_filtered_OA_sample_cluster_and_positions.pkl', 'rb'))
|
450 |
print(basedata_df)
|
|
|
453 |
|
454 |
|
455 |
def setup_mapper():
|
456 |
+
print(f"Getting Mapper: {time.strftime('%Y-%m-%d %H:%M:%S')}")
|
457 |
|
458 |
params_new = pickle.load(open('umap_mapper_300k_random_OA_specter_2_params.pkl', 'rb'))
|
459 |
print("setting up mapper...")
|
|
|
477 |
|
478 |
basedata_df = setup_basemap_data()
|
479 |
mapper = setup_mapper()
|
480 |
+
print(f"Setup done, starting up app: {time.strftime('%Y-%m-%d %H:%M:%S')}")
|
481 |
+
|
482 |
|
483 |
|
484 |
# mount Gradio app to FastAPI app
|