Spaces:
Runtime error
Runtime error
Commit
·
0cc7583
1
Parent(s):
1d0916c
German
Browse files- SynonymEditor.py +16 -5
- __pycache__/SynonymEditor.cpython-39.pyc +0 -0
- __pycache__/app.cpython-39.pyc +0 -0
- app.py +9 -3
SynonymEditor.py
CHANGED
@@ -7,22 +7,33 @@ nltk.download('punkt')
|
|
7 |
|
8 |
class SynonymEditor:
|
9 |
|
10 |
-
def __init__(self, api_key, model_engine, max_tokens, temperature):
|
11 |
openai.api_key = api_key
|
12 |
self.model_engine = model_engine
|
13 |
self.max_tokens = max_tokens
|
14 |
self.temperature = temperature
|
|
|
15 |
|
16 |
# Play with the prompts here and change the return index to change and see the effect of the prompt on the output quality
|
17 |
# Note that the longer the prompt, higher the token used and hence the billing
|
18 |
def _get_prompt(self, sentence, few_shots):
|
19 |
if (few_shots):
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
22 |
elif "__QUOTE__" in sentence:
|
23 |
-
|
|
|
|
|
|
|
24 |
else:
|
25 |
-
|
|
|
|
|
|
|
26 |
return prompt
|
27 |
|
28 |
# Call the OpenAI API here
|
|
|
7 |
|
8 |
class SynonymEditor:
|
9 |
|
10 |
+
def __init__(self, api_key, model_engine, max_tokens, temperature, language):
|
11 |
openai.api_key = api_key
|
12 |
self.model_engine = model_engine
|
13 |
self.max_tokens = max_tokens
|
14 |
self.temperature = temperature
|
15 |
+
self.language = language
|
16 |
|
17 |
# Play with the prompts here and change the return index to change and see the effect of the prompt on the output quality
|
18 |
# Note that the longer the prompt, higher the token used and hence the billing
|
19 |
def _get_prompt(self, sentence, few_shots):
|
20 |
if (few_shots):
|
21 |
+
if (self.language == "de"):
|
22 |
+
prompt = 'Modernisiere den Text. Behalte die Inhalte von Klammern "" bei.\n' + \
|
23 |
+
few_shots + "\nEingang:" + sentence + " Ausgang:"
|
24 |
+
else:
|
25 |
+
prompt = "Replace exactly one word with a synonym while preserving the overall sentence structure and meaning.\n" + \
|
26 |
+
few_shots + "\nInput:" + sentence + " Output:"
|
27 |
elif "__QUOTE__" in sentence:
|
28 |
+
if (self.language == "de"):
|
29 |
+
prompt = 'Modernisiere den Text. Behalte die Inhalte von Klammern "" bei.\n'+sentence+'\n'
|
30 |
+
else:
|
31 |
+
prompt = "Replace exactly one word with a synonym while preserving __QUOTE__ in the following sentence:\n"+sentence+"\n"
|
32 |
else:
|
33 |
+
if (self.language == "de"):
|
34 |
+
prompt = 'Modernisiere den Text. Behalte die Inhalte von Klammern "" bei.\n'+sentence+'\n'
|
35 |
+
else:
|
36 |
+
prompt = "Replace exactly one word with a synonym in the following sentence:\n"+sentence+"\n"
|
37 |
return prompt
|
38 |
|
39 |
# Call the OpenAI API here
|
__pycache__/SynonymEditor.cpython-39.pyc
CHANGED
Binary files a/__pycache__/SynonymEditor.cpython-39.pyc and b/__pycache__/SynonymEditor.cpython-39.pyc differ
|
|
__pycache__/app.cpython-39.pyc
CHANGED
Binary files a/__pycache__/app.cpython-39.pyc and b/__pycache__/app.cpython-39.pyc differ
|
|
app.py
CHANGED
@@ -1,11 +1,14 @@
|
|
1 |
import gradio as gr
|
2 |
from SynonymEditor import SynonymEditor
|
3 |
|
|
|
4 |
|
5 |
-
|
|
|
6 |
model_engine = "text-davinci-003"
|
7 |
max_tokens = 500
|
8 |
-
editor = SynonymEditor(api_key, model_engine,
|
|
|
9 |
if (use_few_shots):
|
10 |
return editor._edit_text(text, few_shots)
|
11 |
else:
|
@@ -15,6 +18,9 @@ def replace_synonyms(api_key, text, use_few_shots, few_shots, temperature):
|
|
15 |
api_key = gr.inputs.Textbox(label="OpenAI API Key", lines=1,
|
16 |
default="YOUR_API_KEY_HERE")
|
17 |
|
|
|
|
|
|
|
18 |
use_few_shots = gr.inputs.Checkbox(label="Use Few Shots", default=True)
|
19 |
|
20 |
few_shots = gr.inputs.Textbox(
|
@@ -28,6 +34,6 @@ temperature_slider = gr.inputs.Slider(
|
|
28 |
|
29 |
output_text = gr.outputs.Textbox(label="Output Text")
|
30 |
|
31 |
-
io = gr.Interface(fn=replace_synonyms, inputs=[api_key, input_text, use_few_shots, few_shots, temperature_slider], outputs=output_text, title="Synonym Replacer",
|
32 |
description="Replace words in a text with their synonyms.")
|
33 |
io.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from SynonymEditor import SynonymEditor
|
3 |
|
4 |
+
LANGS = ["de", "en"]
|
5 |
|
6 |
+
|
7 |
+
def replace_synonyms(api_key, language, text, use_few_shots, few_shots, temperature):
|
8 |
model_engine = "text-davinci-003"
|
9 |
max_tokens = 500
|
10 |
+
editor = SynonymEditor(api_key, model_engine,
|
11 |
+
max_tokens, temperature, language)
|
12 |
if (use_few_shots):
|
13 |
return editor._edit_text(text, few_shots)
|
14 |
else:
|
|
|
18 |
api_key = gr.inputs.Textbox(label="OpenAI API Key", lines=1,
|
19 |
default="YOUR_API_KEY_HERE")
|
20 |
|
21 |
+
language = gr.inputs.Dropdown(
|
22 |
+
label="Language", choices=LANGS, default="en")
|
23 |
+
|
24 |
use_few_shots = gr.inputs.Checkbox(label="Use Few Shots", default=True)
|
25 |
|
26 |
few_shots = gr.inputs.Textbox(
|
|
|
34 |
|
35 |
output_text = gr.outputs.Textbox(label="Output Text")
|
36 |
|
37 |
+
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",
|
38 |
description="Replace words in a text with their synonyms.")
|
39 |
io.launch()
|