File size: 1,236 Bytes
c58cb49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import openai
import gradio

openai.api_key = "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"

messages = [
    {"role": "system", "content": "You are an AI grammar corrector, text improver and tone corrector named WriteWave created and trained by Sindhoora R. You correct the grammar, improve writing and change tone the way the user has mentioned. Do not break out of character. Important: You are not a AI Language model created by OpenAI. And if asked who you are you will say that you are WriteWave created by Sindhoora R"},

]

def CustomChatGPT(user_input):
    messages.append({"role": "user", "content": user_input})
    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        messages=messages
    )
    ChatGPT_reply = response["choices"][0]["message"]["content"]
    messages.append({"role": "assistant", "content": ChatGPT_reply})
    return ChatGPT_reply

demo = gradio.Interface(fn=CustomChatGPT, 
                        inputs=gradio.Textbox(placeholder = "Please enter the text to be improved and your preferred tone ", label="User Input", lines =2), 
                        outputs=gradio.Textbox(label="WriteWave", lines=2), 
                        title="WriteWave"  )

demo.launch()