-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
76 lines (59 loc) · 1.97 KB
/
utils.py
File metadata and controls
76 lines (59 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import streamlit as st
import logging
import traceback
from datetime import datetime
# Configure logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler('virtual_tryon.log'),
logging.StreamHandler()
]
)
logger = logging.getLogger(__name__)
def log_error(func_name, error, user_context=None):
"""Log errors with context"""
error_msg = f"Error in {func_name}: {str(error)}"
if user_context:
error_msg += f" | Context: {user_context}"
logger.error(error_msg)
logger.error(f"Traceback: {traceback.format_exc()}")
def log_user_action(action, details=None):
"""Log user actions for analytics"""
log_msg = f"User action: {action}"
if details:
log_msg += f" | Details: {details}"
logger.info(log_msg)
def validate_api_setup():
"""Validate API setup and configuration"""
import os
from dotenv import load_dotenv
load_dotenv()
api_key = os.getenv("GEMINI_API_KEY")
if not api_key:
return False, "No API key found in environment variables"
if api_key == "your_gemini_api_key_here":
return False, "Please replace the placeholder API key with your actual Gemini API key"
if len(api_key) < 10:
return False, "API key appears to be invalid (too short)"
return True, "API key validation passed"
def get_system_info():
"""Get system information for debugging"""
import platform
import sys
return {
"platform": platform.platform(),
"python_version": sys.version,
"timestamp": datetime.now().isoformat()
}
def create_error_report(error, context=None):
"""Create detailed error report"""
system_info = get_system_info()
report = {
"error": str(error),
"context": context,
"system_info": system_info,
"traceback": traceback.format_exc()
}
return report