Spaces:
Sleeping
Sleeping
| # 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=False).launch(share=True) | |
| # Launch interface | |
| demo.launch(share=true) |