gezirehberifaz1 / app.py
Destovania's picture
Stream test #2
53a9fc0
import gradio as gr
import openai
# Getting responses using the OpenAI API
def response_chatgpt(api_key, message: str):
# OPENAI API KEY
openai.api_key = api_key
response = openai.Completion.create(
engine="text-davinci-003",
prompt=message,
max_tokens=1024,
stream=False,
)
# Choosing best conversation
completion_text = ''
# iterate through the stream of events
for event in response:
event_text = event['choices'][0]['text'] # extract the text
completion_text += event_text # append the text
return completion_text
# User input and web interface
chatbot = gr.Interface(
fn=response_chatgpt,
inputs=["text", "text"],
outputs="text",
)
chatbot.launch()