Frankie-walsh4 commited on
Commit
2615e7f
·
1 Parent(s): 2405040

removing admin features as not needed anymore

Browse files
Files changed (1) hide show
  1. app.py +1 -55
app.py CHANGED
@@ -290,31 +290,6 @@ If comparing two services or features:
290
  error_msg = f"I apologize, but I encountered an error while generating a response. Error details: {str(e)}"
291
  yield error_msg
292
 
293
- # Function to get admin stats about rate limiting
294
- def get_rate_limit_stats():
295
- stats = {
296
- "max_requests_per_day": MAX_REQUESTS_PER_DAY,
297
- "active_ips": len(ip_request_counters),
298
- "ip_usage": dict(ip_request_counters),
299
- "last_reset_dates": {ip: date.strftime("%Y-%m-%d") for ip, date in ip_last_reset.items()}
300
- }
301
- return stats
302
-
303
- # Admin interface to adjust rate limit settings
304
- def update_rate_limit(new_limit):
305
- global MAX_REQUESTS_PER_DAY
306
-
307
- if new_limit < 1:
308
- return {"success": False, "message": "Limit must be at least 1"}
309
-
310
- old_limit = MAX_REQUESTS_PER_DAY
311
- MAX_REQUESTS_PER_DAY = new_limit
312
-
313
- return {
314
- "success": True,
315
- "message": f"Rate limit updated from {old_limit} to {new_limit} requests per IP per day"
316
- }
317
-
318
  # Custom CSS for Plant Wisdom.AI styling
319
  custom_css = """
320
  .gradio-container {
@@ -537,39 +512,10 @@ IMPORTANT: If a question has been asked before in the conversation, acknowledge
537
  ],
538
  )
539
 
540
- # Create Gradio Blocks app with both interfaces
541
  with gr.Blocks(theme=gr.themes.Base()) as demo:
542
  # Main chat interface
543
  chat_interface.render()
544
-
545
- # Hidden admin panel (accessible at /admin)
546
- with gr.Tab("Admin", visible=False):
547
- gr.Markdown("## Rate Limiting Settings")
548
-
549
- with gr.Row():
550
- current_limit = gr.Number(label="Current Request Limit Per IP Per Day", value=MAX_REQUESTS_PER_DAY, interactive=False)
551
- new_limit = gr.Number(label="New Request Limit", value=MAX_REQUESTS_PER_DAY, minimum=1, step=1)
552
- update_btn = gr.Button("Update Limit")
553
-
554
- result_text = gr.Textbox(label="Result", interactive=False)
555
-
556
- # Stats display
557
- with gr.Accordion("Usage Statistics", open=False):
558
- refresh_btn = gr.Button("Refresh Stats")
559
- stats_json = gr.JSON(label="Current Usage Stats")
560
-
561
- # Connect buttons to functions
562
- update_btn.click(
563
- fn=update_rate_limit,
564
- inputs=[new_limit],
565
- outputs=[result_text, current_limit]
566
- )
567
-
568
- refresh_btn.click(
569
- fn=get_rate_limit_stats,
570
- inputs=[],
571
- outputs=[stats_json]
572
- )
573
 
574
  if __name__ == "__main__":
575
  demo.launch(server_name="0.0.0.0")
 
290
  error_msg = f"I apologize, but I encountered an error while generating a response. Error details: {str(e)}"
291
  yield error_msg
292
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
293
  # Custom CSS for Plant Wisdom.AI styling
294
  custom_css = """
295
  .gradio-container {
 
512
  ],
513
  )
514
 
515
+ # Create Gradio Blocks app with chat interface
516
  with gr.Blocks(theme=gr.themes.Base()) as demo:
517
  # Main chat interface
518
  chat_interface.render()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
519
 
520
  if __name__ == "__main__":
521
  demo.launch(server_name="0.0.0.0")