Spaces:
Paused
Paused
Andy Lee
commited on
Commit
·
bf35ece
1
Parent(s):
a9dca21
feat: let users choose diff datasets
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import time
|
|
| 5 |
from io import BytesIO
|
| 6 |
from PIL import Image
|
| 7 |
from typing import Dict, List, Any
|
|
|
|
| 8 |
|
| 9 |
# Import core logic and configurations from the project
|
| 10 |
from geo_bot import (
|
|
@@ -13,11 +14,30 @@ from geo_bot import (
|
|
| 13 |
BENCHMARK_PROMPT,
|
| 14 |
)
|
| 15 |
from benchmark import MapGuesserBenchmark
|
| 16 |
-
from config import MODELS_CONFIG,
|
| 17 |
from langchain_openai import ChatOpenAI
|
| 18 |
from langchain_anthropic import ChatAnthropic
|
| 19 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
# --- Page UI Setup ---
|
| 22 |
st.set_page_config(page_title="MapCrunch AI Agent", layout="wide")
|
| 23 |
st.title("🗺️ MapCrunch AI Agent")
|
|
@@ -34,22 +54,33 @@ with st.sidebar:
|
|
| 34 |
os.environ["ANTHROPIC_API_KEY"] = st.secrets.get("ANTHROPIC_API_KEY", "")
|
| 35 |
# os.environ['GOOGLE_API_KEY'] = st.secrets.get("GOOGLE_API_KEY", "")
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
model_choice = st.selectbox("Select AI Model", list(MODELS_CONFIG.keys()))
|
| 38 |
steps_per_sample = st.slider(
|
| 39 |
"Max Exploration Steps per Sample", min_value=3, max_value=20, value=10
|
| 40 |
)
|
| 41 |
|
| 42 |
-
# Load golden labels for
|
|
|
|
| 43 |
try:
|
| 44 |
-
with open(
|
| 45 |
golden_labels = json.load(f).get("samples", [])
|
| 46 |
total_samples = len(golden_labels)
|
|
|
|
|
|
|
|
|
|
| 47 |
num_samples_to_run = st.slider(
|
| 48 |
-
"Number of Samples to Test",
|
|
|
|
|
|
|
|
|
|
| 49 |
)
|
| 50 |
except FileNotFoundError:
|
| 51 |
st.error(
|
| 52 |
-
f"
|
| 53 |
)
|
| 54 |
golden_labels = []
|
| 55 |
num_samples_to_run = 0
|
|
@@ -68,11 +99,11 @@ if start_button:
|
|
| 68 |
model_instance_name = config["model_name"]
|
| 69 |
|
| 70 |
# Initialize helpers and result lists
|
| 71 |
-
benchmark_helper = MapGuesserBenchmark()
|
| 72 |
all_results = []
|
| 73 |
|
| 74 |
st.info(
|
| 75 |
-
f"Starting Agent Benchmark... Model: {model_choice}, Steps: {steps_per_sample}, Samples: {num_samples_to_run}"
|
| 76 |
)
|
| 77 |
|
| 78 |
overall_progress_bar = st.progress(0, text="Overall Progress")
|
|
|
|
| 5 |
from io import BytesIO
|
| 6 |
from PIL import Image
|
| 7 |
from typing import Dict, List, Any
|
| 8 |
+
from pathlib import Path
|
| 9 |
|
| 10 |
# Import core logic and configurations from the project
|
| 11 |
from geo_bot import (
|
|
|
|
| 14 |
BENCHMARK_PROMPT,
|
| 15 |
)
|
| 16 |
from benchmark import MapGuesserBenchmark
|
| 17 |
+
from config import MODELS_CONFIG, get_data_paths, SUCCESS_THRESHOLD_KM
|
| 18 |
from langchain_openai import ChatOpenAI
|
| 19 |
from langchain_anthropic import ChatAnthropic
|
| 20 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 21 |
|
| 22 |
+
|
| 23 |
+
# --- Helper function ---
|
| 24 |
+
def get_available_datasets():
|
| 25 |
+
"""Get list of available datasets"""
|
| 26 |
+
datasets_dir = Path("datasets")
|
| 27 |
+
if not datasets_dir.exists():
|
| 28 |
+
return ["default"]
|
| 29 |
+
|
| 30 |
+
datasets = []
|
| 31 |
+
for dataset_dir in datasets_dir.iterdir():
|
| 32 |
+
if dataset_dir.is_dir():
|
| 33 |
+
dataset_name = dataset_dir.name
|
| 34 |
+
data_paths = get_data_paths(dataset_name)
|
| 35 |
+
if os.path.exists(data_paths["golden_labels"]):
|
| 36 |
+
datasets.append(dataset_name)
|
| 37 |
+
|
| 38 |
+
return datasets if datasets else ["default"]
|
| 39 |
+
|
| 40 |
+
|
| 41 |
# --- Page UI Setup ---
|
| 42 |
st.set_page_config(page_title="MapCrunch AI Agent", layout="wide")
|
| 43 |
st.title("🗺️ MapCrunch AI Agent")
|
|
|
|
| 54 |
os.environ["ANTHROPIC_API_KEY"] = st.secrets.get("ANTHROPIC_API_KEY", "")
|
| 55 |
# os.environ['GOOGLE_API_KEY'] = st.secrets.get("GOOGLE_API_KEY", "")
|
| 56 |
|
| 57 |
+
# Dataset selection
|
| 58 |
+
available_datasets = get_available_datasets()
|
| 59 |
+
dataset_choice = st.selectbox("Select Dataset", available_datasets)
|
| 60 |
+
|
| 61 |
model_choice = st.selectbox("Select AI Model", list(MODELS_CONFIG.keys()))
|
| 62 |
steps_per_sample = st.slider(
|
| 63 |
"Max Exploration Steps per Sample", min_value=3, max_value=20, value=10
|
| 64 |
)
|
| 65 |
|
| 66 |
+
# Load golden labels for selected dataset
|
| 67 |
+
data_paths = get_data_paths(dataset_choice)
|
| 68 |
try:
|
| 69 |
+
with open(data_paths["golden_labels"], "r", encoding="utf-8") as f:
|
| 70 |
golden_labels = json.load(f).get("samples", [])
|
| 71 |
total_samples = len(golden_labels)
|
| 72 |
+
|
| 73 |
+
st.info(f"Dataset '{dataset_choice}' has {total_samples} samples")
|
| 74 |
+
|
| 75 |
num_samples_to_run = st.slider(
|
| 76 |
+
"Number of Samples to Test",
|
| 77 |
+
min_value=1,
|
| 78 |
+
max_value=total_samples,
|
| 79 |
+
value=min(3, total_samples),
|
| 80 |
)
|
| 81 |
except FileNotFoundError:
|
| 82 |
st.error(
|
| 83 |
+
f"Dataset '{dataset_choice}' not found at {data_paths['golden_labels']}. Please create the dataset first."
|
| 84 |
)
|
| 85 |
golden_labels = []
|
| 86 |
num_samples_to_run = 0
|
|
|
|
| 99 |
model_instance_name = config["model_name"]
|
| 100 |
|
| 101 |
# Initialize helpers and result lists
|
| 102 |
+
benchmark_helper = MapGuesserBenchmark(dataset_name=dataset_choice)
|
| 103 |
all_results = []
|
| 104 |
|
| 105 |
st.info(
|
| 106 |
+
f"Starting Agent Benchmark... Dataset: {dataset_choice}, Model: {model_choice}, Steps: {steps_per_sample}, Samples: {num_samples_to_run}"
|
| 107 |
)
|
| 108 |
|
| 109 |
overall_progress_bar = st.progress(0, text="Overall Progress")
|