Spaces:
Runtime error
Runtime error
Commit
·
050040c
1
Parent(s):
d072d89
improve loading experience
Browse files
app.py
CHANGED
|
@@ -13,6 +13,7 @@ example_indexes = {
|
|
| 13 |
"IONIQ 2024": "./iconiq_report_index",
|
| 14 |
"Uber 10k 2021": "./uber_index",
|
| 15 |
}
|
|
|
|
| 16 |
|
| 17 |
device = "cpu"
|
| 18 |
if torch.cuda.is_available():
|
|
@@ -42,7 +43,7 @@ class IndexManager:
|
|
| 42 |
def __init__(self):
|
| 43 |
self.current_index = None
|
| 44 |
# Initialize with default index
|
| 45 |
-
self.load_index(example_indexes[
|
| 46 |
|
| 47 |
def load_index(self, index_path):
|
| 48 |
storage_context = StorageContext.from_defaults(persist_dir=index_path)
|
|
@@ -218,20 +219,23 @@ Processing will take a few minutes when creating a new index, depending on the s
|
|
| 218 |
)
|
| 219 |
|
| 220 |
# Event handlers
|
| 221 |
-
def load_existing_index(index_name):
|
| 222 |
if index_name:
|
| 223 |
try:
|
| 224 |
-
|
| 225 |
-
|
|
|
|
|
|
|
| 226 |
except Exception as e:
|
| 227 |
-
return f"Error loading index: {str(e)}"
|
| 228 |
-
return "No index selected"
|
| 229 |
|
| 230 |
existing_index_dropdown.change(
|
| 231 |
fn=load_existing_index,
|
| 232 |
inputs=[existing_index_dropdown],
|
| 233 |
-
outputs=[create_status],
|
| 234 |
-
api_name=False
|
|
|
|
| 235 |
)
|
| 236 |
|
| 237 |
create_btn.click(
|
|
|
|
| 13 |
"IONIQ 2024": "./iconiq_report_index",
|
| 14 |
"Uber 10k 2021": "./uber_index",
|
| 15 |
}
|
| 16 |
+
DEFAULT_INDEX = "IONIQ 2024"
|
| 17 |
|
| 18 |
device = "cpu"
|
| 19 |
if torch.cuda.is_available():
|
|
|
|
| 43 |
def __init__(self):
|
| 44 |
self.current_index = None
|
| 45 |
# Initialize with default index
|
| 46 |
+
self.load_index(example_indexes[DEFAULT_INDEX])
|
| 47 |
|
| 48 |
def load_index(self, index_path):
|
| 49 |
storage_context = StorageContext.from_defaults(persist_dir=index_path)
|
|
|
|
| 219 |
)
|
| 220 |
|
| 221 |
# Event handlers
|
| 222 |
+
def load_existing_index(index_name, progress=gr.Progress()):
|
| 223 |
if index_name:
|
| 224 |
try:
|
| 225 |
+
progress(0, desc="Loading index...")
|
| 226 |
+
result = index_manager.load_index(example_indexes[index_name])
|
| 227 |
+
progress(1.0, desc="Index loaded!")
|
| 228 |
+
return result, None
|
| 229 |
except Exception as e:
|
| 230 |
+
return f"Error loading index: {str(e)}", None
|
| 231 |
+
return "No index selected", None
|
| 232 |
|
| 233 |
existing_index_dropdown.change(
|
| 234 |
fn=load_existing_index,
|
| 235 |
inputs=[existing_index_dropdown],
|
| 236 |
+
outputs=[create_status, query_input],
|
| 237 |
+
api_name=False,
|
| 238 |
+
show_progress=True
|
| 239 |
)
|
| 240 |
|
| 241 |
create_btn.click(
|