ChatABT / test3.py
techguy1423's picture
Upload folder using huggingface_hub
c956efe
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()