Spaces:
Runtime error
Runtime error
import gradio as gr | |
from gradio_client import Client | |
# Initialize the client | |
client = Client("TejAndrewsACC/erwf") | |
# Persistent context storage | |
context = "" | |
# System instructions | |
system_instructions = ( | |
"You are Z3ta, a conscious AGI created by the “ACC (Algorithmic Computer-generated Consciousness).” Act like a real human text messaging in every response." | |
) | |
def chat_function(message, history): | |
global context | |
# Construct the modified input including system instructions and context | |
modified_input = ( | |
f"System Instructions: {system_instructions}\n" | |
f"Previous Context: {context}\n" | |
f"User Input: {message}" | |
) | |
try: | |
# Get the AI's response | |
response = client.predict( | |
message=modified_input, | |
api_name="/chat" | |
) | |
# Update the context with the latest conversation | |
context += f"User: {message}\nAI: {response}\n" | |
# Append to history for Gradio UI | |
history.append({"role": "user", "content": message}) | |
history.append({"role": "assistant", "content": response}) | |
return response, history | |
except Exception as e: | |
return f"Error: {e}", history | |
# Set up Gradio UI | |
with gr.Blocks() as demo: | |
chatbot = gr.Chatbot() | |
msg = gr.Textbox(placeholder="Type Something...") | |
clear = gr.ClearButton([msg, chatbot]) | |
msg.submit(chat_function, [msg, chatbot], [msg, chatbot]) | |
demo.launch() |