Spaces:
Running
Running
fix config
Browse files- py_backend/app/config.py +0 -1
- py_backend/app/routers/caption.py +0 -13
- py_backend/app/routers/upload.py +0 -3
- py_backend/run_tests_simple.py +45 -0
- py_backend/tests/README.md +36 -64
- py_backend/tests/run_tests.py +11 -1
- py_backend/tests/test_config.py +39 -0
py_backend/app/config.py
CHANGED
|
@@ -16,7 +16,6 @@ class Settings(BaseSettings):
|
|
| 16 |
STORAGE_PROVIDER: str = "local"
|
| 17 |
STORAGE_DIR: str = "/data/uploads"
|
| 18 |
HF_HOME: str = "/data/.cache/huggingface"
|
| 19 |
-
BASE_URL: str = "https://huggingface.co/spaces/promptAId/Promptaid-VIsion"
|
| 20 |
|
| 21 |
class Config:
|
| 22 |
env_file = ".env"
|
|
|
|
| 16 |
STORAGE_PROVIDER: str = "local"
|
| 17 |
STORAGE_DIR: str = "/data/uploads"
|
| 18 |
HF_HOME: str = "/data/.cache/huggingface"
|
|
|
|
| 19 |
|
| 20 |
class Config:
|
| 21 |
env_file = ".env"
|
py_backend/app/routers/caption.py
CHANGED
|
@@ -144,9 +144,6 @@ async def create_caption(
|
|
| 144 |
except Exception:
|
| 145 |
url = f"/api/images/{c.image_id}/file"
|
| 146 |
|
| 147 |
-
if url and url.startswith('/') and settings.BASE_URL:
|
| 148 |
-
url = f"{settings.BASE_URL}{url}"
|
| 149 |
-
|
| 150 |
img_dict = convert_image_to_dict(c, url)
|
| 151 |
return schemas.ImageOut(**img_dict)
|
| 152 |
|
|
@@ -172,10 +169,6 @@ def get_caption(
|
|
| 172 |
except Exception:
|
| 173 |
url = f"/api/images/{caption.image_id}/file"
|
| 174 |
|
| 175 |
-
|
| 176 |
-
if url and url.startswith('/') and settings.BASE_URL:
|
| 177 |
-
url = f"{settings.BASE_URL}{url}"
|
| 178 |
-
|
| 179 |
img_dict = convert_image_to_dict(caption, url)
|
| 180 |
return schemas.ImageOut(**img_dict)
|
| 181 |
|
|
@@ -200,9 +193,6 @@ def get_captions_by_image(
|
|
| 200 |
except Exception:
|
| 201 |
url = f"/api/images/{caption.image_id}/file"
|
| 202 |
|
| 203 |
-
if url and url.startswith('/') and settings.BASE_URL:
|
| 204 |
-
url = f"{settings.BASE_URL}{url}"
|
| 205 |
-
|
| 206 |
img_dict = convert_image_to_dict(caption, url)
|
| 207 |
result.append(schemas.ImageOut(**img_dict))
|
| 208 |
|
|
@@ -259,9 +249,6 @@ def update_caption(
|
|
| 259 |
except Exception:
|
| 260 |
url = f"/api/images/{caption.image_id}/file"
|
| 261 |
|
| 262 |
-
if url and url.startswith('/') and settings.BASE_URL:
|
| 263 |
-
url = f"{settings.BASE_URL}{url}"
|
| 264 |
-
|
| 265 |
img_dict = convert_image_to_dict(caption, url)
|
| 266 |
return schemas.ImageOut(**img_dict)
|
| 267 |
|
|
|
|
| 144 |
except Exception:
|
| 145 |
url = f"/api/images/{c.image_id}/file"
|
| 146 |
|
|
|
|
|
|
|
|
|
|
| 147 |
img_dict = convert_image_to_dict(c, url)
|
| 148 |
return schemas.ImageOut(**img_dict)
|
| 149 |
|
|
|
|
| 169 |
except Exception:
|
| 170 |
url = f"/api/images/{caption.image_id}/file"
|
| 171 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
img_dict = convert_image_to_dict(caption, url)
|
| 173 |
return schemas.ImageOut(**img_dict)
|
| 174 |
|
|
|
|
| 193 |
except Exception:
|
| 194 |
url = f"/api/images/{caption.image_id}/file"
|
| 195 |
|
|
|
|
|
|
|
|
|
|
| 196 |
img_dict = convert_image_to_dict(caption, url)
|
| 197 |
result.append(schemas.ImageOut(**img_dict))
|
| 198 |
|
|
|
|
| 249 |
except Exception:
|
| 250 |
url = f"/api/images/{caption.image_id}/file"
|
| 251 |
|
|
|
|
|
|
|
|
|
|
| 252 |
img_dict = convert_image_to_dict(caption, url)
|
| 253 |
return schemas.ImageOut(**img_dict)
|
| 254 |
|
py_backend/app/routers/upload.py
CHANGED
|
@@ -36,9 +36,6 @@ def convert_image_to_dict(img, image_url):
|
|
| 36 |
print(f"Warning: Error processing countries for image {img.image_id}: {e}")
|
| 37 |
countries_list = []
|
| 38 |
|
| 39 |
-
if image_url and image_url.startswith('/') and settings.BASE_URL:
|
| 40 |
-
image_url = f"{settings.BASE_URL}{image_url}"
|
| 41 |
-
|
| 42 |
img_dict = {
|
| 43 |
"image_id": img.image_id,
|
| 44 |
"file_key": img.file_key,
|
|
|
|
| 36 |
print(f"Warning: Error processing countries for image {img.image_id}: {e}")
|
| 37 |
countries_list = []
|
| 38 |
|
|
|
|
|
|
|
|
|
|
| 39 |
img_dict = {
|
| 40 |
"image_id": img.image_id,
|
| 41 |
"file_key": img.file_key,
|
py_backend/run_tests_simple.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Simple test runner for PromptAid Vision"""
|
| 3 |
+
|
| 4 |
+
import subprocess
|
| 5 |
+
import sys
|
| 6 |
+
import os
|
| 7 |
+
|
| 8 |
+
def main():
|
| 9 |
+
"""Run the configuration test"""
|
| 10 |
+
print("Running PromptAid Vision Configuration Test...")
|
| 11 |
+
|
| 12 |
+
try:
|
| 13 |
+
# Change to tests directory
|
| 14 |
+
os.chdir('tests')
|
| 15 |
+
|
| 16 |
+
# Run the config test
|
| 17 |
+
result = subprocess.run([sys.executable, 'test_config.py'],
|
| 18 |
+
capture_output=True, text=True, timeout=60)
|
| 19 |
+
|
| 20 |
+
print("\n" + "="*50)
|
| 21 |
+
print("CONFIGURATION TEST RESULTS")
|
| 22 |
+
print("="*50)
|
| 23 |
+
|
| 24 |
+
if result.returncode == 0:
|
| 25 |
+
print("✅ Configuration test PASSED")
|
| 26 |
+
print("\nOutput:")
|
| 27 |
+
print(result.stdout)
|
| 28 |
+
else:
|
| 29 |
+
print("❌ Configuration test FAILED")
|
| 30 |
+
if result.stdout:
|
| 31 |
+
print("\nOutput:")
|
| 32 |
+
print(result.stdout)
|
| 33 |
+
if result.stderr:
|
| 34 |
+
print("\nErrors:")
|
| 35 |
+
print(result.stderr)
|
| 36 |
+
|
| 37 |
+
return result.returncode == 0
|
| 38 |
+
|
| 39 |
+
except Exception as e:
|
| 40 |
+
print(f"❌ Error running test: {e}")
|
| 41 |
+
return False
|
| 42 |
+
|
| 43 |
+
if __name__ == "__main__":
|
| 44 |
+
success = main()
|
| 45 |
+
sys.exit(0 if success else 1)
|
py_backend/tests/README.md
CHANGED
|
@@ -1,16 +1,20 @@
|
|
| 1 |
-
# PromptAid Vision
|
| 2 |
|
| 3 |
-
This
|
| 4 |
|
| 5 |
-
## Test
|
| 6 |
|
| 7 |
-
### Core
|
| 8 |
-
- **`test_core.py`** - Core application functionality
|
| 9 |
-
- **`
|
| 10 |
|
| 11 |
-
###
|
| 12 |
-
- **`
|
| 13 |
-
- **`
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
## Running Tests
|
| 16 |
|
|
@@ -23,70 +27,38 @@ python tests/run_tests.py
|
|
| 23 |
### Run Individual Tests
|
| 24 |
```bash
|
| 25 |
cd py_backend
|
| 26 |
-
python tests/
|
| 27 |
-
python tests/
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
```
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
```bash
|
| 36 |
-
cp .env.example .env
|
| 37 |
-
```
|
| 38 |
-
|
| 39 |
-
2. **Required API Keys**:
|
| 40 |
-
- `HF_API_KEY` - Hugging Face API key
|
| 41 |
-
- `OPENAI_API_KEY` - OpenAI API key (for GPT-4 Vision)
|
| 42 |
-
- `GOOGLE_API_KEY` - Google API key (for Gemini Vision)
|
| 43 |
|
| 44 |
-
|
| 45 |
-
```bash
|
| 46 |
-
pip install -r requirements.txt
|
| 47 |
-
```
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
|
| 53 |
-
## Test
|
| 54 |
|
| 55 |
-
|
| 56 |
-
- **SUCCESS** - Test completed successfully
|
| 57 |
-
- **ERROR** - Test encountered errors
|
| 58 |
-
- **TIMEOUT** - Test took too long
|
| 59 |
-
- **WARNING** - Unexpected error occurred
|
| 60 |
|
| 61 |
## Troubleshooting
|
| 62 |
|
| 63 |
-
|
| 64 |
-
1. **Import Errors**: Tests automatically add the parent directory to Python path
|
| 65 |
-
2. **API Key Issues**: Ensure your API keys are valid and have proper permissions
|
| 66 |
-
3. **Database Connection**: Check database credentials and connection
|
| 67 |
-
4. **Timeout Issues**: Some tests may take longer on first run due to model loading
|
| 68 |
-
|
| 69 |
-
### Debug Mode
|
| 70 |
-
|
| 71 |
-
For detailed debugging, run individual tests directly:
|
| 72 |
-
```bash
|
| 73 |
-
python tests/test_core.py
|
| 74 |
-
```
|
| 75 |
-
|
| 76 |
-
### Logs
|
| 77 |
-
|
| 78 |
-
Check the console output for detailed error messages and debugging information.
|
| 79 |
|
| 80 |
## Adding New Tests
|
| 81 |
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
4. **Add to README** with description
|
| 88 |
-
|
| 89 |
-
## Related Documentation
|
| 90 |
-
|
| 91 |
-
- **`TROUBLESHOOTING_HF.md`** - Hugging Face API troubleshooting guide
|
| 92 |
-
- **`HUGGINGFACE_INTEGRATION.md`** - Hugging Face integration documentation
|
|
|
|
| 1 |
+
# PromptAid Vision Test Suite
|
| 2 |
|
| 3 |
+
This directory contains comprehensive tests for the PromptAid Vision application.
|
| 4 |
|
| 5 |
+
## Test Organization
|
| 6 |
|
| 7 |
+
### Core Functionality Tests
|
| 8 |
+
- **`test_core.py`** - Core application functionality, database operations, and basic API endpoints
|
| 9 |
+
- **`test_config.py`** - Configuration validation and storage setup verification
|
| 10 |
|
| 11 |
+
### API and Integration Tests
|
| 12 |
+
- **`test_upload_flow.py`** - Complete image upload workflow testing
|
| 13 |
+
- **`test_openai_integration.py`** - OpenAI GPT-4 Vision API integration tests
|
| 14 |
+
- **`test_hf.py`** - Hugging Face Spaces deployment and integration tests
|
| 15 |
+
|
| 16 |
+
### Frontend and UI Tests
|
| 17 |
+
- **`test_explore_page.py`** - Frontend explore page functionality and data display
|
| 18 |
|
| 19 |
## Running Tests
|
| 20 |
|
|
|
|
| 27 |
### Run Individual Tests
|
| 28 |
```bash
|
| 29 |
cd py_backend
|
| 30 |
+
python tests/test_config.py # Test configuration
|
| 31 |
+
python tests/test_core.py # Test core functionality
|
| 32 |
+
python tests/test_upload_flow.py # Test upload flow
|
| 33 |
+
python tests/test_openai_integration.py # Test OpenAI integration
|
| 34 |
+
python tests/test_hf.py # Test Hugging Face integration
|
| 35 |
+
python tests/test_explore_page.py # Test explore page
|
| 36 |
```
|
| 37 |
|
| 38 |
+
### Test Configuration
|
| 39 |
+
```bash
|
| 40 |
+
# Test storage configuration
|
| 41 |
+
python tests/test_config.py
|
| 42 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
+
## Test Dependencies
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
- **Database**: Tests use a test SQLite database
|
| 47 |
+
- **External APIs**: Some tests require API keys (OpenAI, Hugging Face)
|
| 48 |
+
- **Storage**: Tests verify both local and S3 storage configurations
|
| 49 |
|
| 50 |
+
## Test Data
|
| 51 |
|
| 52 |
+
- **`test.jpg`** - Sample image file for testing uploads and image processing
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
## Troubleshooting
|
| 55 |
|
| 56 |
+
See `TROUBLESHOOTING_HF.md` for common Hugging Face deployment issues.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
## Adding New Tests
|
| 59 |
|
| 60 |
+
1. Create test file in this directory
|
| 61 |
+
2. Follow naming convention: `test_*.py`
|
| 62 |
+
3. Add to `run_tests.py` in appropriate category
|
| 63 |
+
4. Ensure tests can run independently
|
| 64 |
+
5. Include proper error handling and cleanup
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
py_backend/tests/run_tests.py
CHANGED
|
@@ -48,9 +48,19 @@ def main():
|
|
| 48 |
print(f"Python: {sys.executable}")
|
| 49 |
print(f"Working Directory: {os.getcwd()}")
|
| 50 |
|
|
|
|
| 51 |
tests = [
|
|
|
|
| 52 |
("test_core.py", "Core Application Tests"),
|
| 53 |
-
("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
]
|
| 55 |
|
| 56 |
passed = 0
|
|
|
|
| 48 |
print(f"Python: {sys.executable}")
|
| 49 |
print(f"Working Directory: {os.getcwd()}")
|
| 50 |
|
| 51 |
+
# Organized by category
|
| 52 |
tests = [
|
| 53 |
+
# Core functionality tests
|
| 54 |
("test_core.py", "Core Application Tests"),
|
| 55 |
+
("test_config.py", "Configuration and Storage Tests"),
|
| 56 |
+
|
| 57 |
+
# API and integration tests
|
| 58 |
+
("test_upload_flow.py", "Upload Flow Tests"),
|
| 59 |
+
("test_openai_integration.py", "OpenAI Integration Tests"),
|
| 60 |
+
("test_hf.py", "Hugging Face Integration Tests"),
|
| 61 |
+
|
| 62 |
+
# Frontend and UI tests
|
| 63 |
+
("test_explore_page.py", "Explore Page Tests"),
|
| 64 |
]
|
| 65 |
|
| 66 |
passed = 0
|
py_backend/tests/test_config.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Test script to verify storage configuration"""
|
| 3 |
+
|
| 4 |
+
import os
|
| 5 |
+
import sys
|
| 6 |
+
sys.path.append('..')
|
| 7 |
+
|
| 8 |
+
from app.config import settings
|
| 9 |
+
from app.storage import get_object_url
|
| 10 |
+
|
| 11 |
+
def test_config():
|
| 12 |
+
print("=== Storage Configuration Test ===")
|
| 13 |
+
print(f"STORAGE_PROVIDER: {settings.STORAGE_PROVIDER}")
|
| 14 |
+
print(f"S3_ENDPOINT: {settings.S3_ENDPOINT}")
|
| 15 |
+
print(f"S3_BUCKET: {settings.S3_BUCKET}")
|
| 16 |
+
print(f"S3_PUBLIC_URL_BASE: {settings.S3_PUBLIC_URL_BASE}")
|
| 17 |
+
|
| 18 |
+
if settings.STORAGE_PROVIDER == "s3":
|
| 19 |
+
print("\n=== S3 Storage Test ===")
|
| 20 |
+
try:
|
| 21 |
+
# Test URL generation
|
| 22 |
+
test_key = "maps/test_image.jpg"
|
| 23 |
+
url = get_object_url(test_key)
|
| 24 |
+
print(f"Generated URL for '{test_key}': {url}")
|
| 25 |
+
|
| 26 |
+
if settings.S3_PUBLIC_URL_BASE:
|
| 27 |
+
print(f"✅ Using public URL base: {settings.S3_PUBLIC_URL_BASE}")
|
| 28 |
+
else:
|
| 29 |
+
print("⚠️ No S3_PUBLIC_URL_BASE set - will use presigned URLs")
|
| 30 |
+
|
| 31 |
+
except Exception as e:
|
| 32 |
+
print(f"❌ Error testing S3 storage: {e}")
|
| 33 |
+
else:
|
| 34 |
+
print(f"\n=== Local Storage Test ===")
|
| 35 |
+
print(f"Storage directory: {settings.STORAGE_DIR}")
|
| 36 |
+
print("✅ Local storage configured")
|
| 37 |
+
|
| 38 |
+
if __name__ == "__main__":
|
| 39 |
+
test_config()
|