Yazhou Cao commited on
Commit
4b44dc1
Β·
1 Parent(s): bc524f4

More polish and change camera input widget

Browse files
Files changed (3) hide show
  1. app.py +15 -8
  2. holdem.py +3 -2
  3. poker_functions.py +11 -0
app.py CHANGED
@@ -1,7 +1,6 @@
1
  import logging
2
  from typing import List
3
 
4
- import numpy as np
5
  import streamlit as st
6
  from landingai.common import Prediction
7
  from landingai.predict import Predictor
@@ -9,8 +8,8 @@ from landingai.st_utils import render_svg, setup_page
9
  from landingai.visualize import overlay_predictions
10
  from PIL import Image
11
 
12
- from holdem import run_simulation
13
  import simulation as s
 
14
 
15
  setup_page(page_title="LandingLens Holdem Odds Calculator")
16
 
@@ -26,8 +25,8 @@ def main():
26
  # image_file = st.camera_input("Camera View")
27
  tab1, tab2 = st.tabs(["Your hand", "Flop"])
28
  with tab1:
29
- # image_file_hand = st.file_uploader("Your hand")
30
- image_file_hand = image_file = st.camera_input("Your hand")
31
  if image_file_hand is not None:
32
  preds = _run_inference(image_file_hand)
33
  if len(preds) != 2:
@@ -36,8 +35,8 @@ def main():
36
  return
37
  st.session_state[_HAND] = preds, image_file_hand
38
  with tab2:
39
- # image_file_flop = st.file_uploader("Flop")
40
- image_file_flop = image_file = st.camera_input(label="Flop")
41
  if image_file_flop is not None:
42
  preds = _run_inference(image_file_flop)
43
  if len(preds) != 3:
@@ -66,15 +65,22 @@ def main():
66
  if not _validate_cards(hand, flop):
67
  return
68
  run_simulation(hand=hand, flop=flop)
 
 
69
 
70
 
71
  def _validate_cards(hand, flop) -> bool:
72
  check = hand + flop
73
  if s.dedup(check):
74
- st.error("There is a duplicate card. Please check the board and your hand and try again.", icon="🚨")
 
 
 
75
  return False
76
  if not s.validate_card(check):
77
- st.error("At least one of your cards is not valid. Please try again.", icon="🚨")
 
 
78
  return False
79
  return True
80
 
@@ -85,6 +91,7 @@ def _convert_name(name: str) -> str:
85
  else:
86
  return f"{name[0].upper()}{name[1:].lower()}"
87
 
 
88
  # TODO Rename this here and in `main`
89
  def _show_error_message(expected_length, preds, img_file, pred_name):
90
  msg = (
 
1
  import logging
2
  from typing import List
3
 
 
4
  import streamlit as st
5
  from landingai.common import Prediction
6
  from landingai.predict import Predictor
 
8
  from landingai.visualize import overlay_predictions
9
  from PIL import Image
10
 
 
11
  import simulation as s
12
+ from holdem import run_simulation
13
 
14
  setup_page(page_title="LandingLens Holdem Odds Calculator")
15
 
 
25
  # image_file = st.camera_input("Camera View")
26
  tab1, tab2 = st.tabs(["Your hand", "Flop"])
27
  with tab1:
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 = _run_inference(image_file_hand)
32
  if len(preds) != 2:
 
35
  return
36
  st.session_state[_HAND] = preds, image_file_hand
37
  with tab2:
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 = _run_inference(image_file_flop)
42
  if len(preds) != 3:
 
65
  if not _validate_cards(hand, flop):
66
  return
67
  run_simulation(hand=hand, flop=flop)
68
+ st.divider()
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:
73
  check = hand + flop
74
  if s.dedup(check):
75
+ st.error(
76
+ "There is a duplicate card. Please check the board and your hand and try again.",
77
+ icon="🚨",
78
+ )
79
  return False
80
  if not s.validate_card(check):
81
+ st.error(
82
+ "At least one of your cards is not valid. Please try again.", icon="🚨"
83
+ )
84
  return False
85
  return True
86
 
 
91
  else:
92
  return f"{name[0].upper()}{name[1:].lower()}"
93
 
94
+
95
  # TODO Rename this here and in `main`
96
  def _show_error_message(expected_length, preds, img_file, pred_name):
97
  msg = (
holdem.py CHANGED
@@ -1,4 +1,5 @@
1
  from prettytable import PrettyTable
 
2
  import simulation as s
3
  import streamlit as st
4
 
@@ -30,7 +31,7 @@ def run_simulation(
30
  strt_flush_pct = s.percent(sim[9], sim[0])
31
  strt_flush_ratio = s.ratio(sim[9], sim[0])
32
 
33
- hole_card_str = f"{hand[0]} {hand[1]}"
34
 
35
  table = PrettyTable()
36
  table.field_names = ["Your Hand", "Board"]
@@ -40,7 +41,7 @@ def run_simulation(
40
  turn = []
41
  if river is None:
42
  river = []
43
- board_str = "".join(f"{card} " for card in (flop + turn + river))
44
  table.add_row([hole_card_str, board_str])
45
 
46
  odds = PrettyTable()
 
1
  from prettytable import PrettyTable
2
+ from poker_functions import Card
3
  import simulation as s
4
  import streamlit as st
5
 
 
31
  strt_flush_pct = s.percent(sim[9], sim[0])
32
  strt_flush_ratio = s.ratio(sim[9], sim[0])
33
 
34
+ hole_card_str = f"{Card(hand[0]).pretty_name} {Card(hand[1]).pretty_name}"
35
 
36
  table = PrettyTable()
37
  table.field_names = ["Your Hand", "Board"]
 
41
  turn = []
42
  if river is None:
43
  river = []
44
+ board_str = "".join(f"{Card(card).pretty_name} " for card in (flop + turn + river))
45
  table.add_row([hole_card_str, board_str])
46
 
47
  odds = PrettyTable()
poker_functions.py CHANGED
@@ -33,6 +33,17 @@ class Card:
33
  def __str__(self):
34
  return self.name
35
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  def __getitem__(self, item):
38
  if item == 'rank':
 
33
  def __str__(self):
34
  return self.name
35
 
36
+ @property
37
+ def pretty_name(self):
38
+ rank = '10' if self.rank == 'T' else self.rank
39
+ suit_map = {
40
+ "c": "♣",
41
+ "d": "♦",
42
+ "h": "β™₯",
43
+ "s": "β™ ",
44
+ }
45
+ return f'{rank}{suit_map[self.suit]}'
46
+
47
 
48
  def __getitem__(self, item):
49
  if item == 'rank':