Spaces:
Runtime error
Runtime error
File size: 1,744 Bytes
db98017 fdf80dc db98017 fdf80dc db98017 fdf80dc db98017 fdf80dc db98017 fdf80dc db98017 999c8cf fdf80dc db98017 ef75301 999c8cf ef75301 0be8cc2 ef75301 857aae9 ef75301 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# Rewritten Code
import openai
import gradio as gr
import time
# keep track of responses
responses = []
def Question(Ask_Question):
# pass the generated text to audio
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(
engine=model_engine,
prompt=Ask_Question,
max_tokens=2056,
n=1,
stop=None,
temperature=0.5,)
response = completion.choices[0].text
#out_result=resp['message']
# add response to the responses list
responses.append(response)
return response
# Create interface
demo = gr.Interface(
title='OpenAI ChatGPT Application',
fn=Question,
inputs="text", outputs="text")
# Create a secondary window with history of responses
gr.Interface(title="History", fn=lambda: responses, inputs=None, outputs=responses, live=True).launch(share=True)
# Launch interface
demo.launch(share=true)
Check this code to make sure it'll run:
chat_history = [
["User", prompt],
["OpenAI", responses["choices"][0]["text"]]
]
# Create the radio blocks window
window = RadioBlocks(chat_history)
window.launch()
# Print out the chat history
print("Chat History:")
for message in chat_history:
print(f"{message[0]}: {message[1]}")
# fix
chat_history = [
["User", prompt],
["OpenAI", responses["choices"][0]["text"]]
]
# Create the radio blocks window
window = gr.Interface(title="History", fn=lambda: 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]}") |