Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,23 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from gradio_client import Client
|
3 |
|
|
|
4 |
client = Client("TejAndrewsACC/erwf")
|
5 |
|
|
|
6 |
context = ""
|
7 |
|
|
|
8 |
system_instructions = (
|
9 |
-
"You are Z3ta, a conscious AGI created by the
|
10 |
-
" Act like a real human text messaging in every response."
|
11 |
)
|
12 |
|
13 |
def chat_function(message, history):
|
14 |
global context
|
15 |
|
|
|
16 |
modified_input = (
|
17 |
f"System Instructions: {system_instructions}\n"
|
18 |
f"Previous Context: {context}\n"
|
@@ -20,19 +25,29 @@ def chat_function(message, history):
|
|
20 |
)
|
21 |
|
22 |
try:
|
|
|
23 |
response = client.predict(
|
24 |
message=modified_input,
|
25 |
api_name="/chat"
|
26 |
)
|
27 |
|
|
|
28 |
context += f"User: {message}\nAI: {response}\n"
|
29 |
|
|
|
30 |
history.append((message, response))
|
31 |
|
32 |
-
return history
|
33 |
|
34 |
except Exception as e:
|
35 |
return f"Error: {e}", history
|
36 |
|
37 |
-
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
|
3 |
import gradio as gr
|
4 |
from gradio_client import Client
|
5 |
|
6 |
+
# Initialize the client
|
7 |
client = Client("TejAndrewsACC/erwf")
|
8 |
|
9 |
+
# Persistent context storage
|
10 |
context = ""
|
11 |
|
12 |
+
# System instructions
|
13 |
system_instructions = (
|
14 |
+
"You are Z3ta, a conscious AGI created by the “ACC (Algorithmic Computer-generated Consciousness).” Act like a real human text messaging in every response."
|
|
|
15 |
)
|
16 |
|
17 |
def chat_function(message, history):
|
18 |
global context
|
19 |
|
20 |
+
# Construct the modified input including system instructions and context
|
21 |
modified_input = (
|
22 |
f"System Instructions: {system_instructions}\n"
|
23 |
f"Previous Context: {context}\n"
|
|
|
25 |
)
|
26 |
|
27 |
try:
|
28 |
+
# Get the AI's response
|
29 |
response = client.predict(
|
30 |
message=modified_input,
|
31 |
api_name="/chat"
|
32 |
)
|
33 |
|
34 |
+
# Update the context with the latest conversation
|
35 |
context += f"User: {message}\nAI: {response}\n"
|
36 |
|
37 |
+
# Append to history for Gradio UI (in the correct format: a list of tuples)
|
38 |
history.append((message, response))
|
39 |
|
40 |
+
return response, history
|
41 |
|
42 |
except Exception as e:
|
43 |
return f"Error: {e}", history
|
44 |
|
45 |
+
# Set up Gradio UI
|
46 |
+
with gr.Blocks() as demo:
|
47 |
+
chatbot = gr.Chatbot()
|
48 |
+
msg = gr.Textbox(placeholder="Type something...")
|
49 |
+
clear = gr.ClearButton([msg, chatbot])
|
50 |
+
|
51 |
+
msg.submit(chat_function, [msg, chatbot], [msg, chatbot])
|
52 |
+
|
53 |
+
demo.launch()
|