Devrajsinh bharatsinh gohil commited on
Commit
2c1143e
·
1 Parent(s): a91ef3d

Fix HF Spaces config: Move Dockerfile to root and add metadata

Browse files
Files changed (2) hide show
  1. Dockerfile +30 -0
  2. README.md +12 -286
Dockerfile ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9-slim
2
+
3
+ WORKDIR /app
4
+
5
+ # Install system dependencies
6
+ RUN apt-get update && apt-get install -y \
7
+ gcc \
8
+ g++ \
9
+ postgresql-client \
10
+ && rm -rf /var/lib/apt/lists/*
11
+
12
+ # Copy requirements and install Python packages
13
+ COPY backend/requirements.txt .
14
+ RUN pip install --no-cache-dir -r requirements.txt
15
+
16
+ # Copy application code from backend directory
17
+ COPY backend/ ./backend/
18
+ # Main entry point needs to be at root level for some runners, or we point pythonpath
19
+ ENV PYTHONPATH=/app/backend
20
+
21
+ # Set environment for model caching to /tmp (only writable dir in HF Spaces)
22
+ ENV HF_HOME=/tmp/.cache/huggingface
23
+ ENV FASTEMBED_CACHE_PATH=/tmp/.cache/fastembed
24
+ ENV SENTENCE_TRANSFORMERS_HOME=/tmp/.cache/sentence-transformers
25
+
26
+ # Expose port 7860 (required by Hugging Face Spaces)
27
+ EXPOSE 7860
28
+
29
+ # Run FastAPI with uvicorn (pointing to nested app)
30
+ CMD ["uvicorn", "backend.main:app", "--host", "0.0.0.0", "--port", "7860"]
README.md CHANGED
@@ -1,289 +1,15 @@
1
- # MEXAR Ultimate 🧠
2
-
3
- **Multimodal Explainable AI Reasoning Assistant**
4
-
5
- [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
6
- [![React 18](https://img.shields.io/badge/react-18-61dafb.svg)](https://reactjs.org/)
7
- [![FastAPI](https://img.shields.io/badge/fastapi-0.109-009688.svg)](https://fastapi.tiangolo.com/)
8
- [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
9
-
10
- MEXAR is an explainable AI system that creates domain-specific intelligent agents from your data. It uses **RAG (Retrieval-Augmented Generation)** with source attribution and faithfulness scoring to provide transparent, verifiable answers.
11
-
12
- ---
13
-
14
- ## ✨ Key Features
15
-
16
- | Feature | Description |
17
- |---------|-------------|
18
- | 🔍 **Hybrid Search** | Combines semantic (vector) + keyword search with RRF fusion |
19
- | 🎯 **Cross-Encoder Reranking** | Improves retrieval precision using sentence-transformers |
20
- | 📊 **Source Attribution** | Inline citations `[1]`, `[2]` linking answers to sources |
21
- | ✅ **Faithfulness Scoring** | Measures how well answers are grounded in context |
22
- | 🗣️ **Multimodal Input** | Audio (Whisper), Images (Vision), Video support |
23
- | 🔐 **Domain Guardrails** | Prevents hallucinations outside knowledge base |
24
- | 🔊 **Text-to-Speech** | ElevenLabs + Web Speech API support |
25
- | 📁 **5 File Types** | CSV, PDF, DOCX, JSON, TXT |
26
-
27
- ---
28
-
29
- ## 🏗️ Architecture
30
-
31
- ```
32
- ┌─────────────────────────────────────────────────────────────────┐
33
- │ MEXAR Architecture │
34
- ├─────────────────────────────────────────────────────────────────┤
35
- │ │
36
- │ [User] ──► [React Frontend] │
37
- │ │ │
38
- │ ▼ │
39
- │ [FastAPI Backend] │
40
- │ │ │
41
- │ ├──► Data Validator (CSV/PDF/DOCX/JSON/TXT) │
42
- │ ├──► Prompt Analyzer (LLM-based domain extraction) │
43
- │ ├──► Knowledge Compiler (FastEmbed → pgvector) │
44
- │ └──► Reasoning Engine │
45
- │ │ │
46
- │ ├──► Hybrid Search (semantic + keyword) │
47
- │ ├──► Reranker (cross-encoder) │
48
- │ ├──► Source Attribution (inline citations) │
49
- │ └──► Faithfulness Scorer (claim verification) │
50
- │ │
51
- │ [External Services] │
52
- │ ├──► Supabase (PostgreSQL + Storage) │
53
- │ ├──► Groq API (LLM + Whisper + Vision) │
54
- │ └──► ElevenLabs (Text-to-Speech) │
55
- └─────────────────────────────────────────────────────────────────┘
56
- ```
57
-
58
- ---
59
-
60
- ## 🚀 Quick Start
61
-
62
- ### Prerequisites
63
-
64
- - **Python 3.9+** with pip
65
- - **Node.js 18+** with npm
66
- - **PostgreSQL** with `pgvector` extension (or use Supabase)
67
- - **Groq API Key** - Get free at [console.groq.com](https://console.groq.com)
68
-
69
- ### 1. Backend Setup
70
-
71
- ```bash
72
- cd backend
73
-
74
- # Create virtual environment
75
- python -m venv venv
76
-
77
- # Activate (Windows)
78
- .\venv\Scripts\activate
79
-
80
- # Activate (macOS/Linux)
81
- source venv/bin/activate
82
-
83
- # Install dependencies
84
- pip install -r requirements.txt
85
- ```
86
-
87
- **Configure Environment Variables:**
88
-
89
- Create `backend/.env`:
90
- ```env
91
- # Required
92
- GROQ_API_KEY=your_groq_api_key_here
93
- DATABASE_URL=postgresql://user:password@host:5432/database
94
- SECRET_KEY=your_secure_secret_key
95
-
96
- # Supabase Storage
97
- SUPABASE_URL=https://your-project.supabase.co
98
- SUPABASE_KEY=your_supabase_service_role_key
99
-
100
- # Optional: ElevenLabs TTS
101
- ELEVENLABS_API_KEY=your_elevenlabs_api_key_here
102
- ```
103
-
104
- **Run Server:**
105
- ```bash
106
- python -m uvicorn main:app --reload --host 0.0.0.0 --port 8000
107
- ```
108
-
109
- ### 2. Frontend Setup
110
-
111
- ```bash
112
- cd frontend
113
-
114
- # Install dependencies
115
- npm install
116
-
117
- # Start development server
118
- npm start
119
- ```
120
-
121
- Open [http://localhost:3000](http://localhost:3000) in your browser.
122
-
123
- ---
124
-
125
- ## 📁 Project Structure
126
-
127
- ```
128
- mexar_ultimate/
129
- ├── backend/
130
- │ ├── api/ # REST API endpoints
131
- │ │ ├── auth.py # Authentication (JWT)
132
- │ │ ├── agents.py # Agent CRUD
133
- │ │ ├── chat.py # Chat + multimodal
134
- │ │ ├── compile.py # Knowledge compilation
135
- │ │ └── websocket.py # Real-time updates
136
- │ ├── core/ # Core configuration
137
- │ │ ├── config.py # Settings
138
- │ │ ├── database.py # SQLAlchemy setup
139
- │ │ └── security.py # JWT handling
140
- │ ├── models/ # Database models
141
- │ │ ├── user.py # User model
142
- │ │ ├── agent.py # Agent + CompilationJob
143
- │ │ ├── chunk.py # DocumentChunk (pgvector)
144
- │ │ └── conversation.py # Chat history
145
- │ ├── modules/ # Core AI modules
146
- │ │ ├── data_validator.py # File parsing
147
- │ │ ├── prompt_analyzer.py # Domain extraction
148
- │ │ ├── knowledge_compiler.py # Vector embeddings
149
- │ │ ├── reasoning_engine.py # RAG pipeline
150
- │ │ ├── multimodal_processor.py # Audio/Image/Video
151
- │ │ └── explainability.py # UI formatting
152
- │ ├── utils/ # Utility modules
153
- │ │ ├── groq_client.py # Groq API wrapper
154
- │ │ ├── hybrid_search.py # RRF search fusion
155
- │ │ ├── reranker.py # Cross-encoder
156
- │ │ ├── faithfulness.py # Claim verification
157
- │ │ └── source_attribution.py # Citation extraction
158
- │ ├── services/ # External services
159
- │ │ ├── tts_service.py # Text-to-speech
160
- │ │ └── storage_service.py # Supabase storage
161
- │ ├── main.py # FastAPI app entry
162
- │ └── requirements.txt # Python dependencies
163
-
164
- ├── frontend/
165
- │ ├── src/
166
- │ │ ├── pages/ # React pages
167
- │ │ │ ├── Landing.jsx # Home page
168
- │ │ │ ├── Login.jsx # Authentication
169
- │ │ │ ├── Dashboard.jsx # User dashboard
170
- │ │ │ ├── AgentCreation.jsx # Create agent
171
- │ │ │ ├── CompilationProgress.jsx # Build progress
172
- │ │ │ └── Chat.jsx # Chat interface
173
- │ │ ├── components/ # Reusable UI
174
- │ │ ├── contexts/ # React contexts
175
- │ │ ├── api/ # API client
176
- │ │ └── App.jsx # Main component
177
- │ └── package.json # Node dependencies
178
-
179
- └── README.md
180
- ```
181
-
182
- ---
183
-
184
- ## 🔧 API Reference
185
-
186
- ### Authentication
187
- | Method | Endpoint | Description |
188
- |--------|----------|-------------|
189
- | POST | `/api/auth/register` | Register new user |
190
- | POST | `/api/auth/login` | Login (returns JWT) |
191
- | GET | `/api/auth/me` | Get current user |
192
-
193
- ### Agents
194
- | Method | Endpoint | Description |
195
- |--------|----------|-------------|
196
- | GET | `/api/agents/` | List all agents |
197
- | GET | `/api/agents/{name}` | Get agent details |
198
- | DELETE | `/api/agents/{name}` | Delete agent |
199
-
200
- ### Compilation
201
- | Method | Endpoint | Description |
202
- |--------|----------|-------------|
203
- | POST | `/api/compile/` | Start compilation (multipart) |
204
- | GET | `/api/compile/{name}/status` | Check compilation status |
205
-
206
- ### Chat
207
- | Method | Endpoint | Description |
208
- |--------|----------|-------------|
209
- | POST | `/api/chat/` | Send message |
210
- | POST | `/api/chat/multimodal` | Send with audio/image |
211
- | GET | `/api/chat/{agent}/history` | Get chat history |
212
- | POST | `/api/chat/transcribe` | Transcribe audio |
213
-
214
- ---
215
-
216
- ## 🧪 Technologies
217
-
218
- ### Backend
219
- - **FastAPI** - Modern async Python web framework
220
- - **SQLAlchemy** - ORM for PostgreSQL
221
- - **pgvector** - Vector similarity search
222
- - **FastEmbed** - Local embedding generation (BAAI/bge-small-en-v1.5)
223
- - **sentence-transformers** - Cross-encoder reranking
224
- - **Groq API** - LLM (Llama 3.1/3.3), Whisper (audio), Vision (images)
225
-
226
- ### Frontend
227
- - **React 18** - UI framework
228
- - **Material-UI** - Component library
229
- - **React Router** - Navigation
230
- - **Axios** - HTTP client
231
-
232
- ### External Services
233
- - **Supabase** - Managed PostgreSQL + Storage
234
- - **Groq** - Fast AI inference
235
- - **ElevenLabs** - Text-to-Speech (optional)
236
-
237
- ---
238
-
239
- ## 📊 How It Works
240
-
241
- ### 1. Agent Creation
242
- ```
243
- User uploads files → DataValidator parses → PromptAnalyzer extracts domain
244
- → KnowledgeCompiler creates embeddings
245
- → Stored in pgvector
246
- ```
247
-
248
- ### 2. Query Processing
249
- ```
250
- User query → Domain Guardrail check
251
- → Hybrid Search (semantic + keyword)
252
- → Cross-Encoder Reranking (top 5)
253
- → LLM Generation with context
254
- → Source Attribution (citations)
255
- → Faithfulness Scoring
256
- → Explainability formatting
257
- ```
258
-
259
- ### 3. Confidence Scoring
260
- Confidence is calculated from:
261
- - **Retrieval Quality** (35%) - How relevant the retrieved chunks are
262
- - **Rerank Score** (30%) - Cross-encoder confidence
263
- - **Faithfulness** (25%) - How grounded the answer is
264
- - **Base Floor** (10%) - For in-domain queries
265
-
266
  ---
267
-
268
- ## 🌐 Deployment
269
-
270
- See [implementation_plan.md](./implementation_plan.md) for detailed deployment instructions covering:
271
- - GitHub repository setup
272
- - Vercel (frontend)
273
- - Render.com (backend)
274
- - Neon PostgreSQL (database)
275
-
276
- ---
277
-
278
- ## 📄 License
279
-
280
- MIT License - See [LICENSE](LICENSE) for details.
281
-
282
  ---
 
283
 
284
- ## 🙏 Acknowledgments
285
-
286
- - [Groq](https://groq.com) - Fast AI inference
287
- - [Supabase](https://supabase.com) - Postgres + Storage
288
- - [FastEmbed](https://github.com/qdrant/fastembed) - Embeddings
289
- - [sentence-transformers](https://www.sbert.net) - Reranking models
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Mexar Ultimate
3
+ emoji: 🧠
4
+ colorFrom: blue
5
+ colorTo: purple
6
+ sdk: docker
7
+ app_port: 7860
8
+ app_file: backend/Dockerfile
9
+ pinned: false
10
+ license: mit
 
 
 
 
 
 
11
  ---
12
+ # MEXAR Ultimate - AI Reasoning Assistant
13
 
14
+ This Space hosts the backend API for MEXAR Ultimate.
15
+ Frontend is deployed separately on Vercel.