File size: 829 Bytes
2c4b888
 
 
 
 
 
 
4f3b01c
2c4b888
 
 
 
 
 
 
 
 
 
 
4f3b01c
2c4b888
71aa3f4
2c4b888
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import openai
import os
import gradio as gr

openai.api_key = os.getenv("mykey2")


messages = [{"role": "system", "content": "You are a genius an can answer every question like a philosoph."}]

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
    
title = "Ask any question."

demo = gr.Interface(fn=CustomChatGPT, title = title, inputs = gr.inputs.Textbox(label = "Question", lines = 2, placeholder="E.g. What is the tallest building in the world?"), outputs = gr.outputs.Textbox(label = "Answer"))

demo.launch()