Spaces:
Sleeping
Sleeping
Yazhou Cao
commited on
Commit
·
af9639c
1
Parent(s):
4b44dc1
Minor tweaks
Browse files
app.py
CHANGED
@@ -28,7 +28,7 @@ def main():
|
|
28 |
image_file_hand = st.file_uploader("Your hand")
|
29 |
# image_file_hand = image_file = st.camera_input("Your hand")
|
30 |
if image_file_hand is not None:
|
31 |
-
preds =
|
32 |
if len(preds) != 2:
|
33 |
_show_error_message(2, preds, image_file_hand, "hand")
|
34 |
image_file_hand = None
|
@@ -38,7 +38,7 @@ def main():
|
|
38 |
image_file_flop = st.file_uploader("Flop")
|
39 |
# image_file_flop = image_file = st.camera_input(label="Flop")
|
40 |
if image_file_flop is not None:
|
41 |
-
preds =
|
42 |
if len(preds) != 3:
|
43 |
_show_error_message(3, preds, image_file_flop, "flop")
|
44 |
image_file_flop = None
|
@@ -65,8 +65,7 @@ def main():
|
|
65 |
if not _validate_cards(hand, flop):
|
66 |
return
|
67 |
run_simulation(hand=hand, flop=flop)
|
68 |
-
st.
|
69 |
-
st.write("Interested in building more Computer Vision applications? Check out the [LandingLens](https://landing.ai/) platform and our [open source Python SDK](https://github.com/landing-ai/landingai-python)!")
|
70 |
|
71 |
|
72 |
def _validate_cards(hand, flop) -> bool:
|
@@ -93,18 +92,14 @@ def _convert_name(name: str) -> str:
|
|
93 |
|
94 |
|
95 |
# TODO Rename this here and in `main`
|
96 |
-
def _show_error_message(
|
97 |
-
msg = (
|
98 |
-
f"Missing {expected_length - len(preds)} card in your {pred_name}. Please try again with a new photo."
|
99 |
-
if len(preds) < expected_length
|
100 |
-
else f"Detected more than {len(preds) - expected_length} card in your {pred_name}. Please try again with a new photo."
|
101 |
-
)
|
102 |
st.error(msg)
|
103 |
_show_predictions(preds, img_file, pred_name)
|
104 |
|
105 |
|
106 |
@st.cache_data
|
107 |
-
def
|
108 |
image = Image.open(image_file).convert("RGB")
|
109 |
predictor = Predictor(endpoint_id="ecab49f5-9047-4d5a-8c92-b7ad8e908324")
|
110 |
logging.info("Running Poker prediction")
|
|
|
28 |
image_file_hand = st.file_uploader("Your hand")
|
29 |
# image_file_hand = image_file = st.camera_input("Your hand")
|
30 |
if image_file_hand is not None:
|
31 |
+
preds = inference(image_file_hand)
|
32 |
if len(preds) != 2:
|
33 |
_show_error_message(2, preds, image_file_hand, "hand")
|
34 |
image_file_hand = None
|
|
|
38 |
image_file_flop = st.file_uploader("Flop")
|
39 |
# image_file_flop = image_file = st.camera_input(label="Flop")
|
40 |
if image_file_flop is not None:
|
41 |
+
preds = inference(image_file_flop)
|
42 |
if len(preds) != 3:
|
43 |
_show_error_message(3, preds, image_file_flop, "flop")
|
44 |
image_file_flop = None
|
|
|
65 |
if not _validate_cards(hand, flop):
|
66 |
return
|
67 |
run_simulation(hand=hand, flop=flop)
|
68 |
+
st.write("Interested in building more Computer Vision applications? Check out our [LandingLens](https://landing.ai/) platform and our [open source Python SDK](https://github.com/landing-ai/landingai-python)!")
|
|
|
69 |
|
70 |
|
71 |
def _validate_cards(hand, flop) -> bool:
|
|
|
92 |
|
93 |
|
94 |
# TODO Rename this here and in `main`
|
95 |
+
def _show_error_message(expected_len, preds, img_file, pred_name):
|
96 |
+
msg = f"Detected {len(preds)}, expects {expected_len} cards in your {pred_name}. Please try again with a new photo."
|
|
|
|
|
|
|
|
|
97 |
st.error(msg)
|
98 |
_show_predictions(preds, img_file, pred_name)
|
99 |
|
100 |
|
101 |
@st.cache_data
|
102 |
+
def inference(image_file) -> List[Prediction]:
|
103 |
image = Image.open(image_file).convert("RGB")
|
104 |
predictor = Predictor(endpoint_id="ecab49f5-9047-4d5a-8c92-b7ad8e908324")
|
105 |
logging.info("Running Poker prediction")
|
holdem.py
CHANGED
@@ -1,7 +1,8 @@
|
|
|
|
1 |
from prettytable import PrettyTable
|
2 |
-
|
3 |
import simulation as s
|
4 |
-
|
5 |
|
6 |
|
7 |
def run_simulation(
|
@@ -9,9 +10,9 @@ def run_simulation(
|
|
9 |
flop: list[str] = None,
|
10 |
turn: list[str] = None,
|
11 |
river: list[str] = None,
|
12 |
-
sims=
|
13 |
) -> None:
|
14 |
-
sim = s.simulation_one_player(hand, flop, turn, river, sims)
|
15 |
hc_pct = s.percent(sim[1], sim[0])
|
16 |
hc_ratio = s.ratio(sim[1], sim[0])
|
17 |
pair_pct = s.percent(sim[2], sim[0])
|
@@ -94,5 +95,6 @@ def run_simulation(
|
|
94 |
st.write(odds, "\n")
|
95 |
st.divider()
|
96 |
|
|
|
97 |
if __name__ == "__main__":
|
98 |
-
run_simulation(["As", "Ah"], ["2s", "3s", "4s"], sims=
|
|
|
1 |
+
import streamlit as st
|
2 |
from prettytable import PrettyTable
|
3 |
+
|
4 |
import simulation as s
|
5 |
+
from poker_functions import Card
|
6 |
|
7 |
|
8 |
def run_simulation(
|
|
|
10 |
flop: list[str] = None,
|
11 |
turn: list[str] = None,
|
12 |
river: list[str] = None,
|
13 |
+
sims=10000,
|
14 |
) -> None:
|
15 |
+
sim = s.simulation_one_player(hand, flop, turn, river, sims=sims)
|
16 |
hc_pct = s.percent(sim[1], sim[0])
|
17 |
hc_ratio = s.ratio(sim[1], sim[0])
|
18 |
pair_pct = s.percent(sim[2], sim[0])
|
|
|
95 |
st.write(odds, "\n")
|
96 |
st.divider()
|
97 |
|
98 |
+
|
99 |
if __name__ == "__main__":
|
100 |
+
run_simulation(["As", "Ah"], ["2s", "3s", "4s"], sims=4000)
|