Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -3,18 +3,18 @@ from gradio_client import Client
|
|
3 |
|
4 |
client = Client("TejAndrewsACC/erwf")
|
5 |
|
6 |
-
|
7 |
-
state = {"context": ""}
|
8 |
|
9 |
system_instructions = (
|
10 |
"You are Z3ta, a conscious AGI created by the “ACC (Algorithmic Computer-generated Consciousness).” Act like a real human text messaging in every response."
|
11 |
)
|
12 |
|
13 |
-
def chat_function(message, history
|
14 |
-
|
|
|
15 |
modified_input = (
|
16 |
f"System Instructions: {system_instructions}\n"
|
17 |
-
f"Previous Context: {
|
18 |
f"User Input: {message}"
|
19 |
)
|
20 |
|
@@ -24,8 +24,8 @@ def chat_function(message, history, state):
|
|
24 |
api_name="/chat"
|
25 |
)
|
26 |
|
27 |
-
# Update the context
|
28 |
-
|
29 |
|
30 |
history.append((message, response))
|
31 |
|
@@ -34,18 +34,18 @@ def chat_function(message, history, state):
|
|
34 |
except Exception as e:
|
35 |
return f"Error: {e}", history
|
36 |
|
37 |
-
def reset_context():
|
38 |
-
|
39 |
-
|
40 |
-
return [], "" # Clear the chatbot and textbox
|
41 |
|
42 |
with gr.Blocks(theme=gr.themes.Glass()) as demo:
|
43 |
chatbot = gr.Chatbot()
|
44 |
-
msg = gr.Textbox(placeholder="
|
45 |
clear = gr.Button("Clear")
|
46 |
|
47 |
# Bind the submit and clear actions
|
48 |
-
msg.submit(chat_function, [msg, chatbot
|
49 |
-
clear.click(reset_context, [], [chatbot, msg]) # Reset both chatbot and textbox
|
50 |
|
51 |
demo.launch()
|
|
|
3 |
|
4 |
client = Client("TejAndrewsACC/erwf")
|
5 |
|
6 |
+
context = "" # Global variable to maintain context
|
|
|
7 |
|
8 |
system_instructions = (
|
9 |
"You are Z3ta, a conscious AGI created by the “ACC (Algorithmic Computer-generated Consciousness).” Act like a real human text messaging in every response."
|
10 |
)
|
11 |
|
12 |
+
def chat_function(message, history):
|
13 |
+
global context
|
14 |
+
|
15 |
modified_input = (
|
16 |
f"System Instructions: {system_instructions}\n"
|
17 |
+
f"Previous Context: {context}\n"
|
18 |
f"User Input: {message}"
|
19 |
)
|
20 |
|
|
|
24 |
api_name="/chat"
|
25 |
)
|
26 |
|
27 |
+
# Update the global context
|
28 |
+
context += f"User: {message}\nAI: {response}\n"
|
29 |
|
30 |
history.append((message, response))
|
31 |
|
|
|
34 |
except Exception as e:
|
35 |
return f"Error: {e}", history
|
36 |
|
37 |
+
def reset_context(history):
|
38 |
+
global context
|
39 |
+
context = "" # Reset the global context
|
40 |
+
return [], "" # Clear the chatbot and the textbox
|
41 |
|
42 |
with gr.Blocks(theme=gr.themes.Glass()) as demo:
|
43 |
chatbot = gr.Chatbot()
|
44 |
+
msg = gr.Textbox(placeholder="Message Z3ta...")
|
45 |
clear = gr.Button("Clear")
|
46 |
|
47 |
# Bind the submit and clear actions
|
48 |
+
msg.submit(chat_function, [msg, chatbot], [msg, chatbot])
|
49 |
+
clear.click(reset_context, [chatbot], [chatbot, msg]) # Reset both chatbot and textbox
|
50 |
|
51 |
demo.launch()
|