Compass79 commited on
Commit
5849687
Β·
1 Parent(s): bbac39e

Add MCP integration, OAuth support, and comprehensive API endpoints

Browse files
Files changed (8) hide show
  1. .env.example +18 -0
  2. .gitignore +53 -0
  3. README.md +129 -6
  4. SETUP_GUIDE.md +290 -0
  5. app.py +275 -5
  6. mcp-config.json +85 -0
  7. requirements.txt +8 -0
  8. setup.sh +76 -0
.env.example ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Hugging Face Configuration
2
+ HF_TOKEN=your_hf_token_here
3
+ SPACE_AUTHOR=Recovery-Compass-79
4
+ SPACE_NAME=README
5
+
6
+ # OAuth Configuration
7
+ OAUTH_CLIENT_ID=Recovery-Compass-79
8
+ OAUTH_CLIENT_SECRET=your_client_secret_here
9
+ OAUTH_REDIRECT_URI=https://huggingface.co/spaces/Recovery-Compass-79/README/callback
10
+
11
+ # MCP Configuration
12
+ MCP_SERVER_URL=https://huggingface.co/mcp
13
+ MCP_ENABLED=true
14
+
15
+ # Application Configuration
16
+ APP_NAME=Recovery Compass MCP Hub
17
+ APP_VERSION=1.0.0
18
+ DEBUG=false
.gitignore ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ build/
8
+ develop-eggs/
9
+ dist/
10
+ downloads/
11
+ eggs/
12
+ .eggs/
13
+ lib/
14
+ lib64/
15
+ parts/
16
+ sdist/
17
+ var/
18
+ wheels/
19
+ *.egg-info/
20
+ .installed.cfg
21
+ *.egg
22
+
23
+ # Environment
24
+ .env
25
+ .venv
26
+ env/
27
+ venv/
28
+ ENV/
29
+ env.bak/
30
+ venv.bak/
31
+
32
+ # IDE
33
+ .vscode/
34
+ .idea/
35
+ *.swp
36
+ *.swo
37
+ *~
38
+
39
+ # OS
40
+ .DS_Store
41
+ Thumbs.db
42
+
43
+ # Logs
44
+ *.log
45
+ logs/
46
+
47
+ # Testing
48
+ .pytest_cache/
49
+ .coverage
50
+ htmlcov/
51
+
52
+ # Hugging Face
53
+ hf_token.txt
README.md CHANGED
@@ -1,10 +1,133 @@
1
  ---
2
- title: README
3
- emoji: 🐠
4
- colorFrom: green
5
- colorTo: purple
6
  sdk: docker
7
- pinned: false
 
 
 
 
 
 
 
8
  ---
9
 
10
- Edit this `README.md` markdown file to author your organization card.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Recovery Compass MCP Hub
3
+ emoji: 🧭
4
+ colorFrom: purple
5
+ colorTo: blue
6
  sdk: docker
7
+ pinned: true
8
+ license: mit
9
+ tags:
10
+ - mcp
11
+ - recovery
12
+ - mental-health
13
+ - support
14
+ - ai-assistant
15
  ---
16
 
17
+ # 🧭 Recovery Compass MCP Hub
18
+
19
+ **AI-Powered Recovery Support with Hugging Face MCP Integration**
20
+
21
+ ## 🌟 Features
22
+
23
+ - **πŸ”Œ MCP Server Integration** - Full Model Context Protocol support for AI assistants
24
+ - **πŸ€– AI Chat Support** - 24/7 recovery guidance and support
25
+ - **πŸ” Semantic Search** - Find recovery resources, research papers, and support tools
26
+ - **πŸ“Š Progress Tracking** - Monitor your recovery journey with AI insights
27
+ - **🌐 OAuth Login** - Secure authentication with Hugging Face
28
+ - **πŸš€ REST API** - Complete API for integration with other services
29
+
30
+ ## πŸš€ Quick Start
31
+
32
+ ### Access the Space
33
+ Visit [https://huggingface.co/spaces/Recovery-Compass-79/README](https://huggingface.co/spaces/Recovery-Compass-79/README)
34
+
35
+ ### API Endpoints
36
+
37
+ - **`GET /`** - Welcome page with OAuth login
38
+ - **`GET /health`** - Health check endpoint
39
+ - **`GET /mcp`** - MCP server capabilities
40
+ - **`GET /api/search?query={text}`** - Search HF resources
41
+ - **`GET /api/models?task={task}`** - List ML models
42
+ - **`GET /api/datasets?task={task}`** - List datasets
43
+ - **`GET /api/spaces`** - List recovery-related Spaces
44
+ - **`POST /api/chat`** - AI chat endpoint
45
+
46
+ ### Example API Call
47
+
48
+ ```bash
49
+ # Search for recovery-related resources
50
+ curl "https://Recovery-Compass-79-README.hf.space/api/search?query=mental%20health"
51
+
52
+ # Get health check
53
+ curl "https://Recovery-Compass-79-README.hf.space/health"
54
+
55
+ # Chat with AI
56
+ curl -X POST "https://Recovery-Compass-79-README.hf.space/api/chat" \
57
+ -H "Content-Type: application/json" \
58
+ -d '{"message": "I need support today"}'
59
+ ```
60
+
61
+ ## πŸ”§ MCP Integration
62
+
63
+ This Space serves as an MCP server providing:
64
+
65
+ 1. **Semantic Search Tools** - Find AI apps, papers, and documentation
66
+ 2. **Model Access** - Discover and use ML models
67
+ 3. **Dataset Tools** - Access recovery and mental health datasets
68
+ 4. **Space Integration** - Connect to other support Spaces
69
+ 5. **Progress Tracking** - Monitor recovery metrics
70
+
71
+ ### Connect with MCP Clients
72
+
73
+ Add this to your MCP client configuration:
74
+
75
+ ```json
76
+ {
77
+ "mcpServers": {
78
+ "recovery-compass": {
79
+ "url": "https://huggingface.co/spaces/Recovery-Compass-79/README",
80
+ "oauth": true
81
+ }
82
+ }
83
+ }
84
+ ```
85
+
86
+ ## πŸ” OAuth Setup
87
+
88
+ 1. Visit the Space homepage
89
+ 2. Click "Login with Hugging Face"
90
+ 3. Authorize the application
91
+ 4. Start using MCP tools
92
+
93
+ ## πŸ› οΈ Local Development
94
+
95
+ ```bash
96
+ # Clone the repository
97
+ git clone https://huggingface.co/spaces/Recovery-Compass-79/README
98
+
99
+ # Install dependencies
100
+ pip install -r requirements.txt
101
+
102
+ # Run locally
103
+ uvicorn app:app --host 0.0.0.0 --port 7860
104
+ ```
105
+
106
+ ## πŸ“š Documentation
107
+
108
+ - [Hugging Face MCP Server](https://huggingface.co/mcp)
109
+ - [FastAPI Documentation](https://fastapi.tiangolo.com/)
110
+ - [Model Context Protocol](https://modelcontextprotocol.io/)
111
+
112
+ ## 🀝 Contributing
113
+
114
+ Contributions are welcome! This is an open-source recovery support tool.
115
+
116
+ ## πŸ“„ License
117
+
118
+ MIT License - feel free to use and modify for your own recovery support projects.
119
+
120
+ ## ⚠️ Disclaimer
121
+
122
+ This is an AI-powered support tool and should not replace professional medical or mental health care. If you're in crisis, please contact:
123
+ - National Suicide Prevention Lifeline: 988
124
+ - Crisis Text Line: Text HOME to 741741
125
+ - Emergency Services: 911
126
+
127
+ ## 🌈 About Recovery Compass
128
+
129
+ Recovery Compass is an AI-powered platform designed to support individuals on their recovery journey. By integrating with Hugging Face's MCP ecosystem, we provide access to cutting-edge AI models, datasets, and tools to enhance recovery support.
130
+
131
+ ---
132
+
133
+ Built with ❀️ using Hugging Face, FastAPI, and Model Context Protocol
SETUP_GUIDE.md ADDED
@@ -0,0 +1,290 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Recovery Compass MCP Hub - Complete Setup Guide
2
+
3
+ ## 🎯 Overview
4
+
5
+ This guide will help you set up the Recovery Compass MCP Hub with full Hugging Face integration, OAuth login, and MCP server capabilities.
6
+
7
+ ## πŸ“‹ Prerequisites
8
+
9
+ - Python 3.9+
10
+ - Git
11
+ - Hugging Face account
12
+ - Hugging Face access token (with read/write permissions)
13
+
14
+ ## πŸš€ Quick Setup
15
+
16
+ ### 1. Clone the Repository
17
+
18
+ ```bash
19
+ git clone https://huggingface.co/spaces/Recovery-Compass-79/README recovery-compass-space
20
+ cd recovery-compass-space
21
+ ```
22
+
23
+ ### 2. Run Setup Script
24
+
25
+ ```bash
26
+ chmod +x setup.sh
27
+ ./setup.sh
28
+ ```
29
+
30
+ ### 3. Configure Environment
31
+
32
+ Edit `.env` file with your credentials:
33
+
34
+ ```bash
35
+ HF_TOKEN=your_token_here
36
+ OAUTH_CLIENT_SECRET=your_secret_here
37
+ ```
38
+
39
+ ### 4. Test Locally
40
+
41
+ ```bash
42
+ uvicorn app:app --host 0.0.0.0 --port 7860
43
+ ```
44
+
45
+ Visit: http://localhost:7860
46
+
47
+ ### 5. Deploy to Hugging Face
48
+
49
+ ```bash
50
+ git add .
51
+ git commit -m "Configure deployment"
52
+ git push
53
+ ```
54
+
55
+ ## πŸ”Œ MCP Integration Setup
56
+
57
+ ### Connect to Hugging Face MCP Server
58
+
59
+ 1. **OAuth Authentication**
60
+ - Visit: https://huggingface.co/mcp?login
61
+ - Authorize the application
62
+ - Token will be stored automatically
63
+
64
+ 2. **Configure MCP Client**
65
+
66
+ Add to your MCP client configuration (e.g., Claude Desktop):
67
+
68
+ ```json
69
+ {
70
+ "mcpServers": {
71
+ "huggingface": {
72
+ "url": "https://huggingface.co/mcp",
73
+ "oauth": true
74
+ },
75
+ "recovery-compass": {
76
+ "url": "https://huggingface.co/spaces/Recovery-Compass-79/README",
77
+ "oauth": true
78
+ }
79
+ }
80
+ }
81
+ ```
82
+
83
+ ### Available MCP Tools
84
+
85
+ 1. **Spaces Semantic Search**
86
+ - Find AI Apps via natural language
87
+ - Example: "Find mental health support spaces"
88
+
89
+ 2. **Papers Semantic Search**
90
+ - Search ML research papers
91
+ - Example: "Papers about recovery prediction models"
92
+
93
+ 3. **Model Search**
94
+ - Find ML models with filters
95
+ - Example: "Find sentiment analysis models"
96
+
97
+ 4. **Dataset Search**
98
+ - Search datasets
99
+ - Example: "Mental health conversation datasets"
100
+
101
+ 5. **Documentation Search**
102
+ - Search HF documentation
103
+ - Example: "How to fine-tune a model"
104
+
105
+ 6. **Hub Repository Details**
106
+ - Get info about repos
107
+ - Include README files
108
+
109
+ ## πŸ”— Connect Valuable Apps
110
+
111
+ ### Recommended Spaces to Connect
112
+
113
+ 1. **evalstate/flux1_schnell** - Fast image generation
114
+ 2. **Mental Health Support Spaces** - Crisis counseling
115
+ 3. **Wellness Tracking** - Progress monitoring
116
+ 4. **Mindfulness Tools** - Meditation guidance
117
+
118
+ ### How to Connect Apps
119
+
120
+ 1. Visit: https://huggingface.co/settings/connected-applications
121
+ 2. Authorize each app
122
+ 3. Grant appropriate permissions:
123
+ - Public profile (always)
124
+ - View repo contents (for integration)
125
+ - Edit repo contents (if needed)
126
+ - List MCP tools (for MCP access)
127
+
128
+ ### Currently Connected Apps
129
+
130
+ Based on your setup:
131
+ - βœ… Claude (MCP tools + repo access)
132
+ - βœ… DeepSite (repo management)
133
+
134
+ ## πŸ“± API Endpoints
135
+
136
+ ### Health Check
137
+ ```bash
138
+ curl https://Recovery-Compass-79-README.hf.space/health
139
+ ```
140
+
141
+ ### Search Resources
142
+ ```bash
143
+ curl "https://Recovery-Compass-79-README.hf.space/api/search?query=recovery"
144
+ ```
145
+
146
+ ### List Models
147
+ ```bash
148
+ curl "https://Recovery-Compass-79-README.hf.space/api/models?task=text-generation&limit=5"
149
+ ```
150
+
151
+ ### List Datasets
152
+ ```bash
153
+ curl "https://Recovery-Compass-79-README.hf.space/api/datasets?task=text-classification&limit=5"
154
+ ```
155
+
156
+ ### AI Chat
157
+ ```bash
158
+ curl -X POST https://Recovery-Compass-79-README.hf.space/api/chat \
159
+ -H "Content-Type: application/json" \
160
+ -d '{"message": "I need support today"}'
161
+ ```
162
+
163
+ ### List Recovery Spaces
164
+ ```bash
165
+ curl https://Recovery-Compass-79-README.hf.space/api/spaces
166
+ ```
167
+
168
+ ## πŸ” OAuth Configuration
169
+
170
+ ### Set Up OAuth App
171
+
172
+ 1. Go to: https://huggingface.co/settings/applications
173
+ 2. Create new OAuth application
174
+ 3. Set redirect URI: `https://huggingface.co/spaces/Recovery-Compass-79/README/callback`
175
+ 4. Get client ID and secret
176
+ 5. Add to `.env` file
177
+
178
+ ### Required Scopes
179
+
180
+ - `profile` - User profile information
181
+ - `read` - Read access to repos
182
+ - `write` - Write access for data storage
183
+ - `mcp` - MCP tools access
184
+
185
+ ## πŸ› οΈ Advanced Configuration
186
+
187
+ ### Enable All MCP Tools
188
+
189
+ Edit `mcp-config.json` to enable/disable tools:
190
+
191
+ ```json
192
+ {
193
+ "capabilities": {
194
+ "semantic_search": { "enabled": true },
195
+ "model_inference": { "enabled": true },
196
+ "dataset_access": { "enabled": true },
197
+ "space_integration": { "enabled": true },
198
+ "progress_tracking": { "enabled": true }
199
+ }
200
+ }
201
+ ```
202
+
203
+ ### Add Custom Spaces
204
+
205
+ Add recommended spaces in `mcp-config.json`:
206
+
207
+ ```json
208
+ {
209
+ "integration": {
210
+ "recommended_spaces": [
211
+ "your-space-1",
212
+ "your-space-2"
213
+ ]
214
+ }
215
+ }
216
+ ```
217
+
218
+ ## πŸ§ͺ Testing
219
+
220
+ ### Local Testing
221
+
222
+ ```bash
223
+ # Test health endpoint
224
+ curl http://localhost:7860/health
225
+
226
+ # Test MCP info
227
+ curl http://localhost:7860/mcp
228
+
229
+ # Test search
230
+ curl "http://localhost:7860/api/search?query=test"
231
+ ```
232
+
233
+ ### Production Testing
234
+
235
+ Replace `localhost:7860` with `Recovery-Compass-79-README.hf.space`
236
+
237
+ ## πŸ“Š Monitoring
238
+
239
+ ### Check Space Status
240
+
241
+ Visit: https://huggingface.co/spaces/Recovery-Compass-79/README/logs
242
+
243
+ ### API Usage
244
+
245
+ Monitor requests through FastAPI docs:
246
+ https://Recovery-Compass-79-README.hf.space/docs
247
+
248
+ ## πŸ”§ Troubleshooting
249
+
250
+ ### OAuth Issues
251
+ - Verify redirect URI matches exactly
252
+ - Check token permissions
253
+ - Ensure client secret is correct
254
+
255
+ ### MCP Connection Issues
256
+ - Confirm OAuth is completed
257
+ - Check MCP client configuration
258
+ - Verify Space is running
259
+
260
+ ### API Errors
261
+ - Check Space logs
262
+ - Verify HF token is valid
263
+ - Test endpoints locally first
264
+
265
+ ## πŸ“š Resources
266
+
267
+ - [Hugging Face MCP Server](https://huggingface.co/mcp)
268
+ - [OAuth Documentation](https://huggingface.co/docs/hub/oauth)
269
+ - [Spaces Documentation](https://huggingface.co/docs/hub/spaces)
270
+ - [FastAPI Documentation](https://fastapi.tiangolo.com/)
271
+ - [MCP Protocol](https://modelcontextprotocol.io/)
272
+
273
+ ## 🀝 Support
274
+
275
+ For issues or questions:
276
+ - GitHub Issues: [Create an issue]
277
+ - Hugging Face Discussions: [Community forum]
278
+ - Email: support@recoverycompass.example
279
+
280
+ ## πŸŽ‰ Next Steps
281
+
282
+ 1. βœ… Complete OAuth setup
283
+ 2. βœ… Connect recommended apps
284
+ 3. βœ… Test all API endpoints
285
+ 4. βœ… Configure MCP client
286
+ 5. βœ… Start using with AI assistants!
287
+
288
+ ---
289
+
290
+ Built with ❀️ for the recovery community
app.py CHANGED
@@ -1,7 +1,277 @@
1
- from fastapi import FastAPI
 
 
 
 
 
2
 
3
- app = FastAPI()
 
 
 
 
4
 
5
- @app.get("/")
6
- def greet_json():
7
- return {"Hello": "World!"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, Request, HTTPException
2
+ from fastapi.responses import HTMLResponse, RedirectResponse
3
+ from fastapi.middleware.cors import CORSMiddleware
4
+ from huggingface_hub import HfApi, SpaceInfo
5
+ import os
6
+ import httpx
7
 
8
+ app = FastAPI(
9
+ title="Recovery Compass MCP Hub",
10
+ description="AI-powered recovery support with Hugging Face MCP integration",
11
+ version="1.0.0"
12
+ )
13
 
14
+ # CORS middleware
15
+ app.add_middleware(
16
+ CORSMiddleware,
17
+ allow_origins=["*"],
18
+ allow_credentials=True,
19
+ allow_methods=["*"],
20
+ allow_headers=["*"],
21
+ )
22
+
23
+ # Initialize HF API
24
+ hf_api = HfApi()
25
+
26
+ @app.get("/", response_class=HTMLResponse)
27
+ async def root():
28
+ """Welcome page with OAuth login option"""
29
+ html_content = """
30
+ <!DOCTYPE html>
31
+ <html>
32
+ <head>
33
+ <title>Recovery Compass MCP Hub</title>
34
+ <style>
35
+ body {
36
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
37
+ max-width: 800px;
38
+ margin: 50px auto;
39
+ padding: 20px;
40
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
41
+ color: white;
42
+ }
43
+ .container {
44
+ background: rgba(255, 255, 255, 0.1);
45
+ backdrop-filter: blur(10px);
46
+ border-radius: 20px;
47
+ padding: 40px;
48
+ box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
49
+ }
50
+ h1 {
51
+ text-align: center;
52
+ font-size: 2.5em;
53
+ margin-bottom: 10px;
54
+ }
55
+ .tagline {
56
+ text-align: center;
57
+ font-size: 1.2em;
58
+ margin-bottom: 30px;
59
+ opacity: 0.9;
60
+ }
61
+ .features {
62
+ margin: 30px 0;
63
+ }
64
+ .feature {
65
+ background: rgba(255, 255, 255, 0.1);
66
+ padding: 15px;
67
+ margin: 10px 0;
68
+ border-radius: 10px;
69
+ }
70
+ .btn {
71
+ display: block;
72
+ width: 200px;
73
+ margin: 20px auto;
74
+ padding: 15px;
75
+ background: #ff6b6b;
76
+ color: white;
77
+ text-align: center;
78
+ text-decoration: none;
79
+ border-radius: 10px;
80
+ font-weight: bold;
81
+ transition: all 0.3s;
82
+ }
83
+ .btn:hover {
84
+ background: #ee5a5a;
85
+ transform: translateY(-2px);
86
+ box-shadow: 0 5px 20px rgba(0,0,0,0.3);
87
+ }
88
+ .api-link {
89
+ text-align: center;
90
+ margin-top: 20px;
91
+ }
92
+ .api-link a {
93
+ color: #ffeb3b;
94
+ text-decoration: none;
95
+ }
96
+ </style>
97
+ </head>
98
+ <body>
99
+ <div class="container">
100
+ <h1>🧭 Recovery Compass</h1>
101
+ <p class="tagline">AI-Powered Recovery Support with MCP Integration</p>
102
+
103
+ <div class="features">
104
+ <div class="feature">
105
+ <strong>πŸ€– MCP Server Integration</strong>
106
+ <p>Connect to Hugging Face models, datasets, and Spaces</p>
107
+ </div>
108
+ <div class="feature">
109
+ <strong>πŸ” Semantic Search</strong>
110
+ <p>Find recovery resources, research papers, and support tools</p>
111
+ </div>
112
+ <div class="feature">
113
+ <strong>πŸ’¬ AI Chat Support</strong>
114
+ <p>24/7 AI-powered recovery guidance and support</p>
115
+ </div>
116
+ <div class="feature">
117
+ <strong>πŸ“Š Progress Tracking</strong>
118
+ <p>Monitor your recovery journey with AI insights</p>
119
+ </div>
120
+ </div>
121
+
122
+ <a href="https://huggingface.co/oauth/authorize?client_id=Recovery-Compass-79&scope=profile&redirect_uri=https://huggingface.co/spaces/Recovery-Compass-79/README" class="btn">
123
+ πŸš€ Login with Hugging Face
124
+ </a>
125
+
126
+ <div class="api-link">
127
+ <a href="/docs">πŸ“š API Documentation</a> |
128
+ <a href="/health">❀️ Health Check</a> |
129
+ <a href="/mcp">πŸ”Œ MCP Info</a>
130
+ </div>
131
+ </div>
132
+ </body>
133
+ </html>
134
+ """
135
+ return html_content
136
+
137
+ @app.get("/health")
138
+ async def health_check():
139
+ """Health check endpoint"""
140
+ return {
141
+ "status": "healthy",
142
+ "service": "Recovery Compass MCP Hub",
143
+ "version": "1.0.0",
144
+ "mcp_enabled": True
145
+ }
146
+
147
+ @app.get("/mcp")
148
+ async def mcp_info():
149
+ """MCP server information"""
150
+ return {
151
+ "mcp_server": "Recovery Compass Hub",
152
+ "capabilities": [
153
+ "semantic_search",
154
+ "model_inference",
155
+ "dataset_access",
156
+ "space_integration",
157
+ "progress_tracking"
158
+ ],
159
+ "connected_tools": [
160
+ "Hugging Face Hub API",
161
+ "Spaces Semantic Search",
162
+ "Papers Search",
163
+ "Model Repository",
164
+ "Dataset Repository"
165
+ ],
166
+ "endpoints": {
167
+ "search": "/api/search",
168
+ "models": "/api/models",
169
+ "datasets": "/api/datasets",
170
+ "chat": "/api/chat"
171
+ }
172
+ }
173
+
174
+ @app.get("/api/search")
175
+ async def semantic_search(query: str):
176
+ """Search Hugging Face resources"""
177
+ try:
178
+ # Search models
179
+ models = list(hf_api.list_models(search=query, limit=5))
180
+
181
+ # Search datasets
182
+ datasets = list(hf_api.list_datasets(search=query, limit=5))
183
+
184
+ return {
185
+ "query": query,
186
+ "models": [{"id": m.id, "tags": m.tags[:5]} for m in models],
187
+ "datasets": [{"id": d.id, "tags": d.tags[:5]} for d in datasets],
188
+ "total_results": len(models) + len(datasets)
189
+ }
190
+ except Exception as e:
191
+ raise HTTPException(status_code=500, detail=str(e))
192
+
193
+ @app.get("/api/models")
194
+ async def list_models(task: str = None, limit: int = 10):
195
+ """List available models"""
196
+ try:
197
+ models = list(hf_api.list_models(filter=task, limit=limit))
198
+ return {
199
+ "task": task,
200
+ "count": len(models),
201
+ "models": [
202
+ {
203
+ "id": m.id,
204
+ "tags": m.tags[:5],
205
+ "downloads": getattr(m, 'downloads', 0)
206
+ } for m in models
207
+ ]
208
+ }
209
+ except Exception as e:
210
+ raise HTTPException(status_code=500, detail=str(e))
211
+
212
+ @app.get("/api/datasets")
213
+ async def list_datasets(task: str = None, limit: int = 10):
214
+ """List available datasets"""
215
+ try:
216
+ datasets = list(hf_api.list_datasets(filter=task, limit=limit))
217
+ return {
218
+ "task": task,
219
+ "count": len(datasets),
220
+ "datasets": [
221
+ {
222
+ "id": d.id,
223
+ "tags": d.tags[:5],
224
+ } for d in datasets
225
+ ]
226
+ }
227
+ except Exception as e:
228
+ raise HTTPException(status_code=500, detail=str(e))
229
+
230
+ @app.post("/api/chat")
231
+ async def chat_endpoint(request: Request):
232
+ """AI chat endpoint for recovery support"""
233
+ data = await request.json()
234
+ message = data.get("message", "")
235
+
236
+ return {
237
+ "response": f"Thank you for reaching out. I'm here to support your recovery journey. You said: {message}",
238
+ "suggestions": [
239
+ "Tell me about your recovery goals",
240
+ "Find support resources",
241
+ "Track my progress",
242
+ "Connect with community"
243
+ ],
244
+ "resources": [
245
+ "Crisis support: Available 24/7",
246
+ "Community forums: Join discussions",
247
+ "Progress tracking: Start your journal"
248
+ ]
249
+ }
250
+
251
+ @app.get("/api/spaces")
252
+ async def list_recovery_spaces():
253
+ """List relevant recovery and support Spaces"""
254
+ try:
255
+ # Search for relevant spaces
256
+ spaces_to_recommend = [
257
+ "mental health support",
258
+ "crisis counseling",
259
+ "wellness tracking",
260
+ "mindfulness meditation"
261
+ ]
262
+
263
+ all_spaces = []
264
+ for search_term in spaces_to_recommend:
265
+ spaces = list(hf_api.list_spaces(search=search_term, limit=3))
266
+ all_spaces.extend([{
267
+ "id": s.id,
268
+ "author": s.author,
269
+ "category": search_term
270
+ } for s in spaces])
271
+
272
+ return {
273
+ "recommended_spaces": all_spaces,
274
+ "total": len(all_spaces)
275
+ }
276
+ except Exception as e:
277
+ raise HTTPException(status_code=500, detail=str(e))
mcp-config.json ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "recovery-compass-mcp",
3
+ "version": "1.0.0",
4
+ "description": "Recovery Compass MCP Hub - AI-powered recovery support with Hugging Face integration",
5
+ "mcpServers": {
6
+ "huggingface": {
7
+ "url": "https://huggingface.co/mcp",
8
+ "oauth": true,
9
+ "tools": [
10
+ "spaces_semantic_search",
11
+ "papers_semantic_search",
12
+ "model_search",
13
+ "dataset_search",
14
+ "documentation_search",
15
+ "run_and_manage_jobs",
16
+ "hub_repository_details"
17
+ ]
18
+ },
19
+ "recovery-compass": {
20
+ "url": "https://huggingface.co/spaces/Recovery-Compass-79/README",
21
+ "oauth": true,
22
+ "tools": [
23
+ "semantic_search",
24
+ "chat_support",
25
+ "progress_tracking",
26
+ "resource_finder",
27
+ "community_connect"
28
+ ]
29
+ }
30
+ },
31
+ "capabilities": {
32
+ "semantic_search": {
33
+ "enabled": true,
34
+ "description": "Search for recovery resources, research papers, and support tools"
35
+ },
36
+ "model_inference": {
37
+ "enabled": true,
38
+ "description": "Access to AI models for chat support and analysis"
39
+ },
40
+ "dataset_access": {
41
+ "enabled": true,
42
+ "description": "Access to recovery and mental health datasets"
43
+ },
44
+ "space_integration": {
45
+ "enabled": true,
46
+ "description": "Connect to other Hugging Face Spaces"
47
+ },
48
+ "progress_tracking": {
49
+ "enabled": true,
50
+ "description": "Monitor and analyze recovery progress"
51
+ }
52
+ },
53
+ "endpoints": {
54
+ "api": {
55
+ "base_url": "https://Recovery-Compass-79-README.hf.space",
56
+ "health": "/health",
57
+ "mcp_info": "/mcp",
58
+ "search": "/api/search",
59
+ "models": "/api/models",
60
+ "datasets": "/api/datasets",
61
+ "chat": "/api/chat",
62
+ "spaces": "/api/spaces"
63
+ }
64
+ },
65
+ "authentication": {
66
+ "oauth": {
67
+ "provider": "huggingface",
68
+ "client_id": "Recovery-Compass-79",
69
+ "scopes": ["profile", "read", "write"],
70
+ "redirect_uri": "https://huggingface.co/spaces/Recovery-Compass-79/README/callback"
71
+ }
72
+ },
73
+ "integration": {
74
+ "recommended_spaces": [
75
+ "evalstate/flux1_schnell",
76
+ "mental-health-support",
77
+ "crisis-counseling",
78
+ "wellness-tracking"
79
+ ],
80
+ "connected_apps": [
81
+ "Claude",
82
+ "DeepSite"
83
+ ]
84
+ }
85
+ }
requirements.txt CHANGED
@@ -1,2 +1,10 @@
1
  fastapi
2
  uvicorn[standard]
 
 
 
 
 
 
 
 
 
1
  fastapi
2
  uvicorn[standard]
3
+ huggingface_hub
4
+ python-multipart
5
+ python-jose[cryptography]
6
+ pydantic
7
+ httpx
8
+ gradio
9
+ transformers
10
+ torch
setup.sh ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Recovery Compass MCP Hub Setup Script
4
+ # This script helps you set up and configure the Recovery Compass Space
5
+
6
+ set -e
7
+
8
+ echo "🧭 Recovery Compass MCP Hub Setup"
9
+ echo "=================================="
10
+ echo ""
11
+
12
+ # Colors for output
13
+ RED='\033[0;31m'
14
+ GREEN='\033[0;32m'
15
+ YELLOW='\033[1;33m'
16
+ NC='\033[0m' # No Color
17
+
18
+ # Check if Python is installed
19
+ if ! command -v python3 &> /dev/null; then
20
+ echo -e "${RED}Error: Python 3 is not installed${NC}"
21
+ exit 1
22
+ fi
23
+
24
+ echo -e "${GREEN}βœ“ Python 3 found${NC}"
25
+
26
+ # Check if pip is installed
27
+ if ! command -v pip3 &> /dev/null; then
28
+ echo -e "${RED}Error: pip3 is not installed${NC}"
29
+ exit 1
30
+ fi
31
+
32
+ echo -e "${GREEN}βœ“ pip3 found${NC}"
33
+
34
+ # Install dependencies
35
+ echo ""
36
+ echo "πŸ“¦ Installing dependencies..."
37
+ pip3 install -r requirements.txt
38
+
39
+ # Check if HF token is configured
40
+ echo ""
41
+ echo "πŸ”‘ Checking Hugging Face authentication..."
42
+ if python3 -c "from huggingface_hub import HfApi; HfApi().whoami()" 2>/dev/null; then
43
+ echo -e "${GREEN}βœ“ Already authenticated with Hugging Face${NC}"
44
+ else
45
+ echo -e "${YELLOW}! Not authenticated. Run: python3 -c 'from huggingface_hub import login; login()'${NC}"
46
+ fi
47
+
48
+ # Create .env file if it doesn't exist
49
+ if [ ! -f .env ]; then
50
+ echo ""
51
+ echo "πŸ“ Creating .env file from template..."
52
+ cp .env.example .env
53
+ echo -e "${YELLOW}! Please edit .env file with your credentials${NC}"
54
+ fi
55
+
56
+ # Test the application
57
+ echo ""
58
+ echo "πŸ§ͺ Testing application..."
59
+ if python3 -c "import app; print('βœ“ App imports successfully')" 2>/dev/null; then
60
+ echo -e "${GREEN}βœ“ Application is ready${NC}"
61
+ else
62
+ echo -e "${RED}βœ— Application import failed${NC}"
63
+ exit 1
64
+ fi
65
+
66
+ echo ""
67
+ echo "=================================="
68
+ echo -e "${GREEN}βœ… Setup complete!${NC}"
69
+ echo ""
70
+ echo "πŸš€ Next steps:"
71
+ echo "1. Edit .env file with your credentials"
72
+ echo "2. Run locally: uvicorn app:app --host 0.0.0.0 --port 7860"
73
+ echo "3. Or deploy to Hugging Face: git push"
74
+ echo ""
75
+ echo "πŸ“š Documentation: https://huggingface.co/spaces/Recovery-Compass-79/README"
76
+ echo ""