arvnoodle commited on
Commit
1968691
1 Parent(s): 41cfe8d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -0
app.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+
4
+ def simulate_success(num_simulations, success_rate_1, success_rate_2, cost_per_attempt_1, cost_per_attempt_2):
5
+ num_simulations = int(num_simulations) # Ensure num_simulations is an integer
6
+
7
+ def run_simulation(success_rate, cost_per_attempt):
8
+ # Simulating the outcomes
9
+ results = np.random.rand(num_simulations) < success_rate
10
+
11
+ # Counting the number of successes and failures
12
+ successes = np.sum(results)
13
+ failures = num_simulations - successes
14
+
15
+ # Calculating the total cost for successes and failures
16
+ total_success_cost = successes * cost_per_attempt
17
+ total_failure_cost = failures * cost_per_attempt
18
+
19
+ return successes, failures, total_success_cost, total_failure_cost
20
+
21
+ # Running the simulation for both options
22
+ successes_option_1, failures_option_1, success_cost_1, failure_cost_1 = run_simulation(success_rate_1, cost_per_attempt_1)
23
+ successes_option_2, failures_option_2, success_cost_2, failure_cost_2 = run_simulation(success_rate_2, cost_per_attempt_2)
24
+
25
+ # Formatting the output
26
+ output_1 = (
27
+ f"Option 1: {successes_option_1} successes, {failures_option_1} failures\n"
28
+ f"Total cost for successes: {success_cost_1} gold\n"
29
+ f"Total cost for failures: {failure_cost_1} gold\n"
30
+ f"Total cost overall: {success_cost_1 + failure_cost_1} gold"
31
+ )
32
+
33
+ output_2 = (
34
+ f"Option 2: {successes_option_2} successes, {failures_option_2} failures\n"
35
+ f"Total cost for successes: {success_cost_2} gold\n"
36
+ f"Total cost for failures: {failure_cost_2} gold\n"
37
+ f"Total cost overall: {success_cost_2 + failure_cost_2} gold"
38
+ )
39
+
40
+ return output_1, output_2
41
+
42
+ # Create Gradio interface
43
+ interface = gr.Interface(
44
+ fn=simulate_success,
45
+ inputs=[
46
+ gr.Number(label="Number of Simulations", value=30, precision=0),
47
+ gr.Slider(0.01, 1.0, step=0.01, label="Success Rate Option 1", value=0.10),
48
+ gr.Slider(0.01, 1.0, step=0.01, label="Success Rate Option 2", value=0.15),
49
+ gr.Number(label="Cost per Attempt Option 1", value=850, precision=0),
50
+ gr.Number(label="Cost per Attempt Option 2", value=1450, precision=0)
51
+ ],
52
+ outputs=[
53
+ gr.Textbox(label="Results for Option 1"),
54
+ gr.Textbox(label="Results for Option 2")
55
+ ],
56
+ title="Success Rate Simulation",
57
+ description="Simulate success and failure outcomes with different rates and costs."
58
+ )
59
+
60
+ # Launch the app with sharing option enabled
61
+ interface.launch()