Spaces:
Running
Running
File size: 4,272 Bytes
f14de11 2526fc7 f14de11 2526fc7 f14de11 2526fc7 f14de11 2526fc7 f14de11 2526fc7 f14de11 2526fc7 f14de11 2526fc7 f14de11 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# -*- coding: utf-8 -*-
from loguru import logger as log
import gradio as gr
import iscc_core as ic
def explain_iscc(code):
result = [gr.Column(visible=True), None, None, None, None, None, None, None, None]
if not code:
return tuple(result)
try:
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("-"))
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),
code,
human,
decomposed,
base16,
base32,
base32hex,
base58btc,
base64url,
)
with gr.Blocks() as demo:
gr.Markdown(
"""
## 🕵️♂️ ISCC Inspector
"""
)
with gr.Row():
with gr.Column():
in_iscc = gr.Text(
label="ISCC Inspector",
info="DECODE & EXPLAIN ISCC STRUCTURE",
placeholder="Paste an ISCC here to break it down",
autofocus=True,
)
examples = [
"ISCC:AAAWN77F727NXSUS", # Meta-Code
"bzqaqaal5rvp72lx2thvq", # Multiformat
"ISCC:EAASKDNZNYGUUF5A", # Text-Code
"ISCC:GABW5LUBVP23N3DOD7PPINHT5JKBI", # Data-Code 128 bits
"ISCC:KUAG5LUBVP23N3DOHCHWIYGXVN7ZS", # ISCC-SUM
"ISCC:KAA2Y5NUST7BFD5NN2XIDK7VW3WG4OEPMRQNPK37TE", # ISCC-CDI
"z36hVxiqoF8AAmDpZV958hn3tsv2i7v1NfCrSzpq", # ISCC-CDI multiformats
"ISCC:KACT4EBWK27737D2AYCJRAL5Z36G76RFRMO4554RU26HZ4ORJGIVHDI",
"ISCC:KED572P4AOF5K6QXQA4T6OJD5UGX7UBPFW2TVQNTHBCKFRFCANCZARQ4K6NSFZQSH4GQ",
]
gr.Examples(label="Example ISCCs", examples=examples, inputs=[in_iscc])
with gr.Row():
with gr.Column(visible=False) as out_column:
out_canonical = gr.Text(
label="Canonical",
info="NORMALIZED STANDARD REPRESENTATION",
show_copy_button=True,
value=None,
)
out_human = gr.Text(
label="Human Readable",
info="MAINTYPE - SUBTYPE - VERSION - LENGTH - BODY",
show_copy_button=True,
)
out_decomposed = gr.Text(
label="Decomposed",
info="ISCC-UNITS",
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],
outputs=[
out_column,
out_canonical,
out_human,
out_decomposed,
out_base16,
out_base32,
out_base32_hex,
out_base58_btc,
out_base64_url,
],
show_progress="hidden",
)
if __name__ == "__main__":
demo.launch()
|