Spaces:
Runtime error
Runtime error
Download test_hf_session.py from kalyan9/HealthGuard-AI: direct link, hf CLI and curl.
- Browser
- Download file 1.67 kB
-
https://huggingface.co/spaces/kalyan9/HealthGuard-AI/resolve/main/test_hf_session.py
- Command line
-
hf download hf://spaces/kalyan9/HealthGuard-AI/test_hf_session.py
-
curl -L -o test_hf_session.py https://huggingface.co/spaces/kalyan9/HealthGuard-AI/resolve/main/test_hf_session.py
1.67 kB
| """ | |
| Test script for session functionality on Hugging Face Spaces. | |
| """ | |
| from flask import Flask, session, request, jsonify | |
| import os | |
| app = Flask(__name__) | |
| app.secret_key = os.getenv('SECRET_KEY', 'test-secret-key') | |
| # Session configuration for Hugging Face Spaces | |
| app.config.update( | |
| SESSION_TYPE='filesystem', | |
| SESSION_FILE_DIR='/tmp/flask_session', | |
| SESSION_FILE_THRESHOLD=100, | |
| SESSION_FILE_MODE=0o600, | |
| SESSION_PERMANENT=True | |
| ) | |
| # Initialize session | |
| try: | |
| from flask_session import Session | |
| Session(app) | |
| # Create session directory | |
| os.makedirs('/tmp/flask_session', exist_ok=True) | |
| print("Filesystem session initialized successfully") | |
| except Exception as e: | |
| print(f"Could not initialize filesystem session: {e}") | |
| def index(): | |
| return ''' | |
| <h1>Session Test for Hugging Face Spaces</h1> | |
| <p><a href="/set">Set Session</a> | <a href="/get">Get Session</a> | <a href="/clear">Clear Session</a></p> | |
| ''' | |
| def set_session(): | |
| session['test'] = 'value' | |
| session['counter'] = session.get('counter', 0) + 1 | |
| return jsonify({ | |
| 'status': 'Session set', | |
| 'session': dict(session), | |
| 'counter': session.get('counter') | |
| }) | |
| def get_session(): | |
| return jsonify({ | |
| 'session': dict(session), | |
| 'counter': session.get('counter', 0), | |
| 'has_session': 'test' in session | |
| }) | |
| def clear_session(): | |
| session.clear() | |
| return jsonify({ | |
| 'status': 'Session cleared' | |
| }) | |
| if __name__ == '__main__': | |
| app.run(host='0.0.0.0', port=7860) |