import sqlite3 # Allowing database access from multiple threads conn = sqlite3.connect("call_logs.db", check_same_thread=False) c = conn.cursor() # Create Table for call logs c.execute('''CREATE TABLE IF NOT EXISTS call_logs (id INTEGER PRIMARY KEY, transcript TEXT, intent TEXT, priority TEXT, sentiment TEXT, ai_response TEXT)''') conn.commit() def log_call(transcript, intent, priority, sentiment, ai_response): """Save the call analysis results to database.""" c.execute("INSERT INTO call_logs (transcript, intent, priority, sentiment, ai_response) VALUES (?, ?, ?, ?, ?)", (transcript, intent, priority, sentiment, ai_response)) conn.commit() def fetch_recent_calls(limit=5): """Fetch latest logged calls from database.""" c.execute("SELECT * FROM call_logs ORDER BY id DESC LIMIT ?", (limit,)) return c.fetchall()