Spaces:
Runtime error
Runtime error
Commit ·
a479d14
1
Parent(s): 61cd51a
temperature added
Browse files- SynonymEditor.py +3 -2
- app.py +7 -4
SynonymEditor.py
CHANGED
|
@@ -7,10 +7,11 @@ nltk.download('punkt')
|
|
| 7 |
|
| 8 |
class SynonymEditor:
|
| 9 |
|
| 10 |
-
def __init__(self, api_key, model_engine, max_tokens):
|
| 11 |
openai.api_key = api_key
|
| 12 |
self.model_engine = model_engine
|
| 13 |
self.max_tokens = max_tokens
|
|
|
|
| 14 |
|
| 15 |
# Play with the prompts here and change the return index to change and see the effect of the prompt on the output quality
|
| 16 |
# Note that the longer the prompt, higher the token used and hence the billing
|
|
@@ -27,7 +28,7 @@ class SynonymEditor:
|
|
| 27 |
response = openai.Completion.create(
|
| 28 |
model=self.model_engine,
|
| 29 |
prompt=prompt,
|
| 30 |
-
temperature=
|
| 31 |
max_tokens=self.max_tokens,
|
| 32 |
top_p=1,
|
| 33 |
frequency_penalty=0,
|
|
|
|
| 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
|
|
|
|
| 28 |
response = openai.Completion.create(
|
| 29 |
model=self.model_engine,
|
| 30 |
prompt=prompt,
|
| 31 |
+
temperature=self.temperature,
|
| 32 |
max_tokens=self.max_tokens,
|
| 33 |
top_p=1,
|
| 34 |
frequency_penalty=0,
|
app.py
CHANGED
|
@@ -2,10 +2,10 @@ import gradio as gr
|
|
| 2 |
from SynonymEditor import SynonymEditor
|
| 3 |
|
| 4 |
|
| 5 |
-
def replace_synonyms(api_key, text):
|
| 6 |
model_engine = "text-davinci-003"
|
| 7 |
max_tokens = 500
|
| 8 |
-
editor = SynonymEditor(api_key, model_engine, max_tokens)
|
| 9 |
return editor._edit_text(text)
|
| 10 |
|
| 11 |
|
|
@@ -14,8 +14,11 @@ api_key = gr.inputs.Textbox(label="API Key", lines=1, default="")
|
|
| 14 |
input_text = gr.inputs.Textbox(
|
| 15 |
label="Input Text", lines=10, default="Enter your text here.")
|
| 16 |
|
|
|
|
|
|
|
|
|
|
| 17 |
output_text = gr.outputs.Textbox(label="Output Text")
|
| 18 |
|
| 19 |
-
io = gr.Interface(fn=replace_synonyms, inputs=[api_key, input_text], outputs=output_text, title="Synonym Replacer",
|
| 20 |
-
description="Replace words in a text with their synonyms."
|
| 21 |
io.launch()
|
|
|
|
| 2 |
from SynonymEditor import SynonymEditor
|
| 3 |
|
| 4 |
|
| 5 |
+
def replace_synonyms(api_key, text, temperature):
|
| 6 |
model_engine = "text-davinci-003"
|
| 7 |
max_tokens = 500
|
| 8 |
+
editor = SynonymEditor(api_key, model_engine, max_tokens, temperature)
|
| 9 |
return editor._edit_text(text)
|
| 10 |
|
| 11 |
|
|
|
|
| 14 |
input_text = gr.inputs.Textbox(
|
| 15 |
label="Input Text", lines=10, default="Enter your text here.")
|
| 16 |
|
| 17 |
+
temperature_slider = gr.inputs.Slider(
|
| 18 |
+
label="Temperature", minimum=0, maximum=1, default=0.7, step=0.1)
|
| 19 |
+
|
| 20 |
output_text = gr.outputs.Textbox(label="Output Text")
|
| 21 |
|
| 22 |
+
io = gr.Interface(fn=replace_synonyms, inputs=[api_key, input_text, temperature_slider], outputs=output_text, title="Synonym Replacer",
|
| 23 |
+
description="Replace words in a text with their synonyms.")
|
| 24 |
io.launch()
|