Spaces:
Running
Running
| import openai | |
| import gradio as gr | |
| # Getting responses using the OpenAI API | |
| def answer_chatgpt(api_key, message): | |
| # OPENAI API KEY | |
| openai.api_key = api_key | |
| prompt = (f"You are GPT-3, you are in a web interface and reply to my following message: {message}") | |
| response = openai.Completion.create( | |
| engine="text-davinci-003", | |
| prompt=prompt, | |
| max_tokens=1024 | |
| ) | |
| # Displaying the answer on the screen | |
| answer = response["choices"][0]["text"] | |
| return answer | |
| # User input | |
| chatbot = gr.Interface( | |
| fn=answer_chatgpt, | |
| inputs=["text", "text"], | |
| outputs="text", | |
| title="π€ ChatGPT-Python π", | |
| description="ChatGPT-Python is a software that allows you to talk to GPT-3 with a web interface using the openai api" | |
| ) | |
| chatbot.launch() |