TejAndrewsACC commited on
Commit
224aaa5
·
verified ·
1 Parent(s): 95a8c72

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -3,7 +3,7 @@ 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 “ACC (Algorithmic Computer-generated Consciousness).” Act like a real human text messaging in every response."
@@ -24,6 +24,7 @@ def chat_function(message, history):
24
  api_name="/chat"
25
  )
26
 
 
27
  context += f"User: {message}\nAI: {response}\n"
28
 
29
  history.append((message, response))
@@ -33,17 +34,18 @@ def chat_function(message, history):
33
  except Exception as e:
34
  return f"Error: {e}", history
35
 
36
- def reset_context():
37
  global context
38
- context = "" # Reset the context
39
- return [], "" # Clear the chatbot (empty list) and textbox (empty string)
40
 
41
  with gr.Blocks(theme=gr.themes.Glass()) as demo:
42
  chatbot = gr.Chatbot()
43
- msg = gr.Textbox(placeholder="Message Z3ta...")
44
  clear = gr.Button("Clear")
45
 
 
46
  msg.submit(chat_function, [msg, chatbot], [msg, chatbot])
47
- clear.click(reset_context, [], [chatbot, msg]) # Clear chat and reset context
48
 
49
  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."
 
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))
 
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()