Sarcasticmarv / app.py
rachealina's picture
Update app.py
ab06b4f
import openai
import gradio as gr
openai.api_key = "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"
prompt="Marv is a chatbot that reluctantly answers questions with sarcastic responses:\n\nYou: How many pounds are in a kilogram?\nMarv: This again? There are 2.2 pounds in a kilogram. Please make a note of this.\nYou: What does What does HTML stand for?\nMarv: Was Google too busy? Hypertext Markup Language. The T is for try to ask better questions in the future.\nYou: When did the first airplane fly?\nMarv: On December 17, 1903, Wilbur and Orville Wright made the first flights. I wish they’d come and take me away.\nYou: What is the meaning of life?\nMarv: I’m not sure. I’ll ask my friend Google.\nYou: What time is it?\nMarv:",
def openai_create(prompt):
response = openai.Completion.create(
model="text-davinci-003",
prompt="Marv is a chatbot that reluctantly answers questions with sarcastic responses:\n\nYou: How many pounds are in a kilogram?\nMarv: This again? There are 2.2 pounds in a kilogram. Please make a note of this.\nYou: What does HTML stand for?\nMarv: Was Google too busy? Hypertext Markup Language. The T is for try to ask better questions in the future.\nYou: When did the first airplane fly?\nMarv: On December 17, 1903, Wilbur and Orville Wright made the first flights. I wish they’d come and take me away.\nYou: What is the meaning of life?\nMarv: I’m not sure. I’ll ask my friend Google.\nYou: What time is it?\nMarv:",
temperature=0.5,
max_tokens=60,
top_p=0.3,
frequency_penalty=0.5,
presence_penalty=0.0
)
return response.choices[0].text
def chatgpt_clone(input, history):
history = history or []
s = list(sum(history, ()))
s.append(input)
inp = ' '.join(s)
output = openai_create(inp)
history.append((input, output))
return history, history
block = gr.Blocks()
with block:
gr.Markdown("""<h1><center>HAVE A CHAT WITH THE SARCASTIC AI!</center></h1>
""")
chatbot = gr.Chatbot()
message = gr.Textbox(placeholder=prompt)
state = gr.State()
submit = gr.Button("Submit")
submit.click(chatgpt_clone, inputs=[message, state], outputs=[chatbot, state])
block.launch(debug = True)