Skip to content

Commit

Permalink
Add all multiformat encodings to inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
titusz committed Mar 17, 2024
1 parent 752c7a4 commit c83af48
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 36 deletions.
75 changes: 61 additions & 14 deletions demos/inspect_.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,41 @@


def explain_iscc(code):
result = [gr.Column(visible=False), None, None, None, None]
result = [gr.Column(visible=True), None, None, None, None, None, None, None, None]
if not code:
return tuple(result)
try:
canonical = ic.iscc_normalize(code)
# TODO Update iscc-core validation for MSCDI
# ic.iscc_validate(canonical, strict=True)
if not code.startswith("ISCC:"):
code = ic.iscc_normalize(code)

code_obj = ic.Code(code)
if code_obj.length != len(code_obj.hash_bits):
raise ValueError(f"Incorrect body length")

ic.iscc_validate(code, strict=True)
human = " - ".join(ic.iscc_explain(code).split("-"))
code_obj = ic.Code(canonical)
decomposed = " - ".join(ic.iscc_decompose(canonical))
multiformat = code_obj.mf_base58btc

decomposed = " - ".join(ic.iscc_decompose(code))
base16 = code_obj.mf_base16
base32 = code_obj.mf_base32
base32hex = code_obj.mf_base32hex
base58btc = code_obj.mf_base58btc
base64url = code_obj.mf_base64url
except Exception as e:
log.error(e)
result[1] = str(e)
return tuple(result)
return gr.Column(visible=True), canonical, human, decomposed, multiformat
return (
gr.Column(visible=True),
code,
human,
decomposed,
base16,
base32,
base32hex,
base58btc,
base64url,
)


with gr.Blocks() as demo:
Expand All @@ -46,6 +65,7 @@ def explain_iscc(code):
"ISCC:KAA2Y5NUST7BFD5NN2XIDK7VW3WG4OEPMRQNPK37TE", # ISCC-CDI
"z36hVxiqoF8AAmDpZV958hn3tsv2i7v1NfCrSzpq", # ISCC-CDI multiformats
"ISCC:KACT4EBWK27737D2AYCJRAL5Z36G76RFRMO4554RU26HZ4ORJGIVHDI",
"ISCC:KED572P4AOF5K6QXQA4T6OJD5UGX7UBPFW2TVQNTHBCKFRFCANCZARQ4K6NSFZQSH4GQ",
]
gr.Examples(label="Example ISCCs", examples=examples, inputs=[in_iscc])

Expand All @@ -67,11 +87,34 @@ def explain_iscc(code):
info="ISCC-UNITS",
show_copy_button=True,
)
out_multiformat = gr.Text(
label="Multiformat",
info="BASE58-BTC",
show_copy_button=True,
)
with gr.Row():
with gr.Column():
gr.Markdown("## Multiformat Encodings")
out_base16 = gr.Text(
label="base16",
show_copy_button=True,
)

out_base32 = gr.Text(
label="base32",
show_copy_button=True,
)

out_base32_hex = gr.Text(
label="base32hex",
show_copy_button=True,
)

out_base58_btc = gr.Text(
label="base58btc",
show_copy_button=True,
)

out_base64_url = gr.Text(
label="base64url",
show_copy_button=True,
)

in_iscc.change(
explain_iscc,
inputs=[in_iscc],
Expand All @@ -80,7 +123,11 @@ def explain_iscc(code):
out_canonical,
out_human,
out_decomposed,
out_multiformat,
out_base16,
out_base32,
out_base32_hex,
out_base58_btc,
out_base64_url,
],
show_progress="hidden",
)
Expand Down
49 changes: 27 additions & 22 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ readme = "README.md"
python = "^3.9"
gradio = "*"
iscc-sdk = "^0.6.1"
iscc-core= "^1.0.9"
iscc-sci = "^0.1.0"
plotly = "^5.18.0"

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
gradio==4.21.0
iscc-sdk==0.6.1
iscc-core==1.0.9
iscc-sci==0.1.0
plotly==5.20.0

0 comments on commit c83af48

Please sign in to comment.