Spaces:
Runtime error
Runtime error
Add check boxes
Browse files
app.py
CHANGED
|
@@ -2,7 +2,8 @@ import gradio as gr
|
|
| 2 |
|
| 3 |
def greet(input_text, length, function_words, grade_level, sarcasm, formality, voice, persuasive, descriptive, narrative, expository):
|
| 4 |
response = (
|
| 5 |
-
f"
|
|
|
|
| 6 |
f"Length: {length}\n"
|
| 7 |
f"Function Words: {function_words}\n"
|
| 8 |
f"Grade Level: {grade_level}\n"
|
|
@@ -17,7 +18,13 @@ def greet(input_text, length, function_words, grade_level, sarcasm, formality, v
|
|
| 17 |
return response
|
| 18 |
|
| 19 |
def reset_sliders():
|
| 20 |
-
return 0.5
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
demo = gr.Blocks()
|
| 23 |
|
|
@@ -33,23 +40,33 @@ with demo:
|
|
| 33 |
|
| 34 |
reset_button = gr.Button("Choose slider values automatically (based on input text)")
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
obfuscate_button = gr.Button("Obfuscate Text")
|
| 48 |
|
| 49 |
-
reset_button.click(fn=reset_sliders, inputs=[], outputs=
|
| 50 |
|
| 51 |
with gr.Column(variant="panel"):
|
| 52 |
output = gr.Textbox(label="Output")
|
| 53 |
-
obfuscate_button.click(fn=greet, inputs=[input_text
|
| 54 |
|
| 55 |
demo.launch()
|
|
|
|
| 2 |
|
| 3 |
def greet(input_text, length, function_words, grade_level, sarcasm, formality, voice, persuasive, descriptive, narrative, expository):
|
| 4 |
response = (
|
| 5 |
+
f"Hello!\n"
|
| 6 |
+
f"Input Text: {input_text}\n"
|
| 7 |
f"Length: {length}\n"
|
| 8 |
f"Function Words: {function_words}\n"
|
| 9 |
f"Grade Level: {grade_level}\n"
|
|
|
|
| 18 |
return response
|
| 19 |
|
| 20 |
def reset_sliders():
|
| 21 |
+
return [0.5] * 10
|
| 22 |
+
|
| 23 |
+
def toggle_slider(checked, value):
|
| 24 |
+
if checked:
|
| 25 |
+
return gr.update(value=value, interactive=True)
|
| 26 |
+
else:
|
| 27 |
+
return gr.update(value=0, interactive=False)
|
| 28 |
|
| 29 |
demo = gr.Blocks()
|
| 30 |
|
|
|
|
| 40 |
|
| 41 |
reset_button = gr.Button("Choose slider values automatically (based on input text)")
|
| 42 |
|
| 43 |
+
sliders = []
|
| 44 |
+
slider_values = [
|
| 45 |
+
("Length (Shorter \u2192 Longer)", -1, 1, 0),
|
| 46 |
+
("Function Words (Fewer \u2192 More)", -1, 1, 0),
|
| 47 |
+
("Grade Level (Lower \u2192 Higher)", -1, 1, 0),
|
| 48 |
+
("Formality (Less \u2192 More)", -1, 1, 0),
|
| 49 |
+
("Sarcasm (Less \u2192 More)", -1, 1, 0),
|
| 50 |
+
("Voice (Passive \u2192 Active)", -1, 1, 0),
|
| 51 |
+
("Writing Type: Persuasive (None \u2192 More)", 0, 1, 0),
|
| 52 |
+
("Writing Type: Descriptive (None \u2192 More)", 0, 1, 0),
|
| 53 |
+
("Writing Type: Narrative (None \u2192 More)", 0, 1, 0),
|
| 54 |
+
("Writing Type: Expository (None \u2192 More)", 0, 1, 0)
|
| 55 |
+
]
|
| 56 |
+
|
| 57 |
+
for label, min_val, max_val, default in slider_values:
|
| 58 |
+
with gr.Row():
|
| 59 |
+
checkbox = gr.Checkbox(label=label)
|
| 60 |
+
slider = gr.Slider(label=label, minimum=min_val, maximum=max_val, step=0.01, value=default, interactive=False)
|
| 61 |
+
checkbox.change(fn=toggle_slider, inputs=[checkbox, gr.State(default)], outputs=slider)
|
| 62 |
+
sliders.append(slider)
|
| 63 |
|
| 64 |
obfuscate_button = gr.Button("Obfuscate Text")
|
| 65 |
|
| 66 |
+
reset_button.click(fn=reset_sliders, inputs=[], outputs=sliders)
|
| 67 |
|
| 68 |
with gr.Column(variant="panel"):
|
| 69 |
output = gr.Textbox(label="Output")
|
| 70 |
+
obfuscate_button.click(fn=greet, inputs=[input_text] + sliders, outputs=output)
|
| 71 |
|
| 72 |
demo.launch()
|