Spaces:
Running
on
Zero
Running
on
Zero
from transformers import AutoTokenizer | |
import gradio as gr | |
def greet(input_text, length, function_words, grade_level, sarcasm, formality, voice, persuasive, descriptive, narrative, expository): | |
response = ( | |
f"Hello!\n" | |
f"Input Text: {input_text}\n" | |
f"Length: {length}\n" | |
f"Function Words: {function_words}\n" | |
f"Grade Level: {grade_level}\n" | |
f"Sarcasm: {sarcasm}\n" | |
f"Formality: {formality}\n" | |
f"Voice: {voice}\n" | |
f"Persuasive: {persuasive}\n" | |
f"Descriptive: {descriptive}\n" | |
f"Narrative: {narrative}\n" | |
f"Expository: {expository}" | |
) | |
return response | |
def reset_sliders(): | |
return [0.5] * 10 | |
def toggle_slider(checked, value): | |
if checked: | |
return gr.update(value=value, interactive=True) | |
else: | |
return gr.update(value=0, interactive=False) | |
demo = gr.Blocks() | |
with demo: | |
with gr.Row(): | |
with gr.Column(variant="panel"): | |
gr.Markdown("# 1) Input Text\n### Enter the text to be obfuscated.") | |
input_text = gr.Textbox( | |
label="Input Text", | |
value="The quick brown fox jumped over the lazy dogs." | |
) | |
gr.Markdown("# 2) Style Element Sliders\n### Adjust the style element sliders to the desired levels to steer the obfuscation.") | |
reset_button = gr.Button("Choose slider values automatically (based on input text)") | |
sliders = [] | |
slider_values = [ | |
("Length (Shorter \u2192 Longer)", -1, 1, 0), | |
("Function Words (Fewer \u2192 More)", -1, 1, 0), | |
("Grade Level (Lower \u2192 Higher)", -1, 1, 0), | |
("Formality (Less \u2192 More)", -1, 1, 0), | |
("Sarcasm (Less \u2192 More)", -1, 1, 0), | |
("Voice (Passive \u2192 Active)", -1, 1, 0), | |
("Writing Type: Persuasive (None \u2192 More)", 0, 1, 0), | |
("Writing Type: Descriptive (None \u2192 More)", 0, 1, 0), | |
("Writing Type: Narrative (None \u2192 More)", 0, 1, 0), | |
("Writing Type: Expository (None \u2192 More)", 0, 1, 0) | |
] | |
for label, min_val, max_val, default in slider_values: | |
with gr.Row(): | |
checkbox = gr.Checkbox(label=label) | |
slider = gr.Slider(label=label, minimum=min_val, maximum=max_val, step=0.01, value=default, interactive=False) | |
checkbox.change(fn=toggle_slider, inputs=[checkbox, gr.State(default)], outputs=slider) | |
sliders.append(slider) | |
obfuscate_button = gr.Button("Obfuscate Text") | |
reset_button.click(fn=reset_sliders, inputs=[], outputs=sliders) | |
with gr.Column(variant="panel"): | |
output = gr.Textbox(label="Output") | |
obfuscate_button.click(fn=greet, inputs=[input_text] + sliders, outputs=output) | |
demo.launch() | |