AEUPH commited on
Commit
2aadecd
·
verified ·
1 Parent(s): a293b60

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -5
app.py CHANGED
@@ -990,7 +990,6 @@ class TemporalPredictionSystem:
990
  # Global System Initialization
991
  # -------------------------------------------------------------------
992
  system = TemporalPredictionSystem()
993
- # Run some initial simulation steps to pre-train
994
  time.sleep(2)
995
  system.run_simulation_steps(20)
996
  print("Future Self Conversation System initialized and pre-trained.")
@@ -1003,7 +1002,8 @@ def chat_fn(user_message, history):
1003
  history = []
1004
  response = system.process_user_message(user_message)
1005
  bot_message = f"{response['text']} ({response['timeOffset']} years in future | Confidence: {int(response['confidence']*100)}%)"
1006
- history.append((user_message, bot_message))
 
1007
  system.run_simulation_steps(5)
1008
  return history
1009
 
@@ -1056,13 +1056,23 @@ with gr.Blocks(title="Future Self Conversation System") as demo:
1056
  with main_interface:
1057
  with gr.Row():
1058
  with gr.Column():
1059
- chatbot = gr.Chatbot(label="Conversation", elem_id="chatbot")
 
1060
  txt = gr.Textbox(placeholder="Type your message here...", label="Your Message")
1061
  send_btn = gr.Button("Send")
1062
  with gr.Column():
1063
  network_image = gr.Image(label="Neural Network Visualization")
1064
- # Auto-update network visualization every 5 seconds.
1065
- interval = gr.Interval(5, fn=update_network_visualization, outputs=network_image)
 
 
 
 
 
 
 
 
 
1066
  send_btn.click(fn=chat_fn, inputs=[txt, chatbot], outputs=chatbot).then(lambda: "", None, txt)
1067
 
1068
  # On page load, run pre-training and then reveal the main interface.
 
990
  # Global System Initialization
991
  # -------------------------------------------------------------------
992
  system = TemporalPredictionSystem()
 
993
  time.sleep(2)
994
  system.run_simulation_steps(20)
995
  print("Future Self Conversation System initialized and pre-trained.")
 
1002
  history = []
1003
  response = system.process_user_message(user_message)
1004
  bot_message = f"{response['text']} ({response['timeOffset']} years in future | Confidence: {int(response['confidence']*100)}%)"
1005
+ history.append({"role": "user", "content": user_message})
1006
+ history.append({"role": "assistant", "content": bot_message})
1007
  system.run_simulation_steps(5)
1008
  return history
1009
 
 
1056
  with main_interface:
1057
  with gr.Row():
1058
  with gr.Column():
1059
+ # Use type="messages" to get openai-style dictionaries.
1060
+ chatbot = gr.Chatbot(label="Conversation", elem_id="chatbot", type="messages")
1061
  txt = gr.Textbox(placeholder="Type your message here...", label="Your Message")
1062
  send_btn = gr.Button("Send")
1063
  with gr.Column():
1064
  network_image = gr.Image(label="Neural Network Visualization")
1065
+ # A hidden refresh button used to update network visualization automatically.
1066
+ refresh_btn = gr.Button("Refresh Network", visible=False, elem_id="refresh_network")
1067
+ refresh_btn.click(fn=update_network_visualization, inputs=[], outputs=network_image)
1068
+ # Inject custom JS to click the hidden refresh button every 5 seconds.
1069
+ gr.HTML("""
1070
+ <script>
1071
+ setInterval(function() {
1072
+ document.getElementById("refresh_network").click();
1073
+ }, 5000);
1074
+ </script>
1075
+ """)
1076
  send_btn.click(fn=chat_fn, inputs=[txt, chatbot], outputs=chatbot).then(lambda: "", None, txt)
1077
 
1078
  # On page load, run pre-training and then reveal the main interface.