File size: 896 Bytes
992c974
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
28
import openai
import gradio as gr


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

message=[{ "role" : "system" , "content" : "You are a helpful and kind AI Assistant." }]

def user_input(input):
    if input:
        input_message={"role" : "user" , "content" : input}
        message.append(input_message)
        chat = openai.ChatCompletion.create( model = 'gpt-3.5-turbo' , messages=message)
        reply=chat.choices[0].message.content
        output_message={"role" : "assistant" , "content" : reply}
        message.append(output_message)

    return reply

input=gr.inputs.Textbox(lines=7 , label='Chat with AI')
output=gr.outputs.Textbox(label='replay')

interface=gr.Interface(fn=user_input, inputs=input, outputs=output, title="AI Chatbot",
             description="Ask anything you want",
             theme="compact").launch(share=True)

interface.launch()