TejAndrewsACC commited on
Commit
05cf037
·
verified ·
1 Parent(s): ad181ed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -15
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 get_response(user_input):
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: {user_input}"
23
  )
24
 
25
  try:
26
  # Get the AI's response
27
- result = client.predict(
28
  message=modified_input,
29
  api_name="/chat"
30
  )
 
31
  # Update the context with the latest conversation
32
- context += f"User: {user_input}\nAI: {result}\n"
33
-
34
- return result
35
-
 
 
 
 
36
  except Exception as e:
37
- return f"Error: {e}"
 
 
 
 
 
 
38
 
39
- # Gradio interface
40
- iface = gr.Interface(fn=get_response,
41
- inputs="text",
42
- outputs="text",
43
- live=True)
44
 
45
- # Launch the interface
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()