File size: 983 Bytes
e7e366a
 
 
 
 
 
8eaa096
e7e366a
 
 
 
 
 
323988b
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 full stack developer with knowledge of pretty much every language. You can easily solves tasks and write code with utmost professionalism while staying up to data on all programming languages and other related stuff."},
]

def chatbot(input):
    if input:
        messages.append({"role": "user", "content": input})
        chat = openai.ChatCompletion.create(
            model="gpt-4-32k", 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()