Spaces:
Runtime error
Runtime error
hedtorresca
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -2,17 +2,28 @@ import gradio as gr
|
|
2 |
import matplotlib.pyplot as plt
|
3 |
import numpy as np
|
4 |
from matplotlib_venn import venn3
|
|
|
5 |
|
6 |
def calculate_probabilities(A, B, C, AB, AC, BC, ABC):
|
7 |
total = A + B + C - AB - AC - BC + ABC
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
-
P_A = A / total
|
10 |
-
P_B = B / total
|
11 |
-
P_C = C / total
|
12 |
-
P_AB = AB / total
|
13 |
-
P_AC = AC / total
|
14 |
-
P_BC = BC / total
|
15 |
-
P_ABC = ABC / total
|
16 |
|
17 |
return {
|
18 |
"P(A)": P_A,
|
@@ -28,12 +39,17 @@ def plot_venn(A, B, C, AB, AC, BC, ABC):
|
|
28 |
plt.figure(figsize=(8, 8))
|
29 |
venn = venn3(subsets=(A, B, AB, C, AC, BC, ABC), set_labels=('A', 'B', 'C'))
|
30 |
plt.title("Venn Diagram")
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
def main(A, B, C, AB, AC, BC, ABC):
|
34 |
-
plot_venn(A, B, C, AB, AC, BC, ABC)
|
35 |
probabilities = calculate_probabilities(A, B, C, AB, AC, BC, ABC)
|
36 |
-
return probabilities
|
37 |
|
38 |
iface = gr.Interface(
|
39 |
fn=main,
|
@@ -47,7 +63,7 @@ iface = gr.Interface(
|
|
47 |
gr.Number(label="Cantidad en A ∩ B ∩ C")
|
48 |
],
|
49 |
outputs=[
|
50 |
-
gr.
|
51 |
gr.JSON(label="Probabilidades Calculadas")
|
52 |
]
|
53 |
)
|
|
|
2 |
import matplotlib.pyplot as plt
|
3 |
import numpy as np
|
4 |
from matplotlib_venn import venn3
|
5 |
+
from io import BytesIO
|
6 |
|
7 |
def calculate_probabilities(A, B, C, AB, AC, BC, ABC):
|
8 |
total = A + B + C - AB - AC - BC + ABC
|
9 |
+
if total == 0:
|
10 |
+
return {
|
11 |
+
"P(A)": 0,
|
12 |
+
"P(B)": 0,
|
13 |
+
"P(C)": 0,
|
14 |
+
"P(A ∩ B)": 0,
|
15 |
+
"P(A ∩ C)": 0,
|
16 |
+
"P(B ∩ C)": 0,
|
17 |
+
"P(A ∩ B ∩ C)": 0,
|
18 |
+
}
|
19 |
|
20 |
+
P_A = A / total if total > 0 else 0
|
21 |
+
P_B = B / total if total > 0 else 0
|
22 |
+
P_C = C / total if total > 0 else 0
|
23 |
+
P_AB = AB / total if total > 0 else 0
|
24 |
+
P_AC = AC / total if total > 0 else 0
|
25 |
+
P_BC = BC / total if total > 0 else 0
|
26 |
+
P_ABC = ABC / total if total > 0 else 0
|
27 |
|
28 |
return {
|
29 |
"P(A)": P_A,
|
|
|
39 |
plt.figure(figsize=(8, 8))
|
40 |
venn = venn3(subsets=(A, B, AB, C, AC, BC, ABC), set_labels=('A', 'B', 'C'))
|
41 |
plt.title("Venn Diagram")
|
42 |
+
|
43 |
+
buf = BytesIO()
|
44 |
+
plt.savefig(buf, format='png')
|
45 |
+
buf.seek(0)
|
46 |
+
|
47 |
+
return buf
|
48 |
|
49 |
def main(A, B, C, AB, AC, BC, ABC):
|
50 |
+
venn_diagram = plot_venn(A, B, C, AB, AC, BC, ABC)
|
51 |
probabilities = calculate_probabilities(A, B, C, AB, AC, BC, ABC)
|
52 |
+
return venn_diagram, probabilities
|
53 |
|
54 |
iface = gr.Interface(
|
55 |
fn=main,
|
|
|
63 |
gr.Number(label="Cantidad en A ∩ B ∩ C")
|
64 |
],
|
65 |
outputs=[
|
66 |
+
gr.Image(type="plot", label="Diagrama de Venn"),
|
67 |
gr.JSON(label="Probabilidades Calculadas")
|
68 |
]
|
69 |
)
|