titusz commited on
Commit
144e90e
1 Parent(s): a17fbe2

Synced repo using 'sync_with_huggingface' Github Action

Browse files
Files changed (5) hide show
  1. app.py +30 -2
  2. demos/compare.py +337 -33
  3. demos/search.py +34 -0
  4. poetry.lock +0 -0
  5. requirements.txt +2 -2
app.py CHANGED
@@ -15,6 +15,34 @@ custom_css = """
15
  object-fit: contain; /* Scale the image to fit within the element */
16
  }
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  #chunked-text span.label {
19
  text-transform: none !important;
20
  }
@@ -43,8 +71,8 @@ iscc_theme = gr.themes.Default(
43
 
44
  demo = gr.TabbedInterface(
45
  title="▶️ ISCC Playground - The DNA of your digital content",
46
- interface_list=[demo_generate, demo_compare, demo_inspect, demo_chunker],
47
- tab_names=["GENERATE", "COMPARE", "INSPECT", "CHUNKER"],
48
  css=custom_css,
49
  theme=iscc_theme,
50
  )
 
15
  object-fit: contain; /* Scale the image to fit within the element */
16
  }
17
 
18
+ .modebar-btn {
19
+ display: none !important;
20
+ }
21
+
22
+ .small-height {
23
+ display: flex; /* Use flexbox layout */
24
+ flex-direction: column; /* Arrange children vertically */
25
+ justify-content: flex-end; /* Align children to the end (bottom) */
26
+ height: 85px; /* Fixed height */
27
+ object-fit: contain; /* Scale the content to fit within the element */
28
+ }
29
+
30
+ .bit-matrix-big {
31
+ display: flex;
32
+ flex-direction: column;
33
+ justify-content: flex-end;
34
+ height: 150px; /* Fixed height */
35
+ object-fit: contain; /* Scale the content to fit within the element */
36
+ }
37
+
38
+ .iscc-unit-sim {
39
+ display: flex;
40
+ flex-direction: column;
41
+ justify-content: flex-end;
42
+ height: 240px; /* Fixed height */
43
+ object-fit: contain; /* Scale the content to fit within the element */
44
+ }
45
+
46
  #chunked-text span.label {
47
  text-transform: none !important;
48
  }
 
71
 
72
  demo = gr.TabbedInterface(
73
  title="▶️ ISCC Playground - The DNA of your digital content",
74
+ interface_list=[demo_compare, demo_generate, demo_inspect, demo_chunker],
75
+ tab_names=["COMPARE", "GENERATE", "INSPECT", "CHUNKER"],
76
  css=custom_css,
77
  theme=iscc_theme,
78
  )
demos/compare.py CHANGED
@@ -6,6 +6,7 @@ import gradio as gr
6
  from PIL import Image
7
  import iscc_core as ic
8
  import iscc_sdk as idk
 
9
  import iscc_sci as sci
10
  import plotly.graph_objects as go
11
  import pandas as pd
@@ -26,6 +27,34 @@ custom_css = """
26
  object-fit: contain; /* Scale the image to fit within the element */
27
  }
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  #examples-a, #examples-b {
30
  height: 140px; /* Fixed height */
31
  object-fit: contain; /* Scale the image to fit within the element */
@@ -70,11 +99,7 @@ def similarity_plot(sim_data):
70
  data_df["Percentage"] = data_df["Value"] * 100 # Convert to percentage
71
 
72
  # Define color for bars based on value
73
- # data_df["Color"] = ["red" if x < 0 else "green" for x in data_df["Value"]]
74
- data_df["Color"] = [
75
- f"rgba(224,122,95,{abs(x)})" if x < 0 else f"rgba(118,185,71,{x})"
76
- for x in data_df["Value"]
77
- ]
78
 
79
  # Create Plotly Figure
80
  fig = go.Figure()
@@ -84,31 +109,255 @@ def similarity_plot(sim_data):
84
  y=data_df["Category"],
85
  orientation="h",
86
  marker_color=data_df["Color"],
 
87
  text=data_df["Percentage"].apply(lambda x: f"{x:.2f}%"),
88
  textposition="inside",
 
 
 
 
 
 
 
 
 
 
89
  )
90
- ) # Change made here
91
 
92
  # Update layout for aesthetics
93
  fig.update_layout(
94
- title={"text": "Approximate ISCC-UNIT Similarities", "x": 0.5},
95
- xaxis=dict(title="Similarity", tickformat=",.0%"),
96
- yaxis=dict(title=""),
 
 
 
 
 
 
 
 
 
97
  plot_bgcolor="rgba(0,0,0,0)",
98
- height=len(sim_data) * 70,
99
  showlegend=False,
100
- autosize=True,
101
- margin=dict(l=50, r=50, t=50, b=50),
 
 
 
 
 
 
 
102
  )
103
 
104
  # Adjust the x-axis to accommodate percentage labels
105
- fig.update_xaxes(range=[-1.1, 1.1])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
 
107
  return fig
108
 
109
 
110
  with gr.Blocks(css=custom_css) as demo:
111
- gr.Markdown("## 🖼️ ISCC Similarity Comparison")
112
 
113
  with gr.Row(variant="default", equal_height=True):
114
  with gr.Column(variant="compact"):
@@ -137,8 +386,13 @@ with gr.Blocks(css=custom_css) as demo:
137
 
138
  out_iscc_a = gr.Text(label="ISCC", show_copy_button=True)
139
 
140
- with gr.Accordion(label="ISCC Metadata", open=False):
141
- out_meta_a = gr.Code(language="json", label="JSON-LD")
 
 
 
 
 
142
 
143
  with gr.Column(variant="compact"):
144
  in_file_b = gr.File(
@@ -166,13 +420,45 @@ with gr.Blocks(css=custom_css) as demo:
166
  )
167
 
168
  out_iscc_b = gr.Text(label="ISCC", show_copy_button=True)
169
- with gr.Accordion(label="ISCC Metadata", open=False):
170
- out_meta_b = gr.Code(language="json", label="JSON-LD")
171
 
172
- with gr.Row(variant="panel"):
173
- out_compare = gr.Plot(
174
- label="Approximate ISCC-UNIT Similarities", container=False
175
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
 
177
  def rewrite_uri(filepath, sample_set):
178
  # type: (str, str) -> str
@@ -192,6 +478,7 @@ with gr.Blocks(css=custom_css) as demo:
192
  in_file_func = globals().get(f"in_file_{suffix}")
193
  out_thumb_func = globals().get(f"out_thumb_{suffix}")
194
  out_iscc_func = globals().get(f"out_iscc_{suffix}")
 
195
  out_meta_func = globals().get(f"out_meta_{suffix}")
196
 
197
  # Handle emtpy filepath
@@ -200,7 +487,10 @@ with gr.Blocks(css=custom_css) as demo:
200
  in_file_func: None,
201
  }
202
 
203
- imeta = iscc_semantic(filepath)
 
 
 
204
 
205
  # Pop Thumbnail for Preview
206
  thumbnail = None
@@ -214,6 +504,7 @@ with gr.Blocks(css=custom_css) as demo:
214
  in_file_func: gr.File(visible=False, value=None),
215
  out_thumb_func: gr.Image(visible=True, value=thumbnail),
216
  out_iscc_func: imeta.iscc,
 
217
  out_meta_func: imeta.json(exclude_unset=False, by_alias=True, indent=2),
218
  }
219
 
@@ -223,50 +514,63 @@ with gr.Blocks(css=custom_css) as demo:
223
  # type: (str, str) -> dict | None
224
  """Compare two ISCCs"""
225
  if not all([iscc_a, iscc_b]):
226
- return None
227
  dist_data = ic.iscc_compare(iscc_a, iscc_b)
228
  sim_data = dist_to_sim(dist_data, dim=64)
229
  sim_plot = similarity_plot(sim_data)
230
- return sim_plot
 
231
 
232
  # Events
233
  in_file_a.change(
234
  lambda file: process_upload(file, "a"),
235
  inputs=[in_file_a],
236
- outputs=[in_file_a, out_thumb_a, out_iscc_a, out_meta_a],
237
  show_progress="full",
238
  )
239
  in_file_b.change(
240
  lambda file: process_upload(file, "b"),
241
  inputs=[in_file_b],
242
- outputs=[in_file_b, out_thumb_b, out_iscc_b, out_meta_b],
243
  show_progress="full",
244
  )
245
  out_thumb_a.clear(
246
- lambda: (gr.File(visible=True), gr.Image(visible=False), "", ""),
 
 
 
 
 
 
247
  inputs=[],
248
- outputs=[in_file_a, out_thumb_a, out_iscc_a, out_meta_a],
249
  show_progress="hidden",
250
  )
251
 
252
  out_thumb_b.clear(
253
- lambda: (gr.File(visible=True), gr.Image(visible=False), "", ""),
 
 
 
 
 
 
254
  inputs=[],
255
- outputs=[in_file_b, out_thumb_b, out_iscc_b, out_meta_b],
256
  show_progress="hidden",
257
  )
258
 
259
  out_iscc_a.change(
260
  iscc_compare,
261
  inputs=[out_iscc_a, out_iscc_b],
262
- outputs=[out_compare],
263
  show_progress="hidden",
264
  )
265
 
266
  out_iscc_b.change(
267
  iscc_compare,
268
  inputs=[out_iscc_a, out_iscc_b],
269
- outputs=[out_compare],
270
  show_progress="hidden",
271
  )
272
 
 
6
  from PIL import Image
7
  import iscc_core as ic
8
  import iscc_sdk as idk
9
+ import iscc_schema as iss
10
  import iscc_sci as sci
11
  import plotly.graph_objects as go
12
  import pandas as pd
 
27
  object-fit: contain; /* Scale the image to fit within the element */
28
  }
29
 
30
+ .small-height {
31
+ display: flex; /* Use flexbox layout */
32
+ flex-direction: column; /* Arrange children vertically */
33
+ justify-content: flex-end; /* Align children to the end (bottom) */
34
+ height: 85px; /* Fixed height */
35
+ object-fit: contain; /* Scale the content to fit within the element */
36
+ }
37
+
38
+ .bit-matrix-big {
39
+ display: flex;
40
+ flex-direction: column;
41
+ justify-content: flex-end;
42
+ height: 120px; /* Fixed height */
43
+ object-fit: contain; /* Scale the content to fit within the element */
44
+ }
45
+
46
+ .iscc-unit-sim {
47
+ display: flex;
48
+ flex-direction: column;
49
+ justify-content: flex-end;
50
+ height: 120px; /* Fixed height */
51
+ object-fit: contain; /* Scale the content to fit within the element */
52
+ }
53
+
54
+ .modebar-btn {
55
+ display: none !important;
56
+ }
57
+
58
  #examples-a, #examples-b {
59
  height: 140px; /* Fixed height */
60
  object-fit: contain; /* Scale the image to fit within the element */
 
99
  data_df["Percentage"] = data_df["Value"] * 100 # Convert to percentage
100
 
101
  # Define color for bars based on value
102
+ data_df["Color"] = ["#f56169" if x < 0 else "#a6db50" for x in data_df["Value"]]
 
 
 
 
103
 
104
  # Create Plotly Figure
105
  fig = go.Figure()
 
109
  y=data_df["Category"],
110
  orientation="h",
111
  marker_color=data_df["Color"],
112
+ marker_line={"width": 0},
113
  text=data_df["Percentage"].apply(lambda x: f"{x:.2f}%"),
114
  textposition="inside",
115
+ textfont={
116
+ "size": 14,
117
+ "family": "JetBrains Mono",
118
+ },
119
+ hoverinfo=None,
120
+ hovertemplate="ISCC-UNIT: %{y}<br>SIMILARITY: %{x}<extra></extra>",
121
+ hoverlabel={
122
+ "font": {"family": "JetBrains Mono", "color": "#FFFFFF"},
123
+ "bgcolor": "#444444",
124
+ },
125
  )
126
+ )
127
 
128
  # Update layout for aesthetics
129
  fig.update_layout(
130
+ height=len(sim_data) * 40,
131
+ autosize=True,
132
+ xaxis=dict(
133
+ title="",
134
+ tickformat=",.0%",
135
+ showticklabels=False,
136
+ ),
137
+ yaxis=dict(
138
+ title="",
139
+ showticklabels=False,
140
+ ),
141
+ paper_bgcolor="rgba(0,0,0,0)",
142
  plot_bgcolor="rgba(0,0,0,0)",
 
143
  showlegend=False,
144
+ modebar_remove=[
145
+ "toImage",
146
+ "zoom",
147
+ "pan",
148
+ "zoomIn",
149
+ "zoomOut",
150
+ "autoScale",
151
+ "resetScale",
152
+ ],
153
  )
154
 
155
  # Adjust the x-axis to accommodate percentage labels
156
+ fig.update_xaxes(
157
+ range=[-1.1, 1.1],
158
+ fixedrange=False,
159
+ showline=False,
160
+ zeroline=False,
161
+ showgrid=False,
162
+ gridcolor="rgba(0,0,0,0)",
163
+ )
164
+
165
+ return fig
166
+
167
+
168
+ def bit_matrix_plot(iscc_code):
169
+ # type: (ic.Code) -> go.Figure
170
+ """
171
+ Create a bit matrix plot for an ISCC-CODE
172
+ """
173
+
174
+ # Decode ISCC-CODE
175
+ data = {}
176
+ for unit in ic.iscc_decompose(iscc_code.code):
177
+ unit = ic.Code(unit)
178
+ data[unit.type_id.split("-")[0]] = unit.hash_bits
179
+
180
+ # Prepare data for heatmap
181
+ z = []
182
+ for key, value in data.items():
183
+ z.append([int(bit) for bit in value])
184
+
185
+ # Define colors for 0 and 1 bits
186
+ colorscale = [[0, "#f56169"], [1, "#a6db50"]]
187
+
188
+ # Build Plotly Visualization
189
+ fig = go.Figure(
190
+ data=go.Heatmap(
191
+ z=z,
192
+ xgap=2,
193
+ ygap=2,
194
+ showscale=False,
195
+ colorscale=colorscale,
196
+ hoverinfo="x+y",
197
+ hovertemplate="ISCC-UNIT: %{y}<br>BIT-NUMBR: %{x}<br>BIT-VALUE: %{z}<extra></extra>",
198
+ hoverlabel={
199
+ "font": {"family": "JetBrains Mono"},
200
+ },
201
+ )
202
+ )
203
+
204
+ fig.update_layout(
205
+ height=60,
206
+ autosize=True,
207
+ xaxis=dict(
208
+ ticks="",
209
+ side="top",
210
+ scaleanchor="y",
211
+ constrain="domain",
212
+ showticklabels=False,
213
+ ),
214
+ yaxis=dict(
215
+ ticks="",
216
+ tickvals=list(range(len(data))),
217
+ ticktext=list(data.keys()),
218
+ side="left",
219
+ autorange="reversed",
220
+ showticklabels=False,
221
+ ),
222
+ paper_bgcolor="rgba(0,0,0,0)",
223
+ plot_bgcolor="rgba(0,0,0,0)",
224
+ margin=dict(l=10, r=10, t=0, b=10),
225
+ modebar_remove=[
226
+ "toImage",
227
+ "zoom",
228
+ "pan",
229
+ "zoomIn",
230
+ "zoomOut",
231
+ "autoScale",
232
+ "resetScale",
233
+ ],
234
+ )
235
+
236
+ fig.update_xaxes(
237
+ fixedrange=False,
238
+ showline=False,
239
+ zeroline=False,
240
+ showgrid=False,
241
+ gridcolor="rgba(0,0,0,0)",
242
+ )
243
+ fig.update_yaxes(
244
+ fixedrange=False,
245
+ showline=False,
246
+ zeroline=False,
247
+ showgrid=False,
248
+ gridcolor="rgba(0,0,0,0)",
249
+ )
250
+
251
+ return fig
252
+
253
+
254
+ def bit_comparison(iscc_code1, iscc_code2):
255
+ """
256
+ Create a comparison bit matrix plot for two ISCC-CODES
257
+ """
258
+
259
+ # Decode ISCC-CODEs
260
+ data1, data2 = {}, {}
261
+ for unit in ic.iscc_decompose(iscc_code1):
262
+ unit = ic.Code(unit)
263
+ data1[unit.type_id.split("-")[0]] = unit.hash_bits
264
+ for unit in ic.iscc_decompose(iscc_code2):
265
+ unit = ic.Code(unit)
266
+ data2[unit.type_id.split("-")[0]] = unit.hash_bits
267
+
268
+ # Prepare data for heatmap comparison
269
+ z = []
270
+ text = []
271
+ for key in data1.keys():
272
+ z_row = []
273
+ text_row = []
274
+ for bit1, bit2 in zip(data1[key], data2.get(key, "")):
275
+ if bit1 == bit2:
276
+ z_row.append(int(bit1))
277
+ text_row.append(bit1)
278
+ else:
279
+ z_row.append(2)
280
+ text_row.append("x")
281
+ z.append(z_row)
282
+ text.append(text_row)
283
+
284
+ # Define colors for 0, 1, and non-matching bits
285
+ colorscale = [[0, "#a6db50"], [0.5, "#a6db50"], [1, "#f56169"]]
286
+
287
+ fig = go.Figure(
288
+ data=go.Heatmap(
289
+ z=z,
290
+ text=text,
291
+ xgap=2,
292
+ ygap=2,
293
+ showscale=False,
294
+ colorscale=colorscale,
295
+ hoverinfo="text",
296
+ hovertemplate="ISCC-UNIT: %{y}<br>BIT-NUMBR: %{x}<br>BIT-VALUE: %{z}<extra></extra>",
297
+ hoverlabel={
298
+ "font": {"family": "JetBrains Mono"},
299
+ },
300
+ texttemplate="", # Use "%{text}" for showing bits
301
+ textfont={
302
+ "size": 14,
303
+ "color": "#FFFFFF",
304
+ "family": "JetBrains Mono",
305
+ },
306
+ )
307
+ )
308
+
309
+ fig.update_layout(
310
+ height=120,
311
+ autosize=True,
312
+ xaxis=dict(
313
+ ticks="",
314
+ side="top",
315
+ scaleanchor="y",
316
+ constrain="domain",
317
+ showticklabels=False,
318
+ ),
319
+ yaxis=dict(
320
+ ticks="",
321
+ tickvals=list(range(len(data1))),
322
+ ticktext=list(data1.keys()),
323
+ side="left",
324
+ autorange="reversed",
325
+ showticklabels=False,
326
+ ),
327
+ paper_bgcolor="rgba(0,0,0,0)",
328
+ plot_bgcolor="rgba(0,0,0,0)",
329
+ margin=dict(l=0, r=0, t=0, b=0),
330
+ modebar_remove=[
331
+ "toImage",
332
+ "zoom",
333
+ "pan",
334
+ "zoomIn",
335
+ "zoomOut",
336
+ "autoScale",
337
+ "resetScale",
338
+ ],
339
+ )
340
+
341
+ fig.update_xaxes(
342
+ fixedrange=False,
343
+ showline=False,
344
+ zeroline=False,
345
+ showgrid=False,
346
+ gridcolor="rgba(0,0,0,0)",
347
+ )
348
+ fig.update_yaxes(
349
+ fixedrange=False,
350
+ showline=False,
351
+ zeroline=False,
352
+ showgrid=False,
353
+ gridcolor="rgba(0,0,0,0)",
354
+ )
355
 
356
  return fig
357
 
358
 
359
  with gr.Blocks(css=custom_css) as demo:
360
+ gr.Markdown("## ⚙️ ISCC Similarity Comparison")
361
 
362
  with gr.Row(variant="default", equal_height=True):
363
  with gr.Column(variant="compact"):
 
386
 
387
  out_iscc_a = gr.Text(label="ISCC", show_copy_button=True)
388
 
389
+ with gr.Accordion(label="Details", open=False):
390
+ out_dna_a = gr.Plot(
391
+ label="BIT-MATRIX",
392
+ container=True,
393
+ elem_classes=["small-height"],
394
+ )
395
+ out_meta_a = gr.Code(language="json", label="ISCC Metadata")
396
 
397
  with gr.Column(variant="compact"):
398
  in_file_b = gr.File(
 
420
  )
421
 
422
  out_iscc_b = gr.Text(label="ISCC", show_copy_button=True)
 
 
423
 
424
+ with gr.Accordion(
425
+ label="Details",
426
+ open=False,
427
+ ):
428
+ out_dna_b = gr.Plot(
429
+ label="BIT-MATRIX",
430
+ container=True,
431
+ elem_classes=["small-height"],
432
+ )
433
+ out_meta_b = gr.Code(language="json", label="ISCC Metadata")
434
+
435
+ with gr.Row(variant="default", equal_height=True):
436
+ with gr.Column(variant="compact"):
437
+ out_bitcompare = gr.Plot(
438
+ label="BIT-MATRIX Comparison",
439
+ container=True,
440
+ elem_classes=["bit-matrix-big"],
441
+ )
442
+
443
+ with gr.Row(variant="default", equal_height=True):
444
+ with gr.Column(variant="compact"):
445
+ out_compare = gr.Plot(
446
+ label="ISCC-UNIT Similarities",
447
+ container=True,
448
+ elem_classes=["iscc-unit-sim"],
449
+ )
450
+
451
+ # Custom footer
452
+ footer = (
453
+ "https://github.com/iscc"
454
+ f" | iscc-core v{ic.__version__}"
455
+ f" | iscc-sdk v{idk.__version__}"
456
+ f" | iscc-sci v{sci.__version__}"
457
+ f" | iscc-schema v{iss.__version__}"
458
+ )
459
+ gr.Markdown(
460
+ footer,
461
+ )
462
 
463
  def rewrite_uri(filepath, sample_set):
464
  # type: (str, str) -> str
 
478
  in_file_func = globals().get(f"in_file_{suffix}")
479
  out_thumb_func = globals().get(f"out_thumb_{suffix}")
480
  out_iscc_func = globals().get(f"out_iscc_{suffix}")
481
+ out_dna_func = globals().get(f"out_dna_{suffix}")
482
  out_meta_func = globals().get(f"out_meta_{suffix}")
483
 
484
  # Handle emtpy filepath
 
487
  in_file_func: None,
488
  }
489
 
490
+ imeta: idk.IsccMeta = iscc_semantic(filepath)
491
+
492
+ # Create Bit-Matrix Plot
493
+ matrix_plot = bit_matrix_plot(imeta.iscc_obj)
494
 
495
  # Pop Thumbnail for Preview
496
  thumbnail = None
 
504
  in_file_func: gr.File(visible=False, value=None),
505
  out_thumb_func: gr.Image(visible=True, value=thumbnail),
506
  out_iscc_func: imeta.iscc,
507
+ out_dna_func: matrix_plot,
508
  out_meta_func: imeta.json(exclude_unset=False, by_alias=True, indent=2),
509
  }
510
 
 
514
  # type: (str, str) -> dict | None
515
  """Compare two ISCCs"""
516
  if not all([iscc_a, iscc_b]):
517
+ return None, None
518
  dist_data = ic.iscc_compare(iscc_a, iscc_b)
519
  sim_data = dist_to_sim(dist_data, dim=64)
520
  sim_plot = similarity_plot(sim_data)
521
+ bit_plot = bit_comparison(iscc_a, iscc_b)
522
+ return sim_plot, bit_plot
523
 
524
  # Events
525
  in_file_a.change(
526
  lambda file: process_upload(file, "a"),
527
  inputs=[in_file_a],
528
+ outputs=[in_file_a, out_thumb_a, out_iscc_a, out_dna_a, out_meta_a],
529
  show_progress="full",
530
  )
531
  in_file_b.change(
532
  lambda file: process_upload(file, "b"),
533
  inputs=[in_file_b],
534
+ outputs=[in_file_b, out_thumb_b, out_iscc_b, out_dna_b, out_meta_b],
535
  show_progress="full",
536
  )
537
  out_thumb_a.clear(
538
+ lambda: (
539
+ gr.File(visible=True),
540
+ gr.Image(visible=False),
541
+ "",
542
+ gr.Plot(value=None),
543
+ "",
544
+ ),
545
  inputs=[],
546
+ outputs=[in_file_a, out_thumb_a, out_iscc_a, out_dna_a, out_meta_a],
547
  show_progress="hidden",
548
  )
549
 
550
  out_thumb_b.clear(
551
+ lambda: (
552
+ gr.File(visible=True),
553
+ gr.Image(visible=False),
554
+ "",
555
+ gr.Plot(value=None),
556
+ "",
557
+ ),
558
  inputs=[],
559
+ outputs=[in_file_b, out_thumb_b, out_iscc_b, out_dna_b, out_meta_b],
560
  show_progress="hidden",
561
  )
562
 
563
  out_iscc_a.change(
564
  iscc_compare,
565
  inputs=[out_iscc_a, out_iscc_b],
566
+ outputs=[out_compare, out_bitcompare],
567
  show_progress="hidden",
568
  )
569
 
570
  out_iscc_b.change(
571
  iscc_compare,
572
  inputs=[out_iscc_a, out_iscc_b],
573
+ outputs=[out_compare, out_bitcompare],
574
  show_progress="hidden",
575
  )
576
 
demos/search.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ css = """
4
+ #stats_box {font-family: monospace; font-size: 65%; height: 162px;}
5
+ footer {visibility: hidden}
6
+ body {overflow: hidden;}
7
+ * {scrollbar-color: rebeccapurple green; scrollbar-width: thin;}
8
+ """
9
+
10
+
11
+ iscc_theme = gr.themes.Default(
12
+ font=gr.themes.GoogleFont("Readex Pro"),
13
+ font_mono=gr.themes.GoogleFont("JetBrains Mono"),
14
+ radius_size=gr.themes.sizes.radius_none,
15
+ )
16
+
17
+
18
+ with gr.Blocks(css=css, theme=iscc_theme) as demo:
19
+ gr.HTML('<h1 style="color: #6aa84f; font-size: 250%;">ISCC SEARCH DEMO</h1>')
20
+
21
+ with gr.Row(equal_height=True):
22
+ with gr.Column():
23
+ in_image = gr.Image(type="pil")
24
+
25
+ gallery = gr.Gallery(
26
+ value=None,
27
+ columns=8,
28
+ height=750,
29
+ object_fit="scale-down",
30
+ preview=False,
31
+ )
32
+
33
+ if __name__ == "__main__":
34
+ demo.launch()
poetry.lock CHANGED
The diff for this file is too large to render. See raw diff
 
requirements.txt CHANGED
@@ -1,4 +1,4 @@
1
- gradio==4.19.1
2
  iscc-sdk==0.6.1
3
  iscc-sci==0.1.0
4
- plotly==5.19.0
 
1
+ gradio==4.21.0
2
  iscc-sdk==0.6.1
3
  iscc-sci==0.1.0
4
+ plotly==5.20.0