Spaces:
Runtime error
Runtime error
alaahussein
commited on
Commit
•
994b90b
1
Parent(s):
cf3c35f
upload decision app
Browse files- wine_decision_app.py +84 -0
wine_decision_app.py
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Logic for calculating E-values
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
# Initialize the probabilities with Alejandro's initial beliefs
|
5 |
+
prob_storm = 0.5 # Probability of a storm
|
6 |
+
prob_norot_sweet = 0.6 # Probability of no sugar increase without storm
|
7 |
+
prob_typical_sweet = 0.3 # Probability of typical sugar increase without storm
|
8 |
+
prob_high_sweet = 0.1 # Probability of high sugar increase without storm
|
9 |
+
|
10 |
+
# E-Value without model to be used for comparison
|
11 |
+
e_value_without_model = 928500
|
12 |
+
|
13 |
+
# Logic for calculating E-values
|
14 |
+
def calculate_e_values(prob_storm, prob_botrytis, prob_norot_sweet, prob_typical_sweet, prob_high_sweet, sensitivity=0.83, specificity=0.87):
|
15 |
+
# Market revenues per bottle for each Riesling type
|
16 |
+
revenue_per_bottle = {
|
17 |
+
"Trocken": 5,
|
18 |
+
"Kabinett": 10,
|
19 |
+
"Spätlese": 15,
|
20 |
+
"Auslese": 30,
|
21 |
+
"Beerenauslese": 40,
|
22 |
+
"Trockenbeerenauslese": 120
|
23 |
+
}
|
24 |
+
|
25 |
+
# Number of cases produced under different scenarios
|
26 |
+
cases = {
|
27 |
+
"Harvest Now": {"Trocken": 6000, "Kabinett": 2000, "Spätlese": 2000},
|
28 |
+
"Storm-No Mold": {"Trocken": 5000, "Kabinett": 1000},
|
29 |
+
"Storm-Mold": {"Trockenbeerenauslese": 2000},
|
30 |
+
"No Storm-No Sugar": {"Trocken": 6000, "Kabinett": 2000, "Spätlese": 2000},
|
31 |
+
"No Storm-Typical Sugar": {"Trocken": 5000, "Kabinett": 1000, "Spätlese": 2500, "Auslese": 1500},
|
32 |
+
"No Storm-High Sugar": {"Trocken": 4000, "Kabinett": 2500, "Spätlese": 2000, "Auslese": 1000, "Beerenauslese": 500}
|
33 |
+
}
|
34 |
+
|
35 |
+
prob_storm_corrected = prob_storm * sensitivity + (1 - prob_storm) * (1 - specificity)
|
36 |
+
prob_no_storm_corrected = (1 - prob_storm) * specificity + prob_storm * (1 - sensitivity)
|
37 |
+
|
38 |
+
# Revenue calculations for different scenarios
|
39 |
+
storm_revenue = (prob_botrytis * cases["Storm-Mold"]["Trockenbeerenauslese"] * 12 * revenue_per_bottle["Trockenbeerenauslese"]) + \
|
40 |
+
((1 - prob_botrytis) * (cases["Storm-No Mold"]["Trocken"] * 12 * revenue_per_bottle["Trocken"] +
|
41 |
+
cases["Storm-No Mold"]["Kabinett"] * 12 * revenue_per_bottle["Kabinett"]))
|
42 |
+
|
43 |
+
no_sugar_revenue = cases["No Storm-No Sugar"]["Trocken"] * 12 * revenue_per_bottle["Trocken"] + \
|
44 |
+
cases["No Storm-No Sugar"]["Kabinett"] * 12 * revenue_per_bottle["Kabinett"] + \
|
45 |
+
cases["No Storm-No Sugar"]["Spätlese"] * 12 * revenue_per_bottle["Spätlese"]
|
46 |
+
|
47 |
+
typical_sugar_revenue = cases["No Storm-Typical Sugar"]["Trocken"] * 12 * revenue_per_bottle["Trocken"] + \
|
48 |
+
cases["No Storm-Typical Sugar"]["Kabinett"] * 12 * revenue_per_bottle["Kabinett"] + \
|
49 |
+
cases["No Storm-Typical Sugar"]["Spätlese"] * 12 * revenue_per_bottle["Spätlese"] + \
|
50 |
+
cases["No Storm-Typical Sugar"]["Auslese"] * 12 * revenue_per_bottle["Auslese"]
|
51 |
+
|
52 |
+
high_sugar_revenue = cases["No Storm-High Sugar"]["Trocken"] * 12 * revenue_per_bottle["Trocken"] + \
|
53 |
+
cases["No Storm-High Sugar"]["Kabinett"] * 12 * revenue_per_bottle["Kabinett"] + \
|
54 |
+
cases["No Storm-High Sugar"]["Spätlese"] * 12 * revenue_per_bottle["Spätlese"] + \
|
55 |
+
cases["No Storm-High Sugar"]["Auslese"] * 12 * revenue_per_bottle["Auslese"] + \
|
56 |
+
cases["No Storm-High Sugar"]["Beerenauslese"] * 12 * revenue_per_bottle["Beerenauslese"]
|
57 |
+
|
58 |
+
# Calculate the total revenue and determine the recommended action
|
59 |
+
total_revenue = (storm_revenue * prob_storm_corrected) + \
|
60 |
+
((no_sugar_revenue * prob_norot_sweet) +
|
61 |
+
(typical_sugar_revenue * prob_typical_sweet) +
|
62 |
+
(high_sugar_revenue * prob_high_sweet)) * prob_no_storm_corrected
|
63 |
+
|
64 |
+
e_value = total_revenue
|
65 |
+
recommended_action = "Wait" if total_revenue > 928500 else "Harvest Now"
|
66 |
+
|
67 |
+
return f"Expected Value (E-value) of the Decision: ${e_value}", f"Recommended Course of Action: {recommended_action}"
|
68 |
+
|
69 |
+
# Gradio interface setup
|
70 |
+
iface = gr.Interface(
|
71 |
+
fn=calculate_e_values,
|
72 |
+
inputs=[
|
73 |
+
gr.Slider(0, 1, step=0.01, label="Probability of Storm", value=prob_storm),
|
74 |
+
gr.Slider(0, 1, step=0.01, label="Probability of Botrytis if Storm", value=0.1),
|
75 |
+
gr.Slider(0, 1, step=0.01, label="Probability of No Sugar Increase", value=prob_norot_sweet),
|
76 |
+
gr.Slider(0, 1, step=0.01, label="Probability of Typical Sugar Increase", value=prob_typical_sweet),
|
77 |
+
gr.Slider(0, 1, step=0.01, label="Probability of High Sugar Increase", value=prob_high_sweet)
|
78 |
+
],
|
79 |
+
outputs=["text", "text"],
|
80 |
+
title="Wine Production Decision Model"
|
81 |
+
)
|
82 |
+
|
83 |
+
# Run the Gradio app
|
84 |
+
iface.launch(share=False)
|