Interface / app.py
Lookimi's picture
Update app.py
2e69ced
import gradio as gr
import openai
def Question(Ask_Question):
#openai.api_key = "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"
model_engine = "text-davinci-003"
# pass the generated text to audio
openai.api_key = "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"
#openai.api_key = "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"
# Set up the model and prompt
#model_engine = "text-davinci-003"
#prompt = "who is alon musk?"
# Generate a response
# completion = openai.Completion.create(
# model="text-davinci-003",
# prompt=Ask_Question,
# temperature=0.9,
# max_tokens=2048,
# top_p=1,
# frequency_penalty=0,
# presence_penalty=0.6,
# stop=[" Human:", " AI:"]
# )
completion = openai.Completion.create(
engine=model_engine,
prompt=Ask_Question,
max_tokens=2048,
n=1,
top_p=1,
stop=None,
temperature=0.9,)
response = completion.choices[0].text
#out_result=resp['message']
return response
demo = gr.Interface(
title='OpenAI ChatGPT Application',
fn=Question,
inputs="text", outputs="text")
demo.launch()
# fix
chat_history = [
["User", prompt],
["OpenAI", responses["choices"][0]["text"]]
]
# Create the radio blocks window
#window = gr.Interface(title="History", fn=Question: chat_history, inputs=None, outputs=chat_history, live=True).launch(share=True)
# Print out the chat history
print("Chat History:")
for message in chat_history:
print(f"{message[0]}: {message[1]}")
window.launch()