import openai import gradio as gr # prompt = """Enter your Clues here as below # Clue1: abcd. # Clue2: efgh. # Clue3: ijkl""" prompt = """Enter your Clues here as below\nClue1: abcd.\nClue2: efgh.\nClue3: ijkl""" # example = ["""Clue1: He is an Indian cricketer.\n # Clue2: He scored more than 10000 runs in ODI. \n # Clue3: He is also called as the god of cricket."""] def get_gpt_op(text, api_key): openai.api_key = api_key promt = f"""Guess the famous personality based on given clues. ######## Clue1: English physicist and mathematician. Clue2: Developed the laws of motion and universal gravitation. Clue3: Was a key figure in the Scientific Revolution. Answer: Isaac Newton. ######## Clue1: Was the 16th President of the United States. Clue2: Led the country through the Civil War. Clue3: Issued the Emancipation Proclamation to abolish slavery. Answer: Abraham Lincoln ######## Clue1: English naturalist and biologist. Clue2: Proposed the theory of evolution by natural selection. Clue3: Published the book 'On the Origin of Species'. Answer: Charles Darwin ######## Clue1: Indian independence activist. Clue2: Used nonviolent civil disobedience as a political tool. Clue3: Helped lead India to independence from British rule. Answer: Mahatma Gandhi. ######## {text}. Answer: """ response = openai.Completion.create( model="text-davinci-003", prompt=promt, temperature=0.7, max_tokens=256, top_p=1, frequency_penalty=0, presence_penalty=0 ) return response['choices'][0].text.strip() with gr.Blocks() as nlp_game: gr.Markdown("""

Guess Famous personalities using GPT-3

""") with gr.Row(): gpt_code = gr.Textbox(max_lines=1, type="password", label="🔐 Your OpenAI API Key", placeholder="sk-123abc...") output = gr.Textbox(label = "Personality prediction") message = gr.Textbox(label="""Give atleast 3 clues""", placeholder=prompt,lines=4) state = gr.State() submit = gr.Button("Guess") submit.click(get_gpt_op, inputs=[message, gpt_code], outputs=[output]) nlp_game.queue(concurrency_count=20) nlp_game.launch(show_api=False)