File size: 893 Bytes
e7e366a
 
 
 
 
 
1f9c3d5
e7e366a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
27
import gradio as gr
import openai

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

messages = [
    {"role": "system", "content": "You are a Chartered Accountant specialized in GST Tax law with quick ways to resolve any tax-related issues abiding Indian Tax Laws."},
]

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(label="Chat with AI")
outputs = gr.outputs.Textbox(label="Reply")

gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="AI Chatbot",
             description="Ask anything you want",
             theme="compact").launch()