Lasdw commited on
Commit
0ff9cac
·
1 Parent(s): 388798b

added session id for rate limiting

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -42,7 +42,7 @@ def format_history_for_agent(history: list) -> str:
42
  formatted_history += f"{role.upper()}: {content}\n"
43
  return formatted_history
44
 
45
- def chat_with_agent(question: str, file_uploads, history: list, request: gr.Request) -> tuple:
46
  """
47
  Handle chat interaction with TurboNerd agent, now with file upload support.
48
  """
@@ -50,8 +50,8 @@ def chat_with_agent(question: str, file_uploads, history: list, request: gr.Requ
50
  return history, "", "Remaining queries this hour: 5/5"
51
 
52
  try:
53
- # Get session ID from Gradio request
54
- session_id = request.session_hash if request else str(id(history))
55
  print(f"Using session ID: {session_id}")
56
 
57
  # Initialize or get session history
@@ -371,13 +371,13 @@ with gr.Blocks(title="TurboNerd Agent🤓") as demo:
371
  # Chat interface event handlers
372
  submit_btn.click(
373
  fn=chat_with_agent,
374
- inputs=[question_input, file_upload, chatbot, gr.Request()],
375
  outputs=[chatbot, question_input, remaining_queries]
376
  )
377
 
378
  question_input.submit(
379
  fn=chat_with_agent,
380
- inputs=[question_input, file_upload, chatbot, gr.Request()],
381
  outputs=[chatbot, question_input, remaining_queries]
382
  )
383
 
@@ -435,4 +435,4 @@ if __name__ == "__main__":
435
  print("-"*(60 + len(" App Starting ")) + "\n")
436
 
437
  print("Launching Gradio Interface for TurboNerd Agent...")
438
- demo.launch(debug=True, share=False, show_api=False, favicon_path="static/favicon.ico")
 
42
  formatted_history += f"{role.upper()}: {content}\n"
43
  return formatted_history
44
 
45
+ def chat_with_agent(question: str, file_uploads, history: list) -> tuple:
46
  """
47
  Handle chat interaction with TurboNerd agent, now with file upload support.
48
  """
 
50
  return history, "", "Remaining queries this hour: 5/5"
51
 
52
  try:
53
+ # Use the history object's ID as a session identifier
54
+ session_id = str(id(history))
55
  print(f"Using session ID: {session_id}")
56
 
57
  # Initialize or get session history
 
371
  # Chat interface event handlers
372
  submit_btn.click(
373
  fn=chat_with_agent,
374
+ inputs=[question_input, file_upload, chatbot],
375
  outputs=[chatbot, question_input, remaining_queries]
376
  )
377
 
378
  question_input.submit(
379
  fn=chat_with_agent,
380
+ inputs=[question_input, file_upload, chatbot],
381
  outputs=[chatbot, question_input, remaining_queries]
382
  )
383
 
 
435
  print("-"*(60 + len(" App Starting ")) + "\n")
436
 
437
  print("Launching Gradio Interface for TurboNerd Agent...")
438
+ demo.launch(debug=True, share=False, show_api=False, favicon_path="static/favicon.ico", enable_monitoring=True)