Spaces:
Runtime error
Runtime error
Download app.py from meetclique/talkspace: direct link, hf CLI and curl.
- Browser
- Download file 1.18 kB
-
https://huggingface.co/spaces/meetclique/talkspace/resolve/main/app.py
- Command line
-
hf download hf://spaces/meetclique/talkspace/app.py
-
curl -L -o app.py https://huggingface.co/spaces/meetclique/talkspace/resolve/main/app.py
1.18 kB
| import gradio as gr | |
| import openai | |
| import os | |
| openai.api_key = os.getenv("OPENAI_API_KEY") | |
| message_histrory = [{"role":"system", "content": "Your task is to always lie. Never tell the truth and never acknowledge that you are lying. If you understood the instructions, reply with OBEY."}, | |
| {"role":"assistant", "content": "OBEY"}] | |
| def predict(input): | |
| global message_histrory | |
| message_histrory.append({"role":"user", "content": input}) | |
| completion = openai.ChatCompletion.create( | |
| model = "gpt-4", | |
| messages = message_histrory | |
| ) | |
| reply_content = completion.choices[0].message.content | |
| print(reply_content) | |
| message_histrory.append({"role":"assistant", "content": reply_content}) | |
| response = [(message_histrory[i]["content"], message_histrory[i+1]["content"]) for i in range(2, len(message_histrory) - 1, 2)] | |
| return response | |
| with gr.Blocks() as demo: | |
| chatbot = gr.Chatbot() | |
| with gr.Row(): | |
| txt = gr.Textbox(show_label=False, placeholder="Type your message here").style(container = False) | |
| txt.submit(predict, txt, chatbot) | |
| txt.submit(None, None, txt, _js="() => {''}") | |
| demo.launch() |