Spaces:
Sleeping
Sleeping
Yazhou Cao
commited on
Commit
·
bc524f4
1
Parent(s):
4c849c3
Tweak wordings
Browse files
app.py
CHANGED
|
@@ -31,7 +31,7 @@ def main():
|
|
| 31 |
if image_file_hand is not None:
|
| 32 |
preds = _run_inference(image_file_hand)
|
| 33 |
if len(preds) != 2:
|
| 34 |
-
_show_error_message(2, preds, image_file_hand, "
|
| 35 |
image_file_hand = None
|
| 36 |
return
|
| 37 |
st.session_state[_HAND] = preds, image_file_hand
|
|
@@ -41,19 +41,19 @@ def main():
|
|
| 41 |
if image_file_flop is not None:
|
| 42 |
preds = _run_inference(image_file_flop)
|
| 43 |
if len(preds) != 3:
|
| 44 |
-
_show_error_message(3, preds, image_file_flop, "
|
| 45 |
image_file_flop = None
|
| 46 |
return
|
| 47 |
st.session_state[_FLOP] = preds, image_file_flop
|
| 48 |
|
| 49 |
if _HAND not in st.session_state:
|
| 50 |
-
st.info("Please take a photo
|
| 51 |
return
|
| 52 |
if _FLOP not in st.session_state:
|
| 53 |
_show_predictions(*st.session_state[_HAND], "Your hand")
|
| 54 |
hand = [_convert_name(det.label_name) for det in st.session_state[_HAND][0]]
|
| 55 |
run_simulation(hand=hand)
|
| 56 |
-
st.info("Please take a photo
|
| 57 |
return
|
| 58 |
col1, col2 = st.columns(2)
|
| 59 |
with col1:
|
|
@@ -86,14 +86,14 @@ def _convert_name(name: str) -> str:
|
|
| 86 |
return f"{name[0].upper()}{name[1:].lower()}"
|
| 87 |
|
| 88 |
# TODO Rename this here and in `main`
|
| 89 |
-
def _show_error_message(
|
| 90 |
msg = (
|
| 91 |
-
f"{
|
| 92 |
-
if len(preds) <
|
| 93 |
-
else f"
|
| 94 |
)
|
| 95 |
st.error(msg)
|
| 96 |
-
_show_predictions(preds,
|
| 97 |
|
| 98 |
|
| 99 |
@st.cache_data
|
|
|
|
| 31 |
if image_file_hand is not None:
|
| 32 |
preds = _run_inference(image_file_hand)
|
| 33 |
if len(preds) != 2:
|
| 34 |
+
_show_error_message(2, preds, image_file_hand, "hand")
|
| 35 |
image_file_hand = None
|
| 36 |
return
|
| 37 |
st.session_state[_HAND] = preds, image_file_hand
|
|
|
|
| 41 |
if image_file_flop is not None:
|
| 42 |
preds = _run_inference(image_file_flop)
|
| 43 |
if len(preds) != 3:
|
| 44 |
+
_show_error_message(3, preds, image_file_flop, "flop")
|
| 45 |
image_file_flop = None
|
| 46 |
return
|
| 47 |
st.session_state[_FLOP] = preds, image_file_flop
|
| 48 |
|
| 49 |
if _HAND not in st.session_state:
|
| 50 |
+
st.info("Please take a photo of your hand.")
|
| 51 |
return
|
| 52 |
if _FLOP not in st.session_state:
|
| 53 |
_show_predictions(*st.session_state[_HAND], "Your hand")
|
| 54 |
hand = [_convert_name(det.label_name) for det in st.session_state[_HAND][0]]
|
| 55 |
run_simulation(hand=hand)
|
| 56 |
+
st.info("Please take a photo of the flop to continue.")
|
| 57 |
return
|
| 58 |
col1, col2 = st.columns(2)
|
| 59 |
with col1:
|
|
|
|
| 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 = (
|
| 91 |
+
f"Missing {expected_length - len(preds)} card in your {pred_name}. Please try again with a new photo."
|
| 92 |
+
if len(preds) < expected_length
|
| 93 |
+
else f"Detected more than {len(preds) - expected_length} card in your {pred_name}. Please try again with a new photo."
|
| 94 |
)
|
| 95 |
st.error(msg)
|
| 96 |
+
_show_predictions(preds, img_file, pred_name)
|
| 97 |
|
| 98 |
|
| 99 |
@st.cache_data
|