Commit
·
5db88df
1
Parent(s):
b310acb
Add grascii length limit
Browse files
search.py
CHANGED
|
@@ -11,6 +11,9 @@ from vision import run_vision
|
|
| 11 |
from save_image import save_image
|
| 12 |
|
| 13 |
|
|
|
|
|
|
|
|
|
|
| 14 |
@st.cache_data(show_spinner="Loading shorthand images")
|
| 15 |
def load_images():
|
| 16 |
ds = load_dataset(
|
|
@@ -43,7 +46,7 @@ def write_grascii_search():
|
|
| 43 |
placeholder = st.empty()
|
| 44 |
if search_by == "text":
|
| 45 |
placeholder.text_input(
|
| 46 |
-
"Grascii", value=st.session_state["grascii"], key="grascii_text_box"
|
| 47 |
)
|
| 48 |
else:
|
| 49 |
image_data = placeholder.file_uploader(
|
|
@@ -158,6 +161,10 @@ def write_grascii_search():
|
|
| 158 |
|
| 159 |
grascii = st.session_state["grascii"]
|
| 160 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
try:
|
| 162 |
grascii_results = searcher.sorted_search(
|
| 163 |
grascii=grascii,
|
|
|
|
| 11 |
from save_image import save_image
|
| 12 |
|
| 13 |
|
| 14 |
+
MAX_GRASCII_LENGTH = 16
|
| 15 |
+
|
| 16 |
+
|
| 17 |
@st.cache_data(show_spinner="Loading shorthand images")
|
| 18 |
def load_images():
|
| 19 |
ds = load_dataset(
|
|
|
|
| 46 |
placeholder = st.empty()
|
| 47 |
if search_by == "text":
|
| 48 |
placeholder.text_input(
|
| 49 |
+
"Grascii", value=st.session_state["grascii"], key="grascii_text_box", max_chars=MAX_GRASCII_LENGTH
|
| 50 |
)
|
| 51 |
else:
|
| 52 |
image_data = placeholder.file_uploader(
|
|
|
|
| 161 |
|
| 162 |
grascii = st.session_state["grascii"]
|
| 163 |
|
| 164 |
+
if len(grascii) > MAX_GRASCII_LENGTH:
|
| 165 |
+
st.error(f"Grascii too long. Max: {MAX_GRASCII_LENGTH} characters")
|
| 166 |
+
return
|
| 167 |
+
|
| 168 |
try:
|
| 169 |
grascii_results = searcher.sorted_search(
|
| 170 |
grascii=grascii,
|