Spaces:
Sleeping
Sleeping
Download app.py from rahulmolasi/SmartDayAI: direct link, hf CLI and curl.
- Browser
- Download file 1.98 kB
-
https://huggingface.co/spaces/rahulmolasi/SmartDayAI/resolve/main/app.py
- Command line
-
hf download hf://spaces/rahulmolasi/SmartDayAI/app.py
-
curl -L -o app.py https://huggingface.co/spaces/rahulmolasi/SmartDayAI/resolve/main/app.py
1.98 kB
| import streamlit as st | |
| import sqlite3 | |
| from datetime import datetime, timedelta | |
| import os | |
| import json | |
| import requests | |
| # ----------------------------- | |
| # CONFIG | |
| # ----------------------------- | |
| st.set_page_config( | |
| page_title="SmartDay.AI", | |
| page_icon="🌸", | |
| layout="wide", | |
| initial_sidebar_state="expanded" | |
| ) | |
| # Theme Colors | |
| PRIMARY_COLOR = "#FF6F61" # Coral | |
| BG_COLOR = "#FFFFFF" # White | |
| # Database setup | |
| DB_FILE = "smartday_ai.db" | |
| def init_db(): | |
| conn = sqlite3.connect(DB_FILE) | |
| c = conn.cursor() | |
| c.execute('''CREATE TABLE IF NOT EXISTS users | |
| (username TEXT PRIMARY KEY, password TEXT)''') | |
| c.execute('''CREATE TABLE IF NOT EXISTS journal | |
| (username TEXT, date TEXT, entry TEXT)''') | |
| c.execute('''CREATE TABLE IF NOT EXISTS planner | |
| (username TEXT, date TEXT, task TEXT, status TEXT)''') | |
| conn.commit() | |
| conn.close() | |
| init_db() | |
| # ----------------------------- | |
| # AUTHENTICATION | |
| # ----------------------------- | |
| def register_user(username, password): | |
| conn = sqlite3.connect(DB_FILE) | |
| c = conn.cursor() | |
| try: | |
| c.execute("INSERT INTO users VALUES (?,?)", (username, password)) | |
| conn.commit() | |
| return True | |
| except: | |
| return False | |
| finally: | |
| conn.close() | |
| def login_user(username, password): | |
| conn = sqlite3.connect(DB_FILE) | |
| c = conn.cursor() | |
| c.execute("SELECT * FROM users WHERE username=? AND password=?", (username, password)) | |
| result = c.fetchone() | |
| conn.close() | |
| return result is not None | |
| # ----------------------------- | |
| # GROQ AI INTEGRATION | |
| # ----------------------------- | |
| def groq_chat(prompt): | |
| """Call Groq API - key saved in Hugging Face Secrets""" | |
| api_key = os.environ.get("GROQ_API_KEY") | |
| if not api_key: | |
| return "⚠️ No API key found. Please set GROQ_API_KEY in Secrets." | |
| url = "https://api.groq.com/openai/v1/chat/completions" | |
| headers = {"Authorization": f"Bearer {api_key}",_ | |