|
3 | 3 | import io |
4 | 4 | import multiprocessing |
5 | 5 | import os |
| 6 | +import platform |
6 | 7 | import sys |
7 | 8 | import warnings |
8 | 9 | from collections.abc import Callable |
@@ -300,9 +301,10 @@ def on_theme_change(value): |
300 | 301 |
|
301 | 302 | def on_tab_select(value: gr.SelectData): |
302 | 303 | if value.selected and os.path.exists(cfg.ERROR_LOG_FILE): |
303 | | - with open(cfg.ERROR_LOG_FILE, encoding="utf-8") as f: |
304 | | - lines = f.readlines() |
| 304 | + with open(cfg.ERROR_LOG_FILE, mode="rb") as f: |
| 305 | + lines = [line.decode("utf-8", errors="ignore") for line in f] |
305 | 306 | last_100_lines = lines[-100:] |
| 307 | + |
306 | 308 | return "".join(last_100_lines) |
307 | 309 |
|
308 | 310 | return "" |
@@ -614,8 +616,13 @@ def species_lists(opened=True) -> dict[_SPECIES_KEYS, gr.components.Component]: |
614 | 616 | A dict with the created elements. |
615 | 617 | """ |
616 | 618 | with gr.Accordion(loc.localize("species-list-accordion-label"), open=opened), gr.Row(): |
| 619 | + values = [_CUSTOM_SPECIES, _PREDICT_SPECIES, _CUSTOM_CLASSIFIER, _ALL_SPECIES, _USE_PERCH] |
| 620 | + |
| 621 | + if platform.system() == "Darwin": |
| 622 | + values.pop() # TODO: Remove when tf 2.21+ is available on macOS |
| 623 | + |
617 | 624 | species_list_radio = gr.Radio( |
618 | | - [_CUSTOM_SPECIES, _PREDICT_SPECIES, _CUSTOM_CLASSIFIER, _ALL_SPECIES, _USE_PERCH], |
| 625 | + values, |
619 | 626 | value=_ALL_SPECIES, |
620 | 627 | label=loc.localize("species-list-radio-label"), |
621 | 628 | info=loc.localize("species-list-radio-info"), |
@@ -689,13 +696,21 @@ def download_plot(plot, filename=""): |
689 | 696 | ) |
690 | 697 |
|
691 | 698 | if res: |
692 | | - if res.endswith(".webp"): |
| 699 | + if isinstance(res, list | tuple): |
| 700 | + res = res[0] |
| 701 | + |
| 702 | + file_ext = res.split(".", 1)[-1].upper() |
| 703 | + |
| 704 | + if file_ext == "WEBP": |
693 | 705 | with open(res, "wb") as f: |
694 | 706 | f.write(imgdata) |
695 | 707 | else: |
696 | | - output_format = res.rsplit(".", 1)[-1].upper() |
| 708 | + if file_ext not in ["PNG", "JPEG"]: |
| 709 | + file_ext = "PNG" |
| 710 | + res += ".png" |
| 711 | + |
697 | 712 | img = Image.open(io.BytesIO(imgdata)) |
698 | | - img.save(res, output_format if output_format in ["PNG", "JPEG"] else "PNG") |
| 713 | + img.save(res, file_ext) |
699 | 714 |
|
700 | 715 |
|
701 | 716 | def _get_network_shortcuts(): |
|
0 commit comments