hrishikeshagi/QuestionGenerator
0
1import openai2import gradio as gr3 4openai.api_key = "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"5 6def openai_chat(input_prompt):7 8 template = """9 Sentence: India won the 1983 Cricket World Cup which was the 3rd edition of the Cricket World Cup tournament.10 Question: Who won the 1983 Cricket World Cup ______ ? Answer: India11 Sentence: Google was founded on September 4, 1998, by Larry Page and Sergey Brin.12 Question: In which year was Google founded ______? Answer: 199813 """14 15 input_prompt = "Sentence: " + input_prompt16 prompt = template + input_prompt17 18 completion = openai.Completion.create(engine="davinci", 19 prompt=prompt, 20 max_tokens=64, 21 temperature=0.7)22 23 message = completion.choices[0].text24 output_list = message.split("\n")25 out_index = []26 for idx, sentence in enumerate(output_list):27 if "Question" in sentence:28 out_index.append(idx)29 30 if out_index:31 return output_list[min(out_index)]32 33gr.Interface(fn = openai_chat,34 inputs = ["text"],35 outputs = ["text"]).launch(debug = True)36 