Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
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 |
|