File size: 2,591 Bytes
1968691
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
60
61
62
import gradio as gr
import numpy as np

def simulate_success(num_simulations, success_rate_1, success_rate_2, cost_per_attempt_1, cost_per_attempt_2):
    num_simulations = int(num_simulations)  # Ensure num_simulations is an integer

    def run_simulation(success_rate, cost_per_attempt):
        # Simulating the outcomes
        results = np.random.rand(num_simulations) < success_rate
        
        # Counting the number of successes and failures
        successes = np.sum(results)
        failures = num_simulations - successes
        
        # Calculating the total cost for successes and failures
        total_success_cost = successes * cost_per_attempt
        total_failure_cost = failures * cost_per_attempt
        
        return successes, failures, total_success_cost, total_failure_cost
    
    # Running the simulation for both options
    successes_option_1, failures_option_1, success_cost_1, failure_cost_1 = run_simulation(success_rate_1, cost_per_attempt_1)
    successes_option_2, failures_option_2, success_cost_2, failure_cost_2 = run_simulation(success_rate_2, cost_per_attempt_2)
    
    # Formatting the output
    output_1 = (
        f"Option 1: {successes_option_1} successes, {failures_option_1} failures\n"
        f"Total cost for successes: {success_cost_1} gold\n"
        f"Total cost for failures: {failure_cost_1} gold\n"
        f"Total cost overall: {success_cost_1 + failure_cost_1} gold"
    )
    
    output_2 = (
        f"Option 2: {successes_option_2} successes, {failures_option_2} failures\n"
        f"Total cost for successes: {success_cost_2} gold\n"
        f"Total cost for failures: {failure_cost_2} gold\n"
        f"Total cost overall: {success_cost_2 + failure_cost_2} gold"
    )
    
    return output_1, output_2

# Create Gradio interface
interface = gr.Interface(
    fn=simulate_success,
    inputs=[
        gr.Number(label="Number of Simulations", value=30, precision=0),
        gr.Slider(0.01, 1.0, step=0.01, label="Success Rate Option 1", value=0.10),
        gr.Slider(0.01, 1.0, step=0.01, label="Success Rate Option 2", value=0.15),
        gr.Number(label="Cost per Attempt Option 1", value=850, precision=0),
        gr.Number(label="Cost per Attempt Option 2", value=1450, precision=0)
    ],
    outputs=[
        gr.Textbox(label="Results for Option 1"),
        gr.Textbox(label="Results for Option 2")
    ],
    title="Success Rate Simulation",
    description="Simulate success and failure outcomes with different rates and costs."
)

# Launch the app with sharing option enabled
interface.launch()