import os import openai import gradio as gr #1: OpenAI Chat def openai_chat(prompt): completions = openai.Completion.create( engine="text-davinci-003", prompt=prompt, max_tokens=1024, n=1, temperature=0.5, ) message = completions.choices[0].text return message.strip() #2: Gradio Interface Function def chatbot(input, history=[]): output = openai_chat(input) history.append((input, output)) return history, history title ='ChatGPT response' description = "Ask Q and get ChatGPT response" examples = [ ["India is in which continent?"], ["Name the Indian cricket team's captain"], ["Who is the president of America"] ] #3: Launch Interface openai_chat_demo = gr.Interface(fn = chatbot, inputs = ["text",'state'], outputs = ["chatbot",'state'], title = title, description = description ,examples = examples) #.launch(debug = True) ################################## #2: from content_only import GET_gpt_output ############################## demo = gr.TabbedInterface([openai_chat_demo, GET_gpt_output ], ["ChatGPT","Contents ONLY"]) if __name__ == "__main__": demo.launch()