File size: 1,559 Bytes
ed4da02
 
 
 
 
3b3dc37
ed4da02
 
3b3dc37
ed4da02
 
3f70481
8d06a0f
3b3dc37
 
 
ed4da02
 
3b3dc37
ed4da02
 
 
 
 
 
090f331
 
 
 
 
 
49e54f5
7e6c0d6
090f331
49e54f5
 
7e6c0d6
090f331
7e6c0d6
4678308
ed4da02
090f331
ed4da02
 
090f331
ed4da02
 
 
 
ddc967b
ed4da02
 
 
 
 
ddc967b
ed4da02
 
 
 
 
 
 
 
 
090f331
ed4da02
 
 
 
 
 
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
"""Set up gradio api for cmataset."""
# pylint: disable=invalid-name
from typing import List, Tuple, Union

import gradio as gr
import logzero
import numpy as np
from cmat2aset import cmat2aset as c2a

from logzero import logger

logzero.loglevel(10)
logger.debug("gradio version: %s", gr.__version__)

# 3.0.19


def cmat2aset(
    cmat: Union[np.ndarray, List[List[float]]],
    eps: float = 10,
    min_samples: int = 6,
) -> Union[
    np.ndarray, List[Tuple[Union[int, str], Union[int, str], Union[float, str]]]
]:
    """Set up gradio api for cmataset."""
    try:
        cmat = np.array(cmat, dtype=str)
    except Exception as exc:
        logger.exception(exc)
        return None, str(exc)

    try:
        # cmat[cmat==""] = 0
        cmat = np.where(cmat == "", 0, cmat)  # type: ignore
        cmat = np.array(cmat, dtype=float)
    except Exception as exc:
        logger.exception(exc)
        return None, str(exc)

    logger.debug("cmat[:3, :3]: %s", cmat[:3, :3])
    try:
        return c2a(cmat, eps, min_samples), ""
    except Exception as exc:
        logger.exception(exc)
        return None, str(exc)


inputs = [
    "numpy",
    gr.inputs.Slider(
        minimum=1,
        maximum=20,
        step=0.1,
        default=10,
    ),
    gr.inputs.Slider(
        minimum=1,
        maximum=20,
        step=1,
        default=6,
    ),
]
iface = gr.Interface(
    fn=cmat2aset,
    inputs=inputs,
    outputs=["dataframe", "text"],
    allow_flagging="never",
    title="radio-cmat2aset",
)
iface.launch(
    enable_queue=True,
)