Spaces:
Running on Zero
Running on Zero
File size: 4,409 Bytes
5d2d720 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | # Warbler CDA - Quick Start Guide
## π Quick Start (3 options)
### π Home may not be available on path immediately
```bash
# set home path for environment
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
# start the terminal
source ~/.bashrc
```
### Option 1: Local Python (Recommended for Development)
```bash
cd warbler-cda-package
./setup.sh
python app.py
```
Open <http://localhost:7860>
### Option 2: Docker
```bash
cd warbler-cda-package
docker-compose up warbler-cda-demo
```
Open <http://localhost:7860>
### Option 3: HuggingFace Space (Recommended for Sharing)
1. Create a HuggingFace Space at <https://huggingface.co/new-space>
2. Choose "Gradio" as SDK
3. Upload the `warbler-cda-package/` contents
4. Your Space will be live at `https://huggingface.co/spaces/YOUR_USERNAME/warbler-cda`
## π Usage Examples
### Example 1: Basic Query
```python
from warbler_cda import RetrievalAPI, EmbeddingProviderFactory
# Initialize
embedding_provider = EmbeddingProviderFactory.get_default_provider()
api = RetrievalAPI(embedding_provider=embedding_provider)
# Add document
api.add_document(
doc_id="wisdom_1",
content="Courage is not the absence of fear, but acting despite it.",
metadata={"realm_type": "wisdom", "realm_label": "virtue"}
)
# Query
results = api.query_semantic_anchors("What is courage?", max_results=5)
for result in results:
print(f"{result.relevance_score:.3f} - {result.content}")
```
### Example 2: FractalStat Hybrid Scoring
```python
from warbler_cda import FractalStatRAGBridge, RetrievalQuery, RetrievalMode
# Enable FractalStat
fractalstat_bridge = FractalStatRAGBridge()
api = RetrievalAPI(
embedding_provider=embedding_provider,
fractalstat_bridge=fractalstat_bridge,
config={"enable_fractalstat_hybrid": True}
)
# Query with hybrid scoring
query = RetrievalQuery(
query_id="hybrid_1",
mode=RetrievalMode.SEMANTIC_SIMILARITY,
semantic_query="wisdom about resilience",
fractalstat_hybrid=True,
weight_semantic=0.6,
weight_fractalstat=0.4
)
assembly = api.retrieve_context(query)
print(f"Quality: {assembly.assembly_quality:.3f}")
print(f"Results: {len(assembly.results)}")
```
### Example 3: API Service
```bash
# Start the API
uvicorn warbler_cda.api.service:app --host 0.0.0.0 --port 8000
# In another terminal, use the CLI
warbler-cli query --query-id q1 --semantic "wisdom about courage" --hybrid
# Or use curl
curl -X POST http://localhost:8000/query \
-H "Content-Type: application/json" \
-d '{
"query_id": "test1",
"semantic_query": "wisdom about courage",
"fractalstat_hybrid": true
}'
```
## π§ Configuration
### Embedding Providers
```python
# Local TF-IDF (default, no API key needed)
from warbler_cda import EmbeddingProviderFactory
provider = EmbeddingProviderFactory.create_provider("local")
# OpenAI (requires API key)
provider = EmbeddingProviderFactory.create_provider(
"openai",
config={"api_key": "your-api-key", "model": "text-embedding-ada-002"}
)
```
### FractalStat Configuration
```python
# Custom FractalStat weights
api = RetrievalAPI(
fractalstat_bridge=fractalstat_bridge,
config={
"enable_fractalstat_hybrid": True,
"default_weight_semantic": 0.7, # 70% semantic
"default_weight_fractalstat": 0.3 # 30% FractalStat
}
)
```
## π Running Experiments
```python
from warbler_cda import run_all_experiments
# Run FractalStat validation experiments
results = run_all_experiments(
exp01_samples=1000,
exp01_iterations=10,
exp02_queries=1000,
exp03_samples=1000
)
print(f"EXP-01 (Uniqueness): {results['EXP-01']['success']}")
print(f"EXP-02 (Efficiency): {results['EXP-02']['success']}")
print(f"EXP-03 (Necessity): {results['EXP-03']['success']}")
```
## π Troubleshooting
### Import Errors
If you see import errors, make sure the package is installed:
```bash
pip install -e .
```
### Missing Dependencies
Install all dependencies:
```bash
pip install -r requirements.txt
```
### Gradio Not Starting
Check if port 7860 is available:
```bash
lsof -i :7860 # Linux/Mac
netstat -ano | findstr :7860 # Windows
```
## π More Information
- Full documentation: [README.md](README.md)
- Deployment guide: [DEPLOYMENT.md](DEPLOYMENT.md)
- Contributing: [CONTRIBUTING.md](CONTRIBUTING.md)
- Package manifest: [PACKAGE_MANIFEST.md](PACKAGE_MANIFEST.md)
|