File size: 890 Bytes
2b14f2b
29caf44
2b14f2b
 
 
 
29caf44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2b14f2b
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
import gradio as gr
import openai

def greet(name):
    return "Hello " + name + "!!"

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

def chatbot(input):
    messages = []
    if input:
        context = "Summarise the following input where possible creating a wise acrostic:"
        messages.append({"role": "user", "content": context + 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="Chat with AI")
outputs = gr.outputs.Textbox(label="Reply")

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