Spaces:
Sleeping
Sleeping
checking data access
Browse files
app.py
CHANGED
|
@@ -24,13 +24,18 @@ def get_base(filename):
|
|
| 24 |
return BASE["cory"]
|
| 25 |
from datasets import load_dataset
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
# Load dataset
|
| 29 |
-
dataset = load_dataset("IndoorOutdoor/1090dumpData")
|
| 30 |
|
| 31 |
-
# Get dataset cache directory (where files are stored)
|
| 32 |
-
dataset_dir = dataset.cache_files
|
| 33 |
-
print("Dataset directory:", dataset_dir)
|
| 34 |
|
| 35 |
#for root, dirs, files in os.walk(dataset_dir):
|
| 36 |
# for file in files:
|
|
@@ -155,77 +160,51 @@ HF_STORAGE_DIR = "data"
|
|
| 155 |
if not os.path.exists(HF_STORAGE_DIR):
|
| 156 |
os.makedirs(HF_STORAGE_DIR)
|
| 157 |
|
| 158 |
-
|
| 159 |
-
def evaluate_model(username, file):
|
| 160 |
global leaderboard_data
|
| 161 |
|
| 162 |
username = username.strip()
|
| 163 |
if not username:
|
| 164 |
return leaderboard_data.values.tolist()
|
| 165 |
|
| 166 |
-
|
| 167 |
-
temp_file_path = file
|
| 168 |
-
else:
|
| 169 |
-
temp_file_path = os.path.join(HF_STORAGE_DIR, f"{username}_model.pt")
|
| 170 |
-
with open(temp_file_path, "wb") as temp_file:
|
| 171 |
-
temp_file.write(file.read())
|
| 172 |
|
| 173 |
try:
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
#
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
# print(TP, FP, FN, TN)
|
| 200 |
-
# TP = np.mean([x[0] for x in stats_model_in_out])
|
| 201 |
-
# FP = np.mean([x[1] for x in stats_model_in_out])
|
| 202 |
-
# FN = np.mean([x[2] for x in stats_model_in_out])
|
| 203 |
-
# TN = np.mean([x[3] for x in stats_model_in_out])
|
| 204 |
-
# print(TP, FP, FN, TN)
|
| 205 |
-
# end_time = time.time()
|
| 206 |
-
# exec_time = end_time - start_time
|
| 207 |
-
# print(f"Execution Time: {exec_time} seconds")
|
| 208 |
-
except Exception as e:
|
| 209 |
-
leaderboard_data = pd.concat([leaderboard_data, pd.DataFrame([[username, float("inf"), 0, f"Model Load Error: {str(e)}"]],
|
| 210 |
-
columns=["Username", "Execution Time (s)", "Accuracy", "Status"])], ignore_index=True)
|
| 211 |
-
return leaderboard_data.values.tolist()
|
| 212 |
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
correct = 0
|
| 216 |
-
total = 0
|
| 217 |
|
| 218 |
-
|
| 219 |
-
with torch.no_grad():
|
| 220 |
-
for images, labels in test_loader:
|
| 221 |
-
outputs = model(images)
|
| 222 |
-
_, predicted = torch.max(outputs, 1)
|
| 223 |
-
correct += (predicted == labels).sum().item()
|
| 224 |
-
total += labels.size(0)
|
| 225 |
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
|
|
|
| 229 |
|
| 230 |
# Append to leaderboard
|
| 231 |
new_entry = pd.DataFrame([[username, execution_time, accuracy, status]],
|
|
@@ -237,7 +216,8 @@ def evaluate_model(username, file):
|
|
| 237 |
leaderboard_data = leaderboard_data.sort_values(by=["Accuracy", "Execution Time (s)"],
|
| 238 |
ascending=[False, True]).reset_index(drop=True)
|
| 239 |
|
| 240 |
-
return leaderboard_data.values.tolist()
|
|
|
|
| 241 |
|
| 242 |
# Create Gradio UI
|
| 243 |
with gr.Blocks() as demo:
|
|
|
|
| 24 |
return BASE["cory"]
|
| 25 |
from datasets import load_dataset
|
| 26 |
|
| 27 |
+
import pandas as pd
|
| 28 |
+
|
| 29 |
+
metadata_file = os.path.join(data_dir, "metadata.csv")
|
| 30 |
+
df = pd.read_csv(metadata_file)
|
| 31 |
+
print(df.head()) # Print first few rows
|
| 32 |
|
| 33 |
# Load dataset
|
| 34 |
+
# dataset = load_dataset("IndoorOutdoor/1090dumpData")
|
| 35 |
|
| 36 |
+
# # Get dataset cache directory (where files are stored)
|
| 37 |
+
# dataset_dir = dataset.cache_files
|
| 38 |
+
# print("Dataset directory:", dataset_dir)
|
| 39 |
|
| 40 |
#for root, dirs, files in os.walk(dataset_dir):
|
| 41 |
# for file in files:
|
|
|
|
| 160 |
if not os.path.exists(HF_STORAGE_DIR):
|
| 161 |
os.makedirs(HF_STORAGE_DIR)
|
| 162 |
|
| 163 |
+
def evaluate_model(username):
|
|
|
|
| 164 |
global leaderboard_data
|
| 165 |
|
| 166 |
username = username.strip()
|
| 167 |
if not username:
|
| 168 |
return leaderboard_data.values.tolist()
|
| 169 |
|
| 170 |
+
dataset_directory = "/data" # Path where files are stored in Hugging Face Spaces
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
|
| 172 |
try:
|
| 173 |
+
# Load metadata
|
| 174 |
+
metadata_path = os.path.join(dataset_directory, "metadata.csv")
|
| 175 |
+
exp = read_configuration(metadata_path) # Use your existing function
|
| 176 |
+
|
| 177 |
+
stats_model_sectors = []
|
| 178 |
+
stats_model_in_out = []
|
| 179 |
+
|
| 180 |
+
for key in exp:
|
| 181 |
+
filename = exp[key]['file']
|
| 182 |
+
indoor_gt = exp[key]['indoor']
|
| 183 |
+
sectors_gt = exp[key]["sectors"]
|
| 184 |
+
|
| 185 |
+
file_path = os.path.join(dataset_directory, filename)
|
| 186 |
+
|
| 187 |
+
# Run your clustering model
|
| 188 |
+
sectors_model = model_based_clustering(dataset_directory, filename)
|
| 189 |
+
|
| 190 |
+
# Compute statistics
|
| 191 |
+
stats_model_sectors.append(compute_stats_sector(sectors_model, sectors_gt))
|
| 192 |
+
stats_model_in_out.append(compute_stats_in_out(sectors_model, indoor_gt))
|
| 193 |
|
| 194 |
+
TP = np.mean([x[0] for x in stats_model_sectors])
|
| 195 |
+
FP = np.mean([x[1] for x in stats_model_sectors])
|
| 196 |
+
FN = np.mean([x[2] for x in stats_model_sectors])
|
| 197 |
+
TN = np.mean([x[3] for x in stats_model_sectors])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
|
| 199 |
+
execution_time = round(time.time() - start_time, 4)
|
| 200 |
+
accuracy = round((TP + TN) / (TP + TN + FP + FN), 2)
|
|
|
|
|
|
|
| 201 |
|
| 202 |
+
status = "Success" if accuracy > 0 else "Incorrect Model"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
|
| 204 |
+
except Exception as e:
|
| 205 |
+
leaderboard_data = pd.concat([leaderboard_data, pd.DataFrame([[username, float("inf"), 0, f"Model Error: {str(e)}"]],
|
| 206 |
+
columns=["Username", "Execution Time (s)", "Accuracy", "Status"])], ignore_index=True)
|
| 207 |
+
return leaderboard_data.values.tolist()
|
| 208 |
|
| 209 |
# Append to leaderboard
|
| 210 |
new_entry = pd.DataFrame([[username, execution_time, accuracy, status]],
|
|
|
|
| 216 |
leaderboard_data = leaderboard_data.sort_values(by=["Accuracy", "Execution Time (s)"],
|
| 217 |
ascending=[False, True]).reset_index(drop=True)
|
| 218 |
|
| 219 |
+
return leaderboard_data.values.tolist()
|
| 220 |
+
|
| 221 |
|
| 222 |
# Create Gradio UI
|
| 223 |
with gr.Blocks() as demo:
|