Yousif22's picture
Upload folder using huggingface_hub
49dead4 verified
import pandas as pd
from config import Config
class StatsManager:
@staticmethod
def get_stats():
"""Get usage statistics from Google Sheets"""
try:
if not hasattr(Config, "GOOGLE_SHEET_CSV_URL") or not Config.GOOGLE_SHEET_CSV_URL:
return "<div class='error-stats'>❌ Google Sheet URL is not configured.</div>"
df = pd.read_csv(Config.GOOGLE_SHEET_CSV_URL)
return StatsManager._generate_stats_html(df)
except Exception as e:
return f"<div class='error-stats'>❌ Error loading stats: {str(e)}</div>"
@staticmethod
def _generate_stats_html(df):
"""Generate HTML for statistics display"""
if df.empty:
return "<div class='no-stats'>πŸ“Š No usage data available yet.</div>"
total_predictions = len(df)
sentiment_counts = df['sentiment'].value_counts()
model_counts = df['model_used'].value_counts()
stats_html = f"""
<div class="stats-container">
<h3 class="stats-title">πŸ“Š Usage Statistics</h3>
<p class="stats-total"><strong>Total Predictions:</strong> {total_predictions}</p>
<div class="stats-section">
<p><strong>Sentiment Distribution:</strong></p>
<ul class="stats-list">
"""
for sentiment, count in sentiment_counts.items():
percentage = (count / total_predictions) * 100
stats_html += f"<li class='stats-item stats-{str(sentiment).lower()}'>πŸ“Š {str(sentiment).title()}: {count} ({percentage:.1f}%)</li>"
stats_html += """
</ul>
</div>
<div class="stats-section">
<p><strong>Model Usage:</strong></p>
<ul class="stats-list">
"""
for model, count in model_counts.items():
percentage = (count / total_predictions) * 100
stats_html += f"<li class='stats-item'>πŸ€– {model}: {count} ({percentage:.1f}%)</li>"
stats_html += "</ul></div></div>"
return stats_html