Spaces:
Sleeping
Sleeping
Commit
·
187e2a5
1
Parent(s):
5256800
feat: Refine Gradio UI and improve model card
Browse files
app.py
CHANGED
|
@@ -40,7 +40,6 @@ def perform_prediction(model: torch.nn.Module, scaler, input_features: pd.Series
|
|
| 40 |
|
| 41 |
return predicted_class, probability
|
| 42 |
|
| 43 |
-
# --- Asset Loading ---
|
| 44 |
try:
|
| 45 |
model, feature_columns = load_model_and_config(MODEL_DIR)
|
| 46 |
scaler = joblib.load(SCALER_PATH)
|
|
@@ -59,18 +58,15 @@ def predict_price_trend(card_identifier: str) -> str:
|
|
| 59 |
if not card_identifier or not card_identifier.strip().isdigit():
|
| 60 |
return "## Input Error\nPlease enter a valid, numeric TCGPlayer ID."
|
| 61 |
|
| 62 |
-
# --- Find Card Logic ---
|
| 63 |
card_id = int(card_identifier.strip())
|
| 64 |
card_data = full_data[full_data['tcgplayer_id'] == card_id]
|
| 65 |
|
| 66 |
if card_data.empty:
|
| 67 |
return f"## Card Not Found\nCould not find a card with TCGPlayer ID '{card_id}'. Please check the ID and try again."
|
| 68 |
|
| 69 |
-
# Since tcgplayer_id is unique, we can safely take the first (and only) row.
|
| 70 |
card_sample = card_data.iloc[0]
|
| 71 |
sample_features = card_sample[feature_columns]
|
| 72 |
|
| 73 |
-
# --- Prediction Logic ---
|
| 74 |
predicted_class, probability = perform_prediction(model, scaler, sample_features)
|
| 75 |
|
| 76 |
prediction_text = "**RISE**" if predicted_class else "**NOT RISE**"
|
|
@@ -78,14 +74,13 @@ def predict_price_trend(card_identifier: str) -> str:
|
|
| 78 |
tcgplayer_id = card_sample['tcgplayer_id']
|
| 79 |
tcgplayer_link = f"https://www.tcgplayer.com/product/{tcgplayer_id}?Language=English"
|
| 80 |
|
| 81 |
-
# --- Output Formatting ---
|
| 82 |
true_label_text = ""
|
| 83 |
try:
|
| 84 |
if TARGET_COLUMN in card_sample and pd.notna(card_sample[TARGET_COLUMN]):
|
| 85 |
true_label = bool(card_sample[TARGET_COLUMN])
|
| 86 |
true_label_text = f"\n- **Actual Result in Dataset:** The price did **{'RISE' if true_label else 'NOT RISE'}**."
|
| 87 |
except (KeyError, TypeError):
|
| 88 |
-
pass
|
| 89 |
|
| 90 |
output = f"""
|
| 91 |
## 🔮 Prediction Report for {card_sample['name']}
|
|
@@ -97,7 +92,6 @@ def predict_price_trend(card_identifier: str) -> str:
|
|
| 97 |
return output
|
| 98 |
|
| 99 |
|
| 100 |
-
# --- Gradio UI ---
|
| 101 |
with gr.Blocks(theme=gr.themes.Soft(), title="PricePoke Predictor") as demo:
|
| 102 |
gr.Markdown(
|
| 103 |
"""
|
|
|
|
| 40 |
|
| 41 |
return predicted_class, probability
|
| 42 |
|
|
|
|
| 43 |
try:
|
| 44 |
model, feature_columns = load_model_and_config(MODEL_DIR)
|
| 45 |
scaler = joblib.load(SCALER_PATH)
|
|
|
|
| 58 |
if not card_identifier or not card_identifier.strip().isdigit():
|
| 59 |
return "## Input Error\nPlease enter a valid, numeric TCGPlayer ID."
|
| 60 |
|
|
|
|
| 61 |
card_id = int(card_identifier.strip())
|
| 62 |
card_data = full_data[full_data['tcgplayer_id'] == card_id]
|
| 63 |
|
| 64 |
if card_data.empty:
|
| 65 |
return f"## Card Not Found\nCould not find a card with TCGPlayer ID '{card_id}'. Please check the ID and try again."
|
| 66 |
|
|
|
|
| 67 |
card_sample = card_data.iloc[0]
|
| 68 |
sample_features = card_sample[feature_columns]
|
| 69 |
|
|
|
|
| 70 |
predicted_class, probability = perform_prediction(model, scaler, sample_features)
|
| 71 |
|
| 72 |
prediction_text = "**RISE**" if predicted_class else "**NOT RISE**"
|
|
|
|
| 74 |
tcgplayer_id = card_sample['tcgplayer_id']
|
| 75 |
tcgplayer_link = f"https://www.tcgplayer.com/product/{tcgplayer_id}?Language=English"
|
| 76 |
|
|
|
|
| 77 |
true_label_text = ""
|
| 78 |
try:
|
| 79 |
if TARGET_COLUMN in card_sample and pd.notna(card_sample[TARGET_COLUMN]):
|
| 80 |
true_label = bool(card_sample[TARGET_COLUMN])
|
| 81 |
true_label_text = f"\n- **Actual Result in Dataset:** The price did **{'RISE' if true_label else 'NOT RISE'}**."
|
| 82 |
except (KeyError, TypeError):
|
| 83 |
+
pass
|
| 84 |
|
| 85 |
output = f"""
|
| 86 |
## 🔮 Prediction Report for {card_sample['name']}
|
|
|
|
| 92 |
return output
|
| 93 |
|
| 94 |
|
|
|
|
| 95 |
with gr.Blocks(theme=gr.themes.Soft(), title="PricePoke Predictor") as demo:
|
| 96 |
gr.Markdown(
|
| 97 |
"""
|