Spaces:
Build error
Build error
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -5,21 +5,30 @@ import pandas as pd
|
|
| 5 |
|
| 6 |
def ski_rental_fn(buy_cost, current_day, prediction_days, trust, randomized=False):
|
| 7 |
"""Function to call the ski rental algorithm and format the output."""
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
with gr.Blocks(title="LAA Algorithms Demo") as demo:
|
| 25 |
gr.Markdown("# Learning-Augmented Algorithms Demo")
|
|
|
|
| 5 |
|
| 6 |
def ski_rental_fn(buy_cost, current_day, prediction_days, trust, randomized=False):
|
| 7 |
"""Function to call the ski rental algorithm and format the output."""
|
| 8 |
+
try:
|
| 9 |
+
# Explicitly cast inputs to the correct types
|
| 10 |
+
buy_cost = float(buy_cost)
|
| 11 |
+
current_day = int(current_day)
|
| 12 |
+
prediction_days = float(prediction_days)
|
| 13 |
+
trust = float(trust)
|
| 14 |
+
|
| 15 |
+
if randomized:
|
| 16 |
+
algo = laa_core.RandomizedSkiRental(buy_cost)
|
| 17 |
+
algo_name = "Randomized Ski Rental"
|
| 18 |
+
else:
|
| 19 |
+
algo = laa_core.SkiRental(buy_cost)
|
| 20 |
+
algo_name = "Deterministic Ski Rental"
|
| 21 |
+
|
| 22 |
+
decision = algo.decide(current_day, prediction_days, trust)
|
| 23 |
+
decision_str = "Buy" if decision else "Rent"
|
| 24 |
+
|
| 25 |
+
return pd.DataFrame({
|
| 26 |
+
"Algorithm": [algo_name],
|
| 27 |
+
"Decision": [decision_str],
|
| 28 |
+
"Trust in Prediction": [trust]
|
| 29 |
+
})
|
| 30 |
+
except Exception as e:
|
| 31 |
+
return pd.DataFrame({"Error": [str(e)]})
|
| 32 |
|
| 33 |
with gr.Blocks(title="LAA Algorithms Demo") as demo:
|
| 34 |
gr.Markdown("# Learning-Augmented Algorithms Demo")
|