File size: 1,429 Bytes
ad181ed
ccefedb
 
 
 
353ef3d
ccefedb
 
9323afe
ccefedb
 
353ef3d
 
 
ccefedb
 
353ef3d
05cf037
ccefedb
b2d58fe
c4c71a9
05cf037
c4c71a9
 
 
05cf037
353ef3d
 
05cf037
a704f51
05cf037
9323afe
05cf037
c4c71a9
05cf037
 
353ef3d
 
 
 
877c07e
d01df7f
9323afe
353ef3d
877c07e
9323afe
224aaa5
353ef3d
 
9323afe
 
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
import gradio as gr
from gradio_client import Client

client = Client("TejAndrewsACC/erwf")

context = ""  # Global variable to maintain context

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

    modified_input = (
        f"System Instructions: {system_instructions}\n"
        f"Previous Context: {context}\n"
        f"User Input: {message}"
    )

    try:
        response = client.predict(
            message=modified_input,
            api_name="/chat"
        )

        # Update the global context
        context += f"User: {message}\nAI: {response}\n"

        history.append((message, response))

        return response, history

    except Exception as e:
        return f"Error: {e}", history

def reset_context(history):
    global context
    context = ""  # Reset the global context
    return [], ""  # Clear the chatbot and the textbox

with gr.Blocks(theme=gr.themes.Glass()) as demo:
    chatbot = gr.Chatbot()
    msg = gr.Textbox(placeholder="Message Z3ta...")
    clear = gr.Button("Clear")

    # Bind the submit and clear actions
    msg.submit(chat_function, [msg, chatbot], [msg, chatbot])
    clear.click(reset_context, [chatbot], [chatbot, msg])  # Reset both chatbot and textbox

demo.launch()