Spaces:
Runtime error
Runtime error
freemt
090f331
"""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, | |
) | |