Spaces:
Sleeping
Sleeping
Mya-Mya
commited on
Commit
·
4f1e4fb
1
Parent(s):
8f78096
Create Frontend and main
Browse files- app.py +4 -0
- frontend.py +44 -0
app.py
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from dummymixer import DummyMixer
|
2 |
+
from frontend import launch
|
3 |
+
|
4 |
+
launch(DummyMixer())
|
frontend.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from mixer import Mixer
|
2 |
+
from examples import examples
|
3 |
+
|
4 |
+
def launch(mixer:Mixer):
|
5 |
+
# Runners
|
6 |
+
def clear():
|
7 |
+
return ""
|
8 |
+
def mix(sentence_A:str,sentence_B:str,A_ratio:float):
|
9 |
+
return mixer.mix_sentences(sentence_A, sentence_B, A_ratio)
|
10 |
+
|
11 |
+
# Components
|
12 |
+
from gradio import Blocks, Slider, Markdown, Row, Column, Button, TextArea, Examples
|
13 |
+
with Blocks() as app:
|
14 |
+
Markdown(
|
15 |
+
"# Sentence Mixer\n"\
|
16 |
+
"Linear combination of the encoder hidden states generates mixed sentences."
|
17 |
+
)
|
18 |
+
with Row():
|
19 |
+
with Column():
|
20 |
+
sentenceA_textarea = TextArea(label="Sentence A", lines=4)
|
21 |
+
sentenceA_clearbutton = Button(value="Clear", size="sm")
|
22 |
+
with Column():
|
23 |
+
sentenceB_textarea = TextArea(label="Sentence B", lines=4)
|
24 |
+
sentenceB_clearbutton = Button(value="Clear", size="sm")
|
25 |
+
with Row():
|
26 |
+
Aratio_slider = Slider(label="A Ratio", minimum=0.0, maximum=1.0, value=0.5, step=0.001)
|
27 |
+
mix_button = Button(value="Mix", variant="primary")
|
28 |
+
output_textarea = TextArea(label="Mixed Sentence", lines=2)
|
29 |
+
Examples(
|
30 |
+
examples,
|
31 |
+
inputs=[sentenceA_textarea,sentenceB_textarea,Aratio_slider],
|
32 |
+
outputs=output_textarea
|
33 |
+
)
|
34 |
+
|
35 |
+
# Bindings
|
36 |
+
sentenceA_clearbutton.click(clear, inputs=None, outputs=sentenceA_textarea)
|
37 |
+
sentenceB_clearbutton.click(clear, inputs=None, outputs=sentenceB_textarea)
|
38 |
+
mix_button.click(
|
39 |
+
mix,
|
40 |
+
inputs=[sentenceA_textarea,sentenceB_textarea,Aratio_slider],
|
41 |
+
outputs=output_textarea
|
42 |
+
)
|
43 |
+
|
44 |
+
app.launch()
|