Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -12,15 +12,10 @@ I request that you provide only the improved version of the text without any fur
|
|
12 |
|
13 |
PREFIX_PROMPT = "Please refine the following text in academic English: \n"
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
openai.api_key =
|
18 |
-
|
19 |
-
if openai.api_key is None:
|
20 |
-
print('[WARN] OPENAI_API_KEY key not found in env')
|
21 |
-
|
22 |
-
def submit(x, simple=False):
|
23 |
-
# everytime we restart a new conversation.
|
24 |
if simple:
|
25 |
results = openai.ChatCompletion.create(
|
26 |
model="gpt-3.5-turbo",
|
@@ -49,8 +44,6 @@ with gr.Blocks() as app:
|
|
49 |
# allow setting API key in gui
|
50 |
with gr.Row():
|
51 |
api_input = gr.Textbox(label="OPENAI_API_KEY", value=openai.api_key, lines=1)
|
52 |
-
def save_api(x): openai.api_key = x
|
53 |
-
api_input.change(save_api, api_input)
|
54 |
|
55 |
simple_checkbox = gr.Checkbox(value=False, label='simple mode (only send the prefix prompt, 0.00142$ cheaper per query)')
|
56 |
|
@@ -63,6 +56,6 @@ with gr.Blocks() as app:
|
|
63 |
cost = gr.Number(label='cost of this query ($)')
|
64 |
|
65 |
text_button = gr.Button("Submit")
|
66 |
-
text_button.click(submit, inputs=[text_input, simple_checkbox], outputs=[text_output, cost])
|
67 |
|
68 |
app.launch()
|
|
|
12 |
|
13 |
PREFIX_PROMPT = "Please refine the following text in academic English: \n"
|
14 |
|
15 |
+
def submit(x, api, simple=False):
|
16 |
+
# reset api key everytime, so it won't save api unsafely...?
|
17 |
+
openai.api_key = api
|
18 |
+
# restart a new conversation.
|
|
|
|
|
|
|
|
|
|
|
19 |
if simple:
|
20 |
results = openai.ChatCompletion.create(
|
21 |
model="gpt-3.5-turbo",
|
|
|
44 |
# allow setting API key in gui
|
45 |
with gr.Row():
|
46 |
api_input = gr.Textbox(label="OPENAI_API_KEY", value=openai.api_key, lines=1)
|
|
|
|
|
47 |
|
48 |
simple_checkbox = gr.Checkbox(value=False, label='simple mode (only send the prefix prompt, 0.00142$ cheaper per query)')
|
49 |
|
|
|
56 |
cost = gr.Number(label='cost of this query ($)')
|
57 |
|
58 |
text_button = gr.Button("Submit")
|
59 |
+
text_button.click(submit, inputs=[text_input, api_input, simple_checkbox], outputs=[text_output, cost])
|
60 |
|
61 |
app.launch()
|