Synced repo using 'sync_with_huggingface' Github Action
Browse files- iscc_sct/demo.py +15 -17
iscc_sct/demo.py
CHANGED
@@ -164,9 +164,10 @@ with gr.Blocks(css=custom_css, theme=iscc_theme) as demo:
|
|
164 |
|
165 |
gr.Examples(
|
166 |
label="Click to use sample text",
|
167 |
-
examples=[
|
168 |
inputs=[in_text_a],
|
169 |
examples_per_page=1,
|
|
|
170 |
)
|
171 |
out_code_a = gr.Textbox(label="ISCC Code for Text A")
|
172 |
gr.ClearButton(components=[in_text_a])
|
@@ -180,9 +181,10 @@ with gr.Blocks(css=custom_css, theme=iscc_theme) as demo:
|
|
180 |
|
181 |
gr.Examples(
|
182 |
label="Click to use sample text",
|
183 |
-
examples=[
|
184 |
inputs=[in_text_b],
|
185 |
examples_per_page=1,
|
|
|
186 |
)
|
187 |
out_code_b = gr.Textbox(label="ISCC Code for Text B")
|
188 |
gr.ClearButton(components=[in_text_b])
|
@@ -194,17 +196,11 @@ with gr.Blocks(css=custom_css, theme=iscc_theme) as demo:
|
|
194 |
def process_text(text, nbits, suffix):
|
195 |
log.debug(f"{text[:20]}")
|
196 |
if not text:
|
197 |
-
return
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
else sample_text_de
|
203 |
-
if text == truncate_text(sample_text_de)
|
204 |
-
else text
|
205 |
-
)
|
206 |
-
iscc = sct.Metadata(**sct.gen_text_code_semantic(full_text, bits=nbits))
|
207 |
-
return iscc.iscc, full_text
|
208 |
|
209 |
def recalculate_iscc(text_a, text_b, nbits):
|
210 |
code_a = sct.gen_text_code_semantic(text_a, bits=nbits)["iscc"] if text_a else None
|
@@ -222,16 +218,18 @@ with gr.Blocks(css=custom_css, theme=iscc_theme) as demo:
|
|
222 |
)
|
223 |
|
224 |
in_text_a.change(
|
225 |
-
process_text,
|
226 |
inputs=[in_text_a, in_iscc_bits],
|
227 |
-
outputs=[out_code_a
|
228 |
show_progress="full",
|
|
|
229 |
)
|
230 |
in_text_b.change(
|
231 |
-
process_text,
|
232 |
inputs=[in_text_b, in_iscc_bits],
|
233 |
-
outputs=[out_code_b
|
234 |
show_progress="full",
|
|
|
235 |
)
|
236 |
|
237 |
in_iscc_bits.change(
|
|
|
164 |
|
165 |
gr.Examples(
|
166 |
label="Click to use sample text",
|
167 |
+
examples=[sample_text_en],
|
168 |
inputs=[in_text_a],
|
169 |
examples_per_page=1,
|
170 |
+
example_labels=[truncate_text(sample_text_en)]
|
171 |
)
|
172 |
out_code_a = gr.Textbox(label="ISCC Code for Text A")
|
173 |
gr.ClearButton(components=[in_text_a])
|
|
|
181 |
|
182 |
gr.Examples(
|
183 |
label="Click to use sample text",
|
184 |
+
examples=[sample_text_de],
|
185 |
inputs=[in_text_b],
|
186 |
examples_per_page=1,
|
187 |
+
example_labels=[truncate_text(sample_text_de)]
|
188 |
)
|
189 |
out_code_b = gr.Textbox(label="ISCC Code for Text B")
|
190 |
gr.ClearButton(components=[in_text_b])
|
|
|
196 |
def process_text(text, nbits, suffix):
|
197 |
log.debug(f"{text[:20]}")
|
198 |
if not text:
|
199 |
+
return
|
200 |
+
out_code_func = globals().get(f"out_code_{suffix}")
|
201 |
+
iscc = sct.Metadata(**sct.gen_text_code_semantic(text, bits=nbits))
|
202 |
+
result = {out_code_func: gr.Textbox(value=iscc.iscc)}
|
203 |
+
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
204 |
|
205 |
def recalculate_iscc(text_a, text_b, nbits):
|
206 |
code_a = sct.gen_text_code_semantic(text_a, bits=nbits)["iscc"] if text_a else None
|
|
|
218 |
)
|
219 |
|
220 |
in_text_a.change(
|
221 |
+
lambda text, nbits: process_text(text, nbits, "a"),
|
222 |
inputs=[in_text_a, in_iscc_bits],
|
223 |
+
outputs=[out_code_a],
|
224 |
show_progress="full",
|
225 |
+
trigger_mode="always_last",
|
226 |
)
|
227 |
in_text_b.change(
|
228 |
+
lambda text, nbits: process_text(text, nbits, "b"),
|
229 |
inputs=[in_text_b, in_iscc_bits],
|
230 |
+
outputs=[out_code_b],
|
231 |
show_progress="full",
|
232 |
+
trigger_mode="always_last",
|
233 |
)
|
234 |
|
235 |
in_iscc_bits.change(
|