shukdevdatta123 commited on
Commit
2166504
·
verified ·
1 Parent(s): 3de8e15

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -20
app.py CHANGED
@@ -528,27 +528,34 @@ def generate_enhanced_analytics(date_range=None):
528
  else:
529
  most_used_model = "N/A"
530
 
 
531
  summary = f"""
532
- ## Analytics Summary
533
-
534
- ### Overview
535
- - **Total API Requests**: {total_requests:,}
536
- - **Total Tokens Used**: {total_tokens:,}
537
- - **Estimated Cost**: ${total_estimated_cost:.2f}
538
- - **Average Response Time**: {avg_response_time:.2f} seconds
539
- - **Most Used Model**: {most_used_model}
540
- - **Date Range**: {df["timestamp"].min().date()} to {df["timestamp"].max().date()}
541
-
542
- ### Model Costs Breakdown
543
- {''.join([f"- **{cost['model']}**: {cost['tokens']:,} tokens / ${cost['cost']:.2f}\n" for cost in model_costs])}
544
-
545
- ### Usage Patterns
546
- - **Busiest Day**: {df.groupby("date")["tokens_used"].sum().idxmax()} ({df[df["date"] == df.groupby("date")["tokens_used"].sum().idxmax()]["tokens_used"].sum():,} tokens)
547
- - **Most Efficient Model**: {df.groupby("model")["response_time_sec"].mean().idxmin()} ({df.groupby("model")["response_time_sec"].mean().min():.2f}s avg response)
548
-
549
- ### Forecast
550
- - **Projected Usage (Next 7 Days)**: {prediction_data["predicted_tokens"].sum():,.0f} tokens (estimated)
551
- """
 
 
 
 
 
 
552
 
553
  return summary, model_usage_img, daily_usage_img, response_time_img, time_pattern_img, intent_analysis_img, model_comparison_img, forecast_chart, export_analytics_csv(df), df.to_dict("records")
554
 
 
528
  else:
529
  most_used_model = "N/A"
530
 
531
+ # Create summary without nested f-strings to avoid the backslash issue
532
  summary = f"""
533
+ ## Analytics Summary
534
+
535
+ ### Overview
536
+ - **Total API Requests**: {total_requests:,}
537
+ - **Total Tokens Used**: {total_tokens:,}
538
+ - **Estimated Cost**: ${total_estimated_cost:.2f}
539
+ - **Average Response Time**: {avg_response_time:.2f} seconds
540
+ - **Most Used Model**: {most_used_model}
541
+ - **Date Range**: {df["timestamp"].min().date()} to {df["timestamp"].max().date()}
542
+
543
+ ### Model Costs Breakdown
544
+ """
545
+
546
+ # Add each model cost as a separate string concatenation
547
+ for cost in model_costs:
548
+ summary += f"- **{cost['model']}**: {cost['tokens']:,} tokens / ${cost['cost']:.2f}\n"
549
+
550
+ # Continue with the rest of the summary
551
+ summary += f"""
552
+ ### Usage Patterns
553
+ - **Busiest Day**: {df.groupby("date")["tokens_used"].sum().idxmax()} ({df[df["date"] == df.groupby("date")["tokens_used"].sum().idxmax()]["tokens_used"].sum():,} tokens)
554
+ - **Most Efficient Model**: {df.groupby("model")["response_time_sec"].mean().idxmin()} ({df.groupby("model")["response_time_sec"].mean().min():.2f}s avg response)
555
+
556
+ ### Forecast
557
+ - **Projected Usage (Next 7 Days)**: {prediction_data["predicted_tokens"].sum():,.0f} tokens (estimated)
558
+ """
559
 
560
  return summary, model_usage_img, daily_usage_img, response_time_img, time_pattern_img, intent_analysis_img, model_comparison_img, forecast_chart, export_analytics_csv(df), df.to_dict("records")
561