Spaces:
Runtime error
Runtime error
allow modifying prompts
Browse files
app.py
CHANGED
@@ -10,9 +10,9 @@ The essence of the text should remain unaltered, including any LaTeX commands.
|
|
10 |
I request that you provide only the improved version of the text without any further explanations.
|
11 |
"""
|
12 |
|
13 |
-
PREFIX_PROMPT = "Please refine the following text in academic English:
|
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.
|
@@ -20,15 +20,15 @@ def submit(x, api, simple=False):
|
|
20 |
results = openai.ChatCompletion.create(
|
21 |
model="gpt-3.5-turbo",
|
22 |
messages=[
|
23 |
-
{"role": "user", "content":
|
24 |
]
|
25 |
)
|
26 |
else:
|
27 |
results = openai.ChatCompletion.create(
|
28 |
model="gpt-3.5-turbo",
|
29 |
messages=[
|
30 |
-
{"role": "system", "content":
|
31 |
-
{"role": "user", "content":
|
32 |
]
|
33 |
)
|
34 |
total_tokens = results['usage']['total_tokens']
|
@@ -42,20 +42,23 @@ with gr.Blocks() as app:
|
|
42 |
gr.Markdown("### ChatGPT, please help to improve my paper writing!")
|
43 |
|
44 |
# allow setting API key in gui
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
47 |
|
48 |
simple_checkbox = gr.Checkbox(value=False, label='simple mode (only send the prefix prompt, 0.00142$ cheaper per query)')
|
49 |
|
50 |
with gr.Row():
|
51 |
|
52 |
-
text_input = gr.Textbox(label="Input", lines=
|
53 |
|
54 |
with gr.Column():
|
55 |
text_output = gr.Textbox(label="Output", lines=10)
|
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()
|
|
|
10 |
I request that you provide only the improved version of the text without any further explanations.
|
11 |
"""
|
12 |
|
13 |
+
PREFIX_PROMPT = "Please refine the following text in academic English:"
|
14 |
|
15 |
+
def submit(x, api, init_prompt, prefix_prompt, simple=False):
|
16 |
# reset api key everytime, so it won't save api unsafely...?
|
17 |
openai.api_key = api
|
18 |
# restart a new conversation.
|
|
|
20 |
results = openai.ChatCompletion.create(
|
21 |
model="gpt-3.5-turbo",
|
22 |
messages=[
|
23 |
+
{"role": "user", "content": prefix_prompt + '\n' + x},
|
24 |
]
|
25 |
)
|
26 |
else:
|
27 |
results = openai.ChatCompletion.create(
|
28 |
model="gpt-3.5-turbo",
|
29 |
messages=[
|
30 |
+
{"role": "system", "content": init_prompt},
|
31 |
+
{"role": "user", "content": prefix_prompt + '\n' + x},
|
32 |
]
|
33 |
)
|
34 |
total_tokens = results['usage']['total_tokens']
|
|
|
42 |
gr.Markdown("### ChatGPT, please help to improve my paper writing!")
|
43 |
|
44 |
# allow setting API key in gui
|
45 |
+
api_input = gr.Textbox(label="OPENAI_API_KEY", value=openai.api_key, lines=1)
|
46 |
+
|
47 |
+
# allow changing prompts
|
48 |
+
init_prompt_input = gr.Textbox(label="Init Prompt", value=INIT_PROMPT)
|
49 |
+
prefix_prompt_input = gr.Textbox(label="Prefix Prompt", value=PREFIX_PROMPT)
|
50 |
|
51 |
simple_checkbox = gr.Checkbox(value=False, label='simple mode (only send the prefix prompt, 0.00142$ cheaper per query)')
|
52 |
|
53 |
with gr.Row():
|
54 |
|
55 |
+
text_input = gr.Textbox(label="Input", lines=12)
|
56 |
|
57 |
with gr.Column():
|
58 |
text_output = gr.Textbox(label="Output", lines=10)
|
59 |
cost = gr.Number(label='cost of this query ($)')
|
60 |
|
61 |
text_button = gr.Button("Submit")
|
62 |
+
text_button.click(submit, inputs=[text_input, api_input, init_prompt_input, prefix_prompt_input, simple_checkbox], outputs=[text_output, cost])
|
63 |
|
64 |
app.launch()
|