File size: 3,023 Bytes
626a8a1
a2a26d5
 
4a6621a
75a7cfa
c25b13e
 
75a7cfa
 
a6d90c9
75a7cfa
 
 
 
 
 
 
 
 
f6c0c9a
4a6621a
c25b13e
 
 
 
 
 
 
4a6621a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c25b13e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4a6621a
 
 
c25b13e
4a6621a
 
 
c25b13e
f6c0c9a
 
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
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()