Spaces:
Sleeping
Sleeping
“vinit5112”
commited on
Commit
·
45e068b
1
Parent(s):
1edfa40
upload update
Browse files- README.md +61 -1
- frontend/src/components/FileUploader.js +30 -2
- frontend/src/services/api.js +10 -0
README.md
CHANGED
@@ -21,4 +21,64 @@ The application is containerized using Docker and orchestrated with Docker Compo
|
|
21 |
|
22 |
- The **frontend** is a React app served by Nginx.
|
23 |
- The **backend** is a FastAPI server running with Uvicorn.
|
24 |
-
- Nginx acts as a reverse proxy, forwarding API requests from the frontend to the backend.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
- The **frontend** is a React app served by Nginx.
|
23 |
- The **backend** is a FastAPI server running with Uvicorn.
|
24 |
+
- Nginx acts as a reverse proxy, forwarding API requests from the frontend to the backend.
|
25 |
+
|
26 |
+
## 🚀 Quick Setup
|
27 |
+
|
28 |
+
### 1. Environment Configuration
|
29 |
+
```bash
|
30 |
+
# Copy the example environment file
|
31 |
+
cp env.example .env
|
32 |
+
|
33 |
+
# Edit .env with your API keys
|
34 |
+
nano .env
|
35 |
+
```
|
36 |
+
|
37 |
+
Required environment variables:
|
38 |
+
- `GOOGLE_API_KEY`: Get from [Google AI Studio](https://aistudio.google.com/app/apikey)
|
39 |
+
- `QDRANT_URL`: Your Qdrant cloud cluster URL
|
40 |
+
- `QDRANT_API_KEY`: Your Qdrant cloud API key
|
41 |
+
|
42 |
+
### 2. Run System Diagnostic
|
43 |
+
```bash
|
44 |
+
cd backend
|
45 |
+
python diagnostic.py
|
46 |
+
```
|
47 |
+
|
48 |
+
This will check all dependencies and configurations.
|
49 |
+
|
50 |
+
### 3. Start the Application
|
51 |
+
```bash
|
52 |
+
# Using Docker (recommended)
|
53 |
+
docker-compose up --build
|
54 |
+
|
55 |
+
# Or run locally
|
56 |
+
cd backend && python backend_api.py
|
57 |
+
cd frontend && npm start
|
58 |
+
```
|
59 |
+
|
60 |
+
## 🔧 Troubleshooting File Uploads
|
61 |
+
|
62 |
+
If file uploads aren't working, check:
|
63 |
+
|
64 |
+
1. **Environment Variables**: Ensure all required vars are set
|
65 |
+
2. **API Connectivity**: Backend must connect to Qdrant and Google APIs
|
66 |
+
3. **File Size**: Large files (>10MB) may timeout
|
67 |
+
4. **File Format**: Only PDF, DOCX, and TXT are supported
|
68 |
+
5. **Server Status**: Check browser console and server logs
|
69 |
+
|
70 |
+
### Common Upload Errors:
|
71 |
+
|
72 |
+
| Error | Cause | Solution |
|
73 |
+
|-------|-------|----------|
|
74 |
+
| Network Error | Server not running | Start backend server |
|
75 |
+
| 500 Server Error | Missing API keys | Check environment variables |
|
76 |
+
| 413 File Too Large | File exceeds limit | Try smaller files |
|
77 |
+
| 415 Unsupported Type | Wrong file format | Use PDF/DOCX/TXT only |
|
78 |
+
| Timeout | Large file/slow connection | Increase timeout or use smaller files |
|
79 |
+
|
80 |
+
### Debug Steps:
|
81 |
+
1. Run `python backend/diagnostic.py`
|
82 |
+
2. Check browser developer console
|
83 |
+
3. Check backend server logs
|
84 |
+
4. Verify network connectivity to external APIs
|
frontend/src/components/FileUploader.js
CHANGED
@@ -20,9 +20,16 @@ const FileUploader = ({ darkMode, onClose }) => {
|
|
20 |
|
21 |
for (const file of acceptedFiles) {
|
22 |
try {
|
|
|
|
|
23 |
const formData = new FormData();
|
24 |
formData.append('file', file);
|
25 |
|
|
|
|
|
|
|
|
|
|
|
26 |
await uploadDocument(formData);
|
27 |
|
28 |
setUploadedFiles(prev => [...prev, {
|
@@ -32,14 +39,35 @@ const FileUploader = ({ darkMode, onClose }) => {
|
|
32 |
}]);
|
33 |
|
34 |
toast.success(`${file.name} uploaded successfully!`);
|
|
|
|
|
35 |
} catch (error) {
|
|
|
|
|
36 |
setUploadedFiles(prev => [...prev, {
|
37 |
name: file.name,
|
38 |
size: file.size,
|
39 |
-
status: 'error'
|
|
|
40 |
}]);
|
41 |
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
}
|
44 |
}
|
45 |
|
|
|
20 |
|
21 |
for (const file of acceptedFiles) {
|
22 |
try {
|
23 |
+
console.log(`Starting upload for file: ${file.name}, size: ${file.size} bytes`);
|
24 |
+
|
25 |
const formData = new FormData();
|
26 |
formData.append('file', file);
|
27 |
|
28 |
+
// Check file size (warn if > 10MB)
|
29 |
+
if (file.size > 10 * 1024 * 1024) {
|
30 |
+
toast.error(`Warning: ${file.name} is large (${formatFileSize(file.size)}). Upload may take time.`);
|
31 |
+
}
|
32 |
+
|
33 |
await uploadDocument(formData);
|
34 |
|
35 |
setUploadedFiles(prev => [...prev, {
|
|
|
39 |
}]);
|
40 |
|
41 |
toast.success(`${file.name} uploaded successfully!`);
|
42 |
+
console.log(`Successfully uploaded: ${file.name}`);
|
43 |
+
|
44 |
} catch (error) {
|
45 |
+
console.error(`Failed to upload ${file.name}:`, error);
|
46 |
+
|
47 |
setUploadedFiles(prev => [...prev, {
|
48 |
name: file.name,
|
49 |
size: file.size,
|
50 |
+
status: 'error',
|
51 |
+
error: error.message
|
52 |
}]);
|
53 |
|
54 |
+
// More specific error messages
|
55 |
+
let errorMessage = `Failed to upload ${file.name}`;
|
56 |
+
if (error.message.includes('Network Error')) {
|
57 |
+
errorMessage += ': Network connection failed. Check if the server is running.';
|
58 |
+
} else if (error.message.includes('timeout')) {
|
59 |
+
errorMessage += ': Upload timed out. File may be too large.';
|
60 |
+
} else if (error.message.includes('413')) {
|
61 |
+
errorMessage += ': File too large for server.';
|
62 |
+
} else if (error.message.includes('415')) {
|
63 |
+
errorMessage += ': Unsupported file type.';
|
64 |
+
} else if (error.message.includes('500')) {
|
65 |
+
errorMessage += ': Server error. Check server logs.';
|
66 |
+
} else {
|
67 |
+
errorMessage += `: ${error.message}`;
|
68 |
+
}
|
69 |
+
|
70 |
+
toast.error(errorMessage);
|
71 |
}
|
72 |
}
|
73 |
|
frontend/src/services/api.js
CHANGED
@@ -122,11 +122,21 @@ export const uploadDocument = async (formData) => {
|
|
122 |
);
|
123 |
console.log(`Upload progress: ${percentCompleted}%`);
|
124 |
},
|
|
|
125 |
});
|
126 |
|
127 |
return response;
|
128 |
} catch (error) {
|
129 |
console.error('Error uploading document:', error);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
throw error;
|
131 |
}
|
132 |
};
|
|
|
122 |
);
|
123 |
console.log(`Upload progress: ${percentCompleted}%`);
|
124 |
},
|
125 |
+
timeout: 120000, // 2 minutes timeout for large files
|
126 |
});
|
127 |
|
128 |
return response;
|
129 |
} catch (error) {
|
130 |
console.error('Error uploading document:', error);
|
131 |
+
|
132 |
+
// Enhanced error messages for debugging
|
133 |
+
if (error.response) {
|
134 |
+
console.error('Response error:', error.response.data);
|
135 |
+
console.error('Status:', error.response.status);
|
136 |
+
} else if (error.request) {
|
137 |
+
console.error('Request error:', error.request);
|
138 |
+
}
|
139 |
+
|
140 |
throw error;
|
141 |
}
|
142 |
};
|