LOOFYYLO commited on
Commit
fd3b9fc
·
verified ·
1 Parent(s): b2f6f51

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +24 -15
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
- if randomized:
9
- algo = laa_core.RandomizedSkiRental(buy_cost)
10
- algo_name = "Randomized Ski Rental"
11
- else:
12
- algo = laa_core.SkiRental(buy_cost)
13
- algo_name = "Deterministic Ski Rental"
14
-
15
- decision = algo.decide(current_day, prediction_days, trust)
16
- decision_str = "Buy" if decision else "Rent"
17
-
18
- return pd.DataFrame({
19
- "Algorithm": [algo_name],
20
- "Decision": [decision_str],
21
- "Trust in Prediction": [trust]
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")