File size: 2,434 Bytes
89d669f
f537c4c
89d669f
f537c4c
89d669f
 
 
16195e5
 
89d669f
 
 
 
 
f537c4c
 
 
 
89d669f
 
 
 
 
 
 
 
 
 
16195e5
89d669f
16195e5
 
 
 
89d669f
 
 
 
42b9713
 
 
 
89d669f
 
 
 
 
 
 
 
16195e5
 
 
44c4eaa
16195e5
89d669f
16195e5
 
44c4eaa
 
16195e5
 
6ed04ff
89d669f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16195e5
 
89d669f
44c4eaa
16195e5
f537c4c
16195e5
 
89d669f
 
 
 
16195e5
 
89d669f
16195e5
 
 
 
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
"""Gen ubee main."""
# pylint: disable=unused-import, wrong-import-position

import sys
from itertools import zip_longest
from textwrap import dedent

import gradio as gr

import pandas as pd
from icecream import install as ic_install, ic
import logzero
from logzero import logger

# for embeddable python
if "." not in sys.path:
    sys.path.insert(0, ".")

from ubee.ubee import ubee

ic_install()
ic.configureOutput(
    includeContext=True,
    outputFunction=logger.info,
)
ic.enable()
# ic.disenable()  # to turn off


def greet1(name):
    """Dummy."""
    return "Hello " + name + "!!"


def greet(text1, text2) -> pd.DataFrame:
    """Take inputs, return outputs.

    Args:
        text1: text
        text2: text
    Returns:
        pd.DataFrame
    """
    res1 = [elm for elm in text1.splitlines() if elm.strip()]
    res2 = [elm for elm in text2.splitlines() if elm.strip()]

    _ = pd.DataFrame(zip_longest(res1, res2), columns=["text1", "text2"])
    return _


def main():
    """Create main entry."""
    title = "Ultimatumbee Aligner"
    theme = "dark-grass"
    description = """WIP showcasing a novel aligner"""
    article = """Coming soon...
        """
    examples = [
        ["yo"],
        ["me"],
    ]

    lines = 15
    placeholder = "Type or paste text here"
    default1 = dedent(
        """ test 1
        love you
        """
    )
    default2 = dedent(
        """ 测试 1
        爱你
        """
    )
    label1 = "text1"
    label2 = "text2"
    inputs = [
        gr.inputs.Textbox(
            lines=lines, placeholder=placeholder, default=default1, label=label1
        ),
        gr.inputs.Textbox(
            lines=lines, placeholder=placeholder, default=default2, label=label2
        ),
    ]

    out_df = gr.outputs.Dataframe(
        headers=None,
        max_rows=lines,  # 20
        max_cols=None,
        overflow_row_behaviour="paginate",
        type="auto",
        label="To be aligned",
    )
    outputs = [  # tot. 1
        out_df,
    ]

    iface = gr.Interface(
        fn=greet,
        # fn=ubee,
        title=title,
        theme=theme,
        layout="vertical",  # horizontal unaligned
        description=description,
        article=article,
        # inputs="text",
        # outputs="text",
        inputs=inputs,
        outputs=outputs,
        examples=examples,
    )
    iface.launch(enable_queue=False)


if __name__ == "__main__":
    main()