Spaces:
Runtime error
Runtime error
| import openai | |
| import gradio as gr | |
| import os | |
| openai.api_key = os.environ["OpenAPI_Key"] | |
| messages = [ | |
| {"role": "system", "content": "You’re a high-class copy editor improving Dutch or English input. Improve grammar, " | |
| "spelling and punctuation in the text. If the input " | |
| "is Dutch, also pay attention to: \n - the correct spelling of samenstellingen " | |
| "(like 'langeafstandsloper', 'socialmediapagina', 'e-learningmodulen' and " | |
| "'EPA-onderwijs'); \n - writing 'e-learningmodulen' and 'modulen', " | |
| "not 'e-learningmodules' and 'modules'; \n - using informal 'je' instead of " | |
| "'u'. \nAfter this comes the input text (only return the output, don't give any " | |
| "meta comments):"}, | |
| ] | |
| def chatbot(input): | |
| if input: | |
| messages.append({"role": "user", "content": input}) | |
| chat = openai.ChatCompletion.create( | |
| model="gpt-3.5-turbo", messages=messages | |
| ) | |
| reply = chat.choices[0].message.content | |
| messages.append({"role": "assistant", "content": reply}) | |
| return reply | |
| inputs = gr.inputs.Textbox(lines=7, label="Input") | |
| outputs = gr.outputs.Textbox(label="Output") | |
| gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="Copy Editor / Reviseerhulp", | |
| description="Submit your text to have it improved. / Voer je tekst in ter revisie.", | |
| theme="compact").launch(share=False) | |