hrishikesh
Update app.py
07eabf3
import openai
import gradio as gr
openai.api_key = "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"
def openai_chat(input_prompt):
template = """
Sentence: India won the 1983 Cricket World Cup which was the 3rd edition of the Cricket World Cup tournament.
Question: Who won the 1983 Cricket World Cup ______ ? Answer: India
Sentence: Google was founded on September 4, 1998, by Larry Page and Sergey Brin.
Question: In which year was Google founded ______? Answer: 1998
"""
input_prompt = "Sentence: " + input_prompt
prompt = template + input_prompt
completion = openai.Completion.create(engine="davinci",
prompt=prompt,
max_tokens=64,
temperature=0.7)
message = completion.choices[0].text
output_list = message.split("\n")
out_index = []
for idx, sentence in enumerate(output_list):
if "Question" in sentence:
out_index.append(idx)
if out_index:
return output_list[min(out_index)]
gr.Interface(fn = openai_chat,
inputs = ["text"],
outputs = ["text"]).launch(debug = True)