oh-my-dear-ai
commited on
Commit
•
fbb4dba
1
Parent(s):
24c4f11
fix(app): correct task checklist generation and update token handling
Browse files- Fix the logic to include only tasks with a value of 1 from the parsed dictionary.
- Remove unnecessary null check from the task checklist generation logic.
- Update the recovery token input to reflect changes in the checklist generation function.
- Ensure proper component initialization within the Gradio Blocks context.
- Streamline the submit button click function to process data and update UI components.
- Update dependency management to include `pytest` and fix `iniconfig` and `pluggy` versions.
- app.py +67 -69
- poetry.lock +47 -1
- pyproject.toml +1 -0
- requirements.txt +0 -0
- test_token.py +9 -0
app.py
CHANGED
@@ -120,9 +120,7 @@ def show_checkbox_groups(token):
|
|
120 |
tasks,
|
121 |
label=f"{row['name']}",
|
122 |
value=[
|
123 |
-
tasks[i]
|
124 |
-
for i, v in enumerate(parsed_dict[row["plant"]])
|
125 |
-
if v == 1 and df.notnull().at[index, TASKS[i]]
|
126 |
],
|
127 |
type="index",
|
128 |
)
|
@@ -336,81 +334,81 @@ def generate_img_by_plotly(df):
|
|
336 |
return image
|
337 |
|
338 |
|
339 |
-
|
340 |
-
gr.
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
|
|
346 |
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
|
379 |
-
|
380 |
|
381 |
-
|
382 |
|
383 |
-
|
384 |
|
385 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
386 |
"""
|
387 |
-
|
388 |
-
- 2024/08/31: Initial release
|
389 |
-
- 2024/09/03: Fix a mistake in the tasks of mimbulus
|
390 |
-
- 2024/09/04: Correct Radiant count for water hyacinth
|
391 |
-
- 2024/09/05: Support image generated by plotly
|
392 |
-
- 2024/09/13: Update Water Lily tasks and color options
|
393 |
-
"""
|
394 |
-
)
|
395 |
-
|
396 |
-
submit_button.click(
|
397 |
-
process_data,
|
398 |
-
inputs=checklist_inputs + [plot_library],
|
399 |
-
outputs=[generated_img, recovery_token],
|
400 |
-
)
|
401 |
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
|
|
|
|
|
|
|
|
|
|
|
414 |
|
415 |
-
app.queue()
|
416 |
-
app.launch()
|
|
|
120 |
tasks,
|
121 |
label=f"{row['name']}",
|
122 |
value=[
|
123 |
+
tasks[i] for i, v in enumerate(parsed_dict[row["plant"]]) if v == 1
|
|
|
|
|
124 |
],
|
125 |
type="index",
|
126 |
)
|
|
|
334 |
return image
|
335 |
|
336 |
|
337 |
+
if __name__ == "__main__":
|
338 |
+
with gr.Blocks() as app:
|
339 |
+
gr.Markdown(
|
340 |
+
"""
|
341 |
+
<center><font size=8>👩🏻🌾Herbology Almanac Checklist Generator📝</font></center>
|
342 |
+
This is a simple web app that generates an almanac checklist for your plants.
|
343 |
+
"""
|
344 |
+
)
|
345 |
|
346 |
+
gr.Markdown(
|
347 |
+
"""
|
348 |
+
# RECOVERY TOKEN
|
349 |
+
"""
|
350 |
+
)
|
351 |
+
recovery_token = gr.Textbox(
|
352 |
+
value="",
|
353 |
+
label="Recovery Token",
|
354 |
+
info="Save this token or paste your saved one here",
|
355 |
+
placeholder="Keep this token to restore your previous input".upper(),
|
356 |
+
interactive=True,
|
357 |
+
)
|
358 |
|
359 |
+
gr.Markdown(
|
360 |
+
"""
|
361 |
+
# YOUR RESEARCH TASKS
|
362 |
+
"""
|
363 |
+
)
|
364 |
+
checklist_inputs = show_checkbox_groups(recovery_token.value)
|
365 |
|
366 |
+
gr.Markdown(
|
367 |
+
"""
|
368 |
+
# IMAGE STYLE
|
369 |
+
"""
|
370 |
+
)
|
371 |
+
plot_library = gr.Radio(
|
372 |
+
["plotly", "matplotlib"],
|
373 |
+
label="Plot Library",
|
374 |
+
value="plotly",
|
375 |
+
info="Choose your plot library",
|
376 |
+
)
|
377 |
|
378 |
+
submit_button = gr.Button("Generate Image and Token")
|
379 |
|
380 |
+
# df_out = gr.Dataframe(label="Output Dataframe", interactive=False)
|
381 |
|
382 |
+
generated_img = gr.Image(label="Generated Image", format="png", type="pil")
|
383 |
|
384 |
+
logs = gr.Markdown(
|
385 |
+
"""
|
386 |
+
# CHANGELOG
|
387 |
+
- 2024/08/31: Initial release
|
388 |
+
- 2024/09/03: Fix a mistake in the tasks of mimbulus
|
389 |
+
- 2024/09/04: Correct Radiant count for water hyacinth
|
390 |
+
- 2024/09/05: Support image generated by plotly
|
391 |
+
- 2024/09/13: Update Water Lily tasks and color options
|
392 |
"""
|
393 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
394 |
|
395 |
+
submit_button.click(
|
396 |
+
process_data,
|
397 |
+
inputs=checklist_inputs + [plot_library],
|
398 |
+
outputs=[generated_img, recovery_token],
|
399 |
+
)
|
400 |
|
401 |
+
recovery_token.change(
|
402 |
+
show_checkbox_groups,
|
403 |
+
inputs=[recovery_token],
|
404 |
+
outputs=checklist_inputs,
|
405 |
+
)
|
406 |
|
407 |
+
# generate_button.click(
|
408 |
+
# generate_img,
|
409 |
+
# inputs=[df_out],
|
410 |
+
# outputs=[generated_img],
|
411 |
+
# )
|
412 |
|
413 |
+
app.queue()
|
414 |
+
app.launch()
|
poetry.lock
CHANGED
@@ -652,6 +652,17 @@ enabler = ["pytest-enabler (>=2.2)"]
|
|
652 |
test = ["jaraco.test (>=5.4)", "pytest (>=6,!=8.1.*)", "zipp (>=3.17)"]
|
653 |
type = ["pytest-mypy"]
|
654 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
655 |
[[package]]
|
656 |
name = "jinja2"
|
657 |
version = "3.1.4"
|
@@ -1333,6 +1344,21 @@ files = [
|
|
1333 |
packaging = "*"
|
1334 |
tenacity = ">=6.2.0"
|
1335 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1336 |
[[package]]
|
1337 |
name = "pydantic"
|
1338 |
version = "2.8.2"
|
@@ -1495,6 +1521,26 @@ files = [
|
|
1495 |
[package.extras]
|
1496 |
diagrams = ["jinja2", "railroad-diagrams"]
|
1497 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1498 |
[[package]]
|
1499 |
name = "python-dateutil"
|
1500 |
version = "2.9.0.post0"
|
@@ -2056,4 +2102,4 @@ files = [
|
|
2056 |
[metadata]
|
2057 |
lock-version = "2.0"
|
2058 |
python-versions = "^3.12"
|
2059 |
-
content-hash = "
|
|
|
652 |
test = ["jaraco.test (>=5.4)", "pytest (>=6,!=8.1.*)", "zipp (>=3.17)"]
|
653 |
type = ["pytest-mypy"]
|
654 |
|
655 |
+
[[package]]
|
656 |
+
name = "iniconfig"
|
657 |
+
version = "2.0.0"
|
658 |
+
description = "brain-dead simple config-ini parsing"
|
659 |
+
optional = false
|
660 |
+
python-versions = ">=3.7"
|
661 |
+
files = [
|
662 |
+
{file = "iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"},
|
663 |
+
{file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"},
|
664 |
+
]
|
665 |
+
|
666 |
[[package]]
|
667 |
name = "jinja2"
|
668 |
version = "3.1.4"
|
|
|
1344 |
packaging = "*"
|
1345 |
tenacity = ">=6.2.0"
|
1346 |
|
1347 |
+
[[package]]
|
1348 |
+
name = "pluggy"
|
1349 |
+
version = "1.5.0"
|
1350 |
+
description = "plugin and hook calling mechanisms for python"
|
1351 |
+
optional = false
|
1352 |
+
python-versions = ">=3.8"
|
1353 |
+
files = [
|
1354 |
+
{file = "pluggy-1.5.0-py3-none-any.whl", hash = "sha256:44e1ad92c8ca002de6377e165f3e0f1be63266ab4d554740532335b9d75ea669"},
|
1355 |
+
{file = "pluggy-1.5.0.tar.gz", hash = "sha256:2cffa88e94fdc978c4c574f15f9e59b7f4201d439195c3715ca9e2486f1d0cf1"},
|
1356 |
+
]
|
1357 |
+
|
1358 |
+
[package.extras]
|
1359 |
+
dev = ["pre-commit", "tox"]
|
1360 |
+
testing = ["pytest", "pytest-benchmark"]
|
1361 |
+
|
1362 |
[[package]]
|
1363 |
name = "pydantic"
|
1364 |
version = "2.8.2"
|
|
|
1521 |
[package.extras]
|
1522 |
diagrams = ["jinja2", "railroad-diagrams"]
|
1523 |
|
1524 |
+
[[package]]
|
1525 |
+
name = "pytest"
|
1526 |
+
version = "8.3.3"
|
1527 |
+
description = "pytest: simple powerful testing with Python"
|
1528 |
+
optional = false
|
1529 |
+
python-versions = ">=3.8"
|
1530 |
+
files = [
|
1531 |
+
{file = "pytest-8.3.3-py3-none-any.whl", hash = "sha256:a6853c7375b2663155079443d2e45de913a911a11d669df02a50814944db57b2"},
|
1532 |
+
{file = "pytest-8.3.3.tar.gz", hash = "sha256:70b98107bd648308a7952b06e6ca9a50bc660be218d53c257cc1fc94fda10181"},
|
1533 |
+
]
|
1534 |
+
|
1535 |
+
[package.dependencies]
|
1536 |
+
colorama = {version = "*", markers = "sys_platform == \"win32\""}
|
1537 |
+
iniconfig = "*"
|
1538 |
+
packaging = "*"
|
1539 |
+
pluggy = ">=1.5,<2"
|
1540 |
+
|
1541 |
+
[package.extras]
|
1542 |
+
dev = ["argcomplete", "attrs (>=19.2)", "hypothesis (>=3.56)", "mock", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"]
|
1543 |
+
|
1544 |
[[package]]
|
1545 |
name = "python-dateutil"
|
1546 |
version = "2.9.0.post0"
|
|
|
2102 |
[metadata]
|
2103 |
lock-version = "2.0"
|
2104 |
python-versions = "^3.12"
|
2105 |
+
content-hash = "a8f9e09ac59568c26e085b319749b7dc9fd7363892a41b1dfc04e96fa3b406fd"
|
pyproject.toml
CHANGED
@@ -11,6 +11,7 @@ gradio = "4.38.1"
|
|
11 |
uvicorn = "^0.30.6"
|
12 |
plotly = "^5.24.0"
|
13 |
pytz = "^2024.1"
|
|
|
14 |
|
15 |
|
16 |
[build-system]
|
|
|
11 |
uvicorn = "^0.30.6"
|
12 |
plotly = "^5.24.0"
|
13 |
pytz = "^2024.1"
|
14 |
+
pytest = "^8.3.3"
|
15 |
|
16 |
|
17 |
[build-system]
|
requirements.txt
CHANGED
Binary files a/requirements.txt and b/requirements.txt differ
|
|
test_token.py
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from app import bin_ls2base64, base64_to_binary
|
2 |
+
from numpy import random
|
3 |
+
|
4 |
+
|
5 |
+
def test_translation():
|
6 |
+
for _ in range(100):
|
7 |
+
ls0 = random.randint(0, 2, 24 * 10).tolist()
|
8 |
+
ls1 = [int(n) for n in base64_to_binary(bin_ls2base64(ls0))]
|
9 |
+
assert ls0 == ls1
|