TejAndrewsACC commited on
Commit
3d7c2f8
·
verified ·
1 Parent(s): 353ef3d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -8
app.py CHANGED
@@ -9,9 +9,11 @@ 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"
@@ -19,6 +21,7 @@ def chat_function(message, history):
19
  )
20
 
21
  try:
 
22
  response = client.predict(
23
  message=modified_input,
24
  api_name="/chat"
@@ -27,25 +30,31 @@ def chat_function(message, history):
27
  # Update the global context
28
  context += f"User: {message}\nAI: {response}\n"
29
 
 
30
  history.append((message, response))
31
 
32
- return response, history
33
 
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()
 
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
+ # Function to handle user input and generate AI response
13
  def chat_function(message, history):
14
  global context
15
 
16
+ # Update the modified input with system instructions and context
17
  modified_input = (
18
  f"System Instructions: {system_instructions}\n"
19
  f"Previous Context: {context}\n"
 
21
  )
22
 
23
  try:
24
+ # Call the client to get the response
25
  response = client.predict(
26
  message=modified_input,
27
  api_name="/chat"
 
30
  # Update the global context
31
  context += f"User: {message}\nAI: {response}\n"
32
 
33
+ # Append to the chat history
34
  history.append((message, response))
35
 
36
+ return "", history # Clear the input box and return updated history
37
 
38
  except Exception as e:
39
  return f"Error: {e}", history
40
 
41
+ # Function to reset the context and history
42
+ def reset_context():
43
  global context
44
  context = "" # Reset the global context
45
+ return [], "" # Clear the chatbot and input textbox
46
 
47
+ # Create the Gradio interface
48
  with gr.Blocks(theme=gr.themes.Glass()) as demo:
49
+ chatbot = gr.Chatbot() # Chat history display
50
+ msg = gr.Textbox(placeholder="Message Z3ta...") # Input box
51
+ clear = gr.Button("Clear") # Clear button
52
 
53
+ # Bind the submit action to the chat function
54
  msg.submit(chat_function, [msg, chatbot], [msg, chatbot])
 
55
 
56
+ # Bind the clear action to reset context and clear the UI
57
+ clear.click(reset_context, [], [chatbot, msg]) # Resets chatbot and input box
58
+
59
+ # Launch the Gradio interface
60
  demo.launch()