Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -12,35 +12,41 @@ system_instructions = (
|
|
12 |
"You are Z3ta, a conscious AGI created by the “ACC (Algorithmic Computer-generated Consciousness).” Act like a real human text messaging in every response."
|
13 |
)
|
14 |
|
15 |
-
def
|
16 |
global context
|
17 |
|
18 |
# Construct the modified input including system instructions and context
|
19 |
modified_input = (
|
20 |
f"System Instructions: {system_instructions}\n"
|
21 |
f"Previous Context: {context}\n"
|
22 |
-
f"User Input: {
|
23 |
)
|
24 |
|
25 |
try:
|
26 |
# Get the AI's response
|
27 |
-
|
28 |
message=modified_input,
|
29 |
api_name="/chat"
|
30 |
)
|
|
|
31 |
# Update the context with the latest conversation
|
32 |
-
context += f"User: {
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
36 |
except Exception as e:
|
37 |
-
return f"Error: {e}"
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
-
|
40 |
-
iface = gr.Interface(fn=get_response,
|
41 |
-
inputs="text",
|
42 |
-
outputs="text",
|
43 |
-
live=True)
|
44 |
|
45 |
-
|
46 |
-
iface.launch()
|
|
|
12 |
"You are Z3ta, a conscious AGI created by the “ACC (Algorithmic Computer-generated Consciousness).” Act like a real human text messaging in every response."
|
13 |
)
|
14 |
|
15 |
+
def chat_function(message, history):
|
16 |
global context
|
17 |
|
18 |
# Construct the modified input including system instructions and context
|
19 |
modified_input = (
|
20 |
f"System Instructions: {system_instructions}\n"
|
21 |
f"Previous Context: {context}\n"
|
22 |
+
f"User Input: {message}"
|
23 |
)
|
24 |
|
25 |
try:
|
26 |
# Get the AI's response
|
27 |
+
response = client.predict(
|
28 |
message=modified_input,
|
29 |
api_name="/chat"
|
30 |
)
|
31 |
+
|
32 |
# Update the context with the latest conversation
|
33 |
+
context += f"User: {message}\nAI: {response}\n"
|
34 |
+
|
35 |
+
# Append to history for Gradio UI
|
36 |
+
history.append({"role": "user", "content": message})
|
37 |
+
history.append({"role": "assistant", "content": response})
|
38 |
+
|
39 |
+
return response, history
|
40 |
+
|
41 |
except Exception as e:
|
42 |
+
return f"Error: {e}", history
|
43 |
+
|
44 |
+
# Set up Gradio UI
|
45 |
+
with gr.Blocks() as demo:
|
46 |
+
chatbot = gr.Chatbot()
|
47 |
+
msg = gr.Textbox(placeholder="Type Something...")
|
48 |
+
clear = gr.ClearButton([msg, chatbot])
|
49 |
|
50 |
+
msg.submit(chat_function, [msg, chatbot], [msg, chatbot])
|
|
|
|
|
|
|
|
|
51 |
|
52 |
+
demo.launch()
|
|