Spaces:
Sleeping
Sleeping
| # app.py | |
| import os | |
| import pandas as pd | |
| import zipfile | |
| from huggingface_hub import hf_hub_download, HfApi | |
| from autogluon.tabular import TabularPredictor | |
| import gradio as gr | |
| import numpy as np | |
| MODEL_REPO = "samder03/2025-24679-tabular-autolguon-predictor" | |
| LOCAL_DIR = "/tmp/autogluon_predictor" | |
| os.makedirs(LOCAL_DIR, exist_ok=True) | |
| # Download the predictor zip from HF | |
| zip_path = hf_hub_download( | |
| repo_id=MODEL_REPO, | |
| filename="autogluon_predictor_dir.zip", | |
| local_dir=LOCAL_DIR | |
| ) | |
| # Extract the full predictor directory | |
| with zipfile.ZipFile(zip_path, 'r') as zip_ref: | |
| zip_ref.extractall(LOCAL_DIR) | |
| # Load the predictor from the extracted folder | |
| predictor = TabularPredictor.load(LOCAL_DIR, require_py_version_match=False) | |
| print("Predictor loaded successfully!") | |
| print("Label column:", predictor.label) | |
| print("Feature columns:", predictor.feature_metadata.get_features()) | |
| # Build Gradio input widgets | |
| features = predictor.feature_metadata.get_features() | |
| inputs = [] | |
| input_names = [] | |
| sets = ["Journey Together","Journey Together","Destined Rivals","Destined Rivals","Stellar Crown","Journey Together","Evolutions","Evolutions","Primal Clash","Primal Clash","Pokemon 151","Prismatic Evolutions", | |
| "Pokemon 151","Pokemon 151","Prismatic Evolutions","Paldea Evolved","White Flare","White Flare","Paradox Rift","Fates Collide","Evolutions","Evolutions","Next Destinies", | |
| "Base Set","Generations","Generations","XY","Arceus","Roaring Skies","BREAKpoint","EX Sandstorm","Ancient Origins","Double Crisis","McDonalds"] | |
| sets_un = np.unique(sets) | |
| print('unique sets:', sets_un) | |
| print(type(sets_un)) | |
| desired_order = ["Card", "Year", "Card Set", "Artwork Style", "Condition", "Market Value", "Set Number Eq"] | |
| for c in desired_order: | |
| input_names.append(c) | |
| if c=="Card": | |
| inputs.append(gr.Textbox(value="", label=c)) | |
| elif c=="Year": | |
| inputs.append(gr.Number(value=2021, precision=0, label=c)) | |
| elif c=="Card Set": | |
| inputs.append(gr.Dropdown(choices=sets_un.tolist(), value="Journey Together", label=c)) | |
| elif c=="Artwork Style": | |
| inputs.append(gr.Dropdown(choices=["Full Art", "Standard", "Holo", "Reverse Holo", "Full Art Gold", "Full Art Gold", "Promo"], value="Full Art", label=c)) | |
| elif c=="Condition": | |
| inputs.append(gr.Dropdown(choices=["Mint", "Near Mint", "Lightly Played", "Heavily Played"], value="Mint", label=c)) | |
| elif c=="Market Value": | |
| inputs.append(gr.Number(label=c, value=0.0)) | |
| elif c=="Set Number Eq": | |
| inputs.append(gr.Number(label=c, value = 0.0)) | |
| examples_dicts = [ | |
| { | |
| "Card": "Pikachu V", | |
| "Year": 2021, | |
| "Card Set": "Journey Together", | |
| "Artwork Style": "Full Art", | |
| "Condition": "Mint", | |
| "Market Value": 50.0, | |
| "Set Number Eq": 0.6 | |
| }, | |
| { | |
| "Card": "Charizard", | |
| "Year": 1999, | |
| "Card Set": "Base Set", | |
| "Artwork Style": "Holo", | |
| "Condition": "Near Mint", | |
| "Market Value": 12.0, | |
| "Set Number Eq": 1.4 | |
| } | |
| ] | |
| # Convert examples dicts into positional lists matching input_names | |
| examples = [[ex[name] for name in input_names] for ex in examples_dicts] | |
| def predict_record(*args): | |
| record = {name: val for name, val in zip(input_names, args)} | |
| df_in = pd.DataFrame([record]) | |
| return str(predictor.predict(df_in).iloc[0]) | |
| iface = gr.Interface( | |
| fn=predict_record, | |
| inputs=inputs, | |
| outputs=gr.Textbox(label="Is this card a collector's item?"), | |
| title="Pokémon Card Collector's Item Predictor (AutoGluon)", | |
| description="Predicts whether a Pokémon card is a collector's item.", | |
| examples=examples | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch() | |