gradio-cmat / app.py
freemt
pd.set_option("display.precision", 2)
e2968f8
raw
history blame
2.13 kB
"""Bootstrap."""
# pylint: disable=invalid-name
import numpy as np
import pandas as pd
import gradio as gr
from hf_model_s import model_s
import logzero
from logzero import logger
from set_loglevel import set_loglevel
from gradio_cmat import gradio_cmat
pd.set_option("display.precision", 2)
logzero.loglevel(set_loglevel(10, force=True))
model = model_s()
def fn(text1: str, text2: str) -> np.ndarray:
"""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)
logger.info("res: %s, %s", res, res.shape)
except Exception as e:
logger.error("gradio_cmat error: %s", e)
return str(e)
# raise
# return res.round(2)
return res
out_df = gr.outputs.Dataframe(
# headers=None,
max_rows=50, # 20
max_cols=50,
overflow_row_behaviour="paginate",
type="auto",
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=3, default="""The fast brown fox jumps over lazy dogs.
abc
test
Dies ist ein Test
"""),
],
out_df,
name="gradio-cmat",
description="Gen correlation matrix for multlingual texts",
article="Click 'Clear' first for subsequent new texts",
examples=[
"This is a text.", "Ich liebe Dich.", "abc",
"我爱你\nI love you.\n测试\nbcd",
],
)
except Exception as e:
logger.exception("")
logger.error("gr.Interface.load(%s): %s", "fn", e)
raise
interface.launch()