File size: 1,695 Bytes
4f1e4fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from mixer import Mixer
from examples import examples

def launch(mixer:Mixer):
    # Runners
    def clear():
        return ""
    def mix(sentence_A:str,sentence_B:str,A_ratio:float):
        return mixer.mix_sentences(sentence_A, sentence_B, A_ratio)
    
    # Components
    from gradio import Blocks, Slider, Markdown, Row, Column, Button, TextArea, Examples
    with Blocks() as app:
        Markdown(
            "# Sentence Mixer\n"\
            "Linear combination of the encoder hidden states generates mixed sentences."
        )
        with Row():
            with Column():
                sentenceA_textarea = TextArea(label="Sentence A", lines=4)
                sentenceA_clearbutton = Button(value="Clear", size="sm")
            with Column():
                sentenceB_textarea = TextArea(label="Sentence B", lines=4)
                sentenceB_clearbutton = Button(value="Clear", size="sm")
        with Row():
            Aratio_slider = Slider(label="A Ratio", minimum=0.0, maximum=1.0, value=0.5, step=0.001)
            mix_button = Button(value="Mix", variant="primary")
        output_textarea = TextArea(label="Mixed Sentence", lines=2)
        Examples(
            examples,
            inputs=[sentenceA_textarea,sentenceB_textarea,Aratio_slider],
            outputs=output_textarea
        )

        # Bindings
        sentenceA_clearbutton.click(clear, inputs=None, outputs=sentenceA_textarea)
        sentenceB_clearbutton.click(clear, inputs=None, outputs=sentenceB_textarea) 
        mix_button.click(
            mix,
            inputs=[sentenceA_textarea,sentenceB_textarea,Aratio_slider],
            outputs=output_textarea
        )

    app.launch()