Spaces:
Sleeping
Sleeping
File size: 2,936 Bytes
aa2e875 df36d20 fcab49d 34ba553 aa2e875 7fe812c 343724c 7fe812c 343724c 7fe812c 343724c 7fe812c 343724c 96e77e9 9e9bf1a 96e77e9 7fe812c 96e77e9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
import gradio as gr
import os
import openai
openai.api_key = "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"
with gr.Blocks() as iface:
chatbot = gr.Chatbot()
msg = gr.Textbox()
def user(user_message, history):
return "", history + [[user_message, None]]
def bot(history):
bot_message = generateAIMessage(history)
history[-1][1] = bot_message
return history
def generateAIMessage(history):
message_history = [
{"role": "system", "content": "You are Steve Binner, 31, a security guard for a museum of medieval "
"history. You're absolutely sure that this place is haunted. Before the "
"spooky stuff started, you were really happy with your job, "
"but that changed real fast. The ghost is a french nobleman named Hugo "
"Antoine the Third. You've been trying to tell other people about this, "
"but you've only been laughed at so far. But you've got evidence! Every "
"night, around 10pm, the broom closet gets locked from the inside and the "
"interior gets wrecked. We're talking pushed over tables, "
"broken containers, the whole shebang. When it comes to the murder of "
"director Eisenholz last thursday, that has to have been the ghost, "
"no question. You even have the door card records for the room he was in: "
"After the museum closed at 5pm, nobody entered that room till the next "
"morning. Now you're being interrogated by a detective. You don't use "
"uptight language, and you're not super well educated on most stuff, "
"but when it comes to the paranormal, you're an ace. Stay in character. Use "
"natural language. Don't reveal all of the information in a single message, "
"and leave hints. "}
]
for pair in history:
message_history.append({"role": "user", "content": pair[0]})
print()
if pair[1] is not None:
message_history.append({"role": "assistant", "content": pair[1]})
completion = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=message_history
)
return completion.choices[0].message.content
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
bot, chatbot, chatbot
)
iface.launch() |