File size: 2,083 Bytes
d54ec92
 
 
0cc7583
d54ec92
0cc7583
 
d54ec92
 
0cc7583
 
43ab1fa
 
 
 
d54ec92
 
43ab1fa
2fa63a8
43ab1fa
0cc7583
64941b8
0cc7583
64941b8
43ab1fa
 
 
d54ec92
 
 
 
a479d14
 
 
d54ec92
 
0cc7583
a479d14
d54ec92
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
import gradio as gr
from SynonymEditor import SynonymEditor

LANGS = ["de", "en"]


def replace_synonyms(api_key, language, text, use_few_shots, few_shots, temperature):
    model_engine = "text-davinci-003"
    max_tokens = 500
    editor = SynonymEditor(api_key, model_engine,
                           max_tokens, temperature, language)
    if (use_few_shots):
        return editor._edit_text(text, few_shots)
    else:
        return editor._edit_text(text)


api_key = gr.inputs.Textbox(label="OpenAI API Key", lines=1,
                            default="YOUR_API_KEY_HERE")

language = gr.inputs.Dropdown(
    label="Language", choices=LANGS, default="de")

use_few_shots = gr.inputs.Checkbox(label="Use Few Shots", default=False)

few_shots = gr.inputs.Textbox(
    label="Few Shots", lines=10, default='Input: The cat sat on the mat. Output: The cat sat on the rug. \nInput: "She walked to the store to buy some milk.", she said to her mother. Output: "She walked to the shop to buy some milk.", she said to her mother.\nInput: He cooked a "perfect" dinner for his family. Output: He prepared a "perfect" dinner for his family.\nInput: The sun was shining brightly in the sky. Output: The sun was beaming brightly in the sky.\nInput: Little Red Riding Hood was enjoying the warm summer day so much, that she didn\'t notice a sinister shadow approaching out of the forest behind her...	 Output: Little Red Riding Hood was enjoying the warm summer day so much, that she didn\'t notice a dark shadow approaching out of the forest behind her...')

input_text = gr.inputs.Textbox(
    label="Input Text", lines=10, default="Enter your text here.")

temperature_slider = gr.inputs.Slider(
    label="Temperature", minimum=0, maximum=1, default=0.7, step=0.1)

output_text = gr.outputs.Textbox(label="Output Text")

io = gr.Interface(fn=replace_synonyms, inputs=[api_key, language, input_text, use_few_shots, few_shots, temperature_slider], outputs=output_text, title="Synonym Replacer",
                  description="Replace words in a text with their synonyms.")
io.launch()