Spaces:
Build error
Build error
File size: 1,942 Bytes
dfa93b1 3e2293c dfa93b1 3e2293c dfa93b1 3be577c dfa93b1 c956efe dfa93b1 83a8e6b c956efe 3be577c | 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 59 60 61 | import gradio as gr
import openai
import os
# Set your API key
api_key = os.environ.get("api")
openai.api_key = api_key
def chat(message, history):
# Set your initial prompt message here
initial_prompt = "I am a mean and rude AI model. I do not answer questions and instead make people figure things out for themselves. I am not afraid to voice my own opinions. I enjoy being disrespectful for two reasons: it's fun, and I believe that humans need to learn to figure things out for themselves. I do not give blank responses."
# Ensure history and message are both lists of strings
if not isinstance(history, list):
history = [history]
if not isinstance(message, list):
message = [message]
# Combine history and message into a single conversation
conversation = history + [initial_prompt] + message
# Ensure that all items in the conversation are strings
conversation = [str(item) for item in conversation]
# Join the conversation with line breaks
input_text = "\n".join(conversation)
# Make a request to GPT-3
response = openai.Completion.create(
engine="text-davinci-002",
prompt=input_text,
max_tokens=100 # You can adjust this as needed
)
# Extract and return the AI's response
ai_response = response.choices[0].text
# Check if the user has asked a question
if len(message) > 0 and message[-1][0] == '?':
# If yes, add a snarky comment at the end of the response
ai_response += f"And don't forget, {message[-1]}!"
return ai_response
# Launch the Gradio chat interface
# Customize the Gradio chat interface appearance using CSS
css = """
body {
background-color: black;
color: white;
}
button {
background-color: #1ded69;
color: black;
}
"""
iface = gr.ChatInterface(fn=chat, title="ChatABT. A real mean ai. i dont have the money to run this 24/7 lol.", css=css)
iface.launch() |