Spaces:
Runtime error
Runtime error
File size: 2,916 Bytes
f2dd44e 94fcac2 f2dd44e 2650a26 bc8bbd5 54855d5 747c2ab 29f0a11 39b3282 f2dd44e 28e94e4 e2968f8 1d85d70 ef3161d bc8bbd5 222b9bb f2dd44e 60d8e03 457ba36 94fcac2 f2dd44e 747c2ab f2dd44e 39b3282 bc8bbd5 31198fb 1983292 31198fb f2dd44e 2650a26 f2dd44e 28e94e4 bace2bf bc8bbd5 28e94e4 457ba36 bc8bbd5 3552908 f2dd44e 747c2ab ef3161d 747c2ab ef3161d 747c2ab 94fcac2 f2dd44e 54855d5 747c2ab f2dd44e 5a2ec90 f2dd44e 05df558 5a2ec90 f2dd44e bc8bbd5 7a10d0b 05df558 fd0bac7 2650a26 eed1def 60d8e03 2650a26 f2dd44e 60d8e03 f2dd44e 60d8e03 f2dd44e 54855d5 |
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 |
"""Bootstrap."""
# pylint: disable=invalid-name
from typing import Any, List, Union
import gradio as gr
import logzero
import numpy as np
import pandas as pd
# from hf_model_s import model_s
from logzero import logger
from set_loglevel import set_loglevel
from gradio_cmat.gradio_cmat import gradio_cmat
logger.info("gradio version: %s", gr.__version__)
pd.set_option("display.precision", 2)
pd.options.display.float_format = "{:,.2f}".format
logzero.loglevel(set_loglevel(10, force=True))
# model = model_s()
# def fn(text1: str, text2: str) -> np.ndarray:
# def fn(text1: str, text2: str) -> pd.DataFrame:
def fn(text1: str, text2: str) -> Union[List[Any], str]:
"""Define."""
list1 = [elm.strip() for elm in text1.splitlines() if elm.strip()]
list2 = [elm.strip() for elm in text2.splitlines() if elm.strip()]
logger.debug("text1[:10]: %s", text1[:10])
logger.debug("text2[:10]: %s", text2[:10])
logger.info("info text1[:10]: %s", text1[:10])
logger.info("info text2[:10]: %s", text2[:10])
try:
res = gradio_cmat(list1, list2)
# res = np.array([[0.015, 0.235, 0.112], [0.015, 0.235, 0.112]])
logger.debug("res: \n%s, %s", res, res.shape)
logger.debug("type(res): %s", type(res))
# res.round(decimals=2, out=res)
# logger.debug("debug res: %s, %s", res, res.shape)
except Exception as e:
logger.error("gradio_cmat error: %s", e)
return str(e)
# raise
round2 = lambda x: round(x, 1)
vfunc = np.vectorize(round2)
return vfunc(res).tolist()
# return pd.DataFrame(res)
# return str(res.tolist())
out_df = gr.outputs.Dataframe(
# headers=None,
max_rows=50, # 20
max_cols=50,
overflow_row_behaviour="paginate",
type="auto",
label="cmat",
)
out_text = gr.outputs.Textbox(label="cmat")
# _ = """
try:
interface = gr.Interface(
fn,
[
gr.inputs.Textbox(
lines=3, default="""The quick brown fox jumped over the lazy dogs.
test test
测试一下
"""
),
gr.inputs.Textbox(lines=4, default="""The fast brown fox jumps over lazy dogs.
abc
test
Dies ist ein Test
"""),
],
out_df,
# out_text,
title="gradio-cmat",
theme="grass",
allow_flagging="never",
layout="vertical",
description="Gen correlation matrix for multlingual texts",
article="Click 'Clear' first for subsequent new texts",
examples=[
["test\nabc", "测试"],
["This is a text.\nIch liebe Dich.\nabc", "我爱你\nI love you.\n测试\nbcd"],
],
)
except Exception as exc:
logger.exception("")
logger.error("gr.Interface.load(%s): %s", "fn", exc)
raise
interface.launch()
|