Spaces:
Running
Running
Commit History
-
import gradio as gr
Verified signatureimport os import sqlite3 import json from typing import List, Dict, Any from huggingface_hub import InferenceClient import requests from datetime import datetime import hashlib # Persistent memory setup using HF Spaces /data mount MEMORY_DB = "/data/memory.db" def init_memory(): """Initialize persistent SQLite memory database""" os.makedirs(os.path.dirname(MEMORY_DB), exist_ok=True) conn = sqlite3.connect(MEMORY_DB) conn.execute(""" CREATE TABLE IF NOT EXISTS conversations ( id INTEGER PRIMARY KEY AUTOINCREMENT, session_id TEXT, role TEXT, content TEXT, timestamp DATETIME DEFAULT CURRENT_TIMESTAMP, embedding_hash TEXT ) """) conn.commit() conn.close() def save_memory(session_id: str, role: str, content: str): """Save conversation to persistent memory""" content_hash = hashlib.md5(content.encode()).hexdigest() conn = sqlite3.connect(MEMORY_DB) conn.execu…afe04f9