Spaces:
Sleeping
Sleeping
Upload src/persistentpoker_bench/web_ui.py with huggingface_hub
Browse files
src/persistentpoker_bench/web_ui.py
CHANGED
|
@@ -228,13 +228,27 @@ def build_web_app():
|
|
| 228 |
def on_load_file(file):
|
| 229 |
if file is None: return None, gr.update(choices=[]), "No file selected"
|
| 230 |
try:
|
| 231 |
-
|
| 232 |
with open(file.name, "r") as f:
|
| 233 |
-
|
| 234 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
|
| 236 |
-
# Récupère les noms des mains pour le dropdown
|
| 237 |
-
hand_names = [f"Hand {i+1}" for i in range(len(data.get("hand_results", [])))]
|
| 238 |
return data, gr.update(choices=hand_names, value=hand_names[0] if hand_names else None), f"Match loaded: {len(hand_names)} hands."
|
| 239 |
except Exception as e:
|
| 240 |
return None, gr.update(choices=[]), f"Error loading file: {e}"
|
|
@@ -270,11 +284,24 @@ def build_web_app():
|
|
| 270 |
if not demo_path.exists():
|
| 271 |
return None, gr.update(choices=[]), "Demo file 'marathon_demo.jsonl' not found on the server."
|
| 272 |
try:
|
|
|
|
| 273 |
with open(demo_path, "r") as f:
|
| 274 |
-
|
| 275 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
|
| 277 |
-
hand_names = [f"Hand {i+1}" for i in range(len(data.get("hand_results", [])))]
|
| 278 |
return data, gr.update(choices=hand_names, value=hand_names[0] if hand_names else None), f"Demo Marathon loaded: {len(hand_names)} hands."
|
| 279 |
except Exception as e:
|
| 280 |
return None, gr.update(choices=[]), f"Error loading demo file: {e}"
|
|
|
|
| 228 |
def on_load_file(file):
|
| 229 |
if file is None: return None, gr.update(choices=[]), "No file selected"
|
| 230 |
try:
|
| 231 |
+
data = None
|
| 232 |
with open(file.name, "r") as f:
|
| 233 |
+
for line in f:
|
| 234 |
+
if not line.strip(): continue
|
| 235 |
+
try:
|
| 236 |
+
parsed = json.loads(line)
|
| 237 |
+
# Support pour les deux formats historiques (hand_results ou transcript)
|
| 238 |
+
if "hand_results" in parsed or "transcript" in parsed:
|
| 239 |
+
data = parsed
|
| 240 |
+
except json.JSONDecodeError:
|
| 241 |
+
continue
|
| 242 |
+
|
| 243 |
+
if not data:
|
| 244 |
+
return None, gr.update(choices=[]), "No valid match data found in file."
|
| 245 |
+
|
| 246 |
+
hands = data.get("hand_results", data.get("transcript", []))
|
| 247 |
+
hand_names = [f"Hand {i+1}" for i in range(len(hands))]
|
| 248 |
+
|
| 249 |
+
# On normalise la clé pour que on_hand_change trouve toujours 'hand_results'
|
| 250 |
+
data["hand_results"] = hands
|
| 251 |
|
|
|
|
|
|
|
| 252 |
return data, gr.update(choices=hand_names, value=hand_names[0] if hand_names else None), f"Match loaded: {len(hand_names)} hands."
|
| 253 |
except Exception as e:
|
| 254 |
return None, gr.update(choices=[]), f"Error loading file: {e}"
|
|
|
|
| 284 |
if not demo_path.exists():
|
| 285 |
return None, gr.update(choices=[]), "Demo file 'marathon_demo.jsonl' not found on the server."
|
| 286 |
try:
|
| 287 |
+
data = None
|
| 288 |
with open(demo_path, "r") as f:
|
| 289 |
+
for line in f:
|
| 290 |
+
if not line.strip(): continue
|
| 291 |
+
try:
|
| 292 |
+
parsed = json.loads(line)
|
| 293 |
+
if "hand_results" in parsed or "transcript" in parsed:
|
| 294 |
+
data = parsed
|
| 295 |
+
except json.JSONDecodeError:
|
| 296 |
+
continue
|
| 297 |
+
|
| 298 |
+
if not data:
|
| 299 |
+
return None, gr.update(choices=[]), "No valid match data found in demo file."
|
| 300 |
+
|
| 301 |
+
hands = data.get("hand_results", data.get("transcript", []))
|
| 302 |
+
hand_names = [f"Hand {i+1}" for i in range(len(hands))]
|
| 303 |
+
data["hand_results"] = hands
|
| 304 |
|
|
|
|
| 305 |
return data, gr.update(choices=hand_names, value=hand_names[0] if hand_names else None), f"Demo Marathon loaded: {len(hand_names)} hands."
|
| 306 |
except Exception as e:
|
| 307 |
return None, gr.update(choices=[]), f"Error loading demo file: {e}"
|