chatgpt-python / app.py
Damonho316's picture
Update app.py
00c6b07
raw
history blame contribute delete
586 Bytes
import openai
import gradio as gr
# Getting responses using the OpenAI API
def response_chatgpt(api_key, message):
# OPENAI API KEY
openai.api_key = api_key
prompt = (f"{message}")
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=1024
)
# Displaying the answer on the screen
result = response["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"]["text"]
return result
# User input
chatbot = gr.Interface(
fn=response_chatgpt,
inputs=["text", "text"],
outputs="text",
)
chatbot.launch()