Spaces:
Build error
Build error
File size: 2,346 Bytes
8237bc7 fd3b9fc 8237bc7 f9cd83b 8237bc7 4a54efa |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
import gradio as gr
import laa_core
import pandas as pd
def ski_rental_fn(buy_cost, current_day, prediction_days, trust, randomized=False):
"""Function to call the ski rental algorithm and format the output."""
try:
# Explicitly cast inputs to the correct types
buy_cost = float(buy_cost)
current_day = int(current_day)
prediction_days = float(prediction_days)
trust = float(trust)
if randomized:
algo = laa_core.RandomizedSkiRental(buy_cost)
algo_name = "Randomized Ski Rental"
else:
algo = laa_core.SkiRental(buy_cost)
algo_name = "Deterministic Ski Rental"
decision = algo.decide(current_day, prediction_days, trust)
decision_str = "Buy" if decision else "Rent"
return pd.DataFrame({
"Algorithm": [algo_name],
"Decision": [decision_str],
"Trust in Prediction": [trust]
})
except Exception as e:
return pd.DataFrame({"Error": [str(e)]})
with gr.Blocks(title="LAA Algorithms Demo") as demo:
gr.Markdown("# Learning-Augmented Algorithms Demo")
with gr.Tabs():
with gr.TabItem("Ski Rental"):
with gr.Row():
with gr.Column():
gr.Markdown("## Inputs")
buy_cost_input = gr.Slider(1, 1000, value=100, label="Buy Cost")
current_day_input = gr.Slider(1, 150, value=10, label="Current Day")
prediction_days_input = gr.Slider(1, 150, value=120, label="Predicted Ski Days")
trust_input = gr.Slider(0.0, 1.0, value=0.8, label="Trust in Prediction")
randomized_input = gr.Checkbox(label="Use Randomized Algorithm")
with gr.Column():
gr.Markdown("## Decision")
output_df = gr.DataFrame(headers=["Algorithm", "Decision", "Trust in Prediction"])
run_button = gr.Button("Run Algorithm")
run_button.click(
fn=ski_rental_fn,
inputs=[buy_cost_input, current_day_input, prediction_days_input, trust_input, randomized_input],
outputs=output_df
)
if __name__ == "__main__":
demo.launch(server_name="0.0.0.0", server_port=7860)
|