Spaces:
Running
Running
Solomon7890-jpeg
commited on
Commit
Β·
6c914fc
0
Parent(s):
Deploy ProVerBs v2.1 - App files only (logos via web upload)
Browse files- .gitattributes +38 -0
- .gitignore +2 -0
- CHATBOT_INTEGRATION_GUIDE.md +324 -0
- DEPLOY_INTEGRATED_CHATBOT.bat +56 -0
- DEPLOY_NOW.bat +68 -0
- DEPLOY_WITH_LOGOS.bat +90 -0
- LOCAL_PREVIEW_GUIDE.md +353 -0
- LOGO_DEPLOYMENT_GUIDE.md +288 -0
- MULTI_AI_GUIDE.md +73 -0
- OCR_INTEGRATION_GUIDE.md +287 -0
- PREVIEW_LOCALLY.bat +69 -0
- PREVIEW_TESTING_GUIDE.md +272 -0
- PREVIEW_THEN_DEPLOY.bat +96 -0
- README.md +17 -0
- README_DEPLOYMENT.md +110 -0
- app.py +866 -0
- deploy_to_hf.py +164 -0
- enhanced_app.py +352 -0
- integrated_chatbot_app.py +531 -0
- integrated_chatbot_full_ai.py +866 -0
- integrated_chatbot_with_logos.py +538 -0
- integrated_chatbot_with_ocr.py +547 -0
- requirements.txt +6 -0
.gitattributes
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# π€ AI Legal Chatbot Integration Guide
|
| 2 |
+
|
| 3 |
+
## What's Been Integrated
|
| 4 |
+
|
| 5 |
+
I've integrated your comprehensive **AI Legal Chatbot** from `SOLO'CODES/MODULES/ai_legal_chatbot.py` into your Gradio landing page!
|
| 6 |
+
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
## β¨ New Features
|
| 10 |
+
|
| 11 |
+
### π― 7 Specialized AI Modes
|
| 12 |
+
|
| 13 |
+
Your chatbot now has **7 different modes**, each specialized for specific tasks:
|
| 14 |
+
|
| 15 |
+
| Mode | Icon | Purpose |
|
| 16 |
+
|------|------|---------|
|
| 17 |
+
| **Navigation Guide** | π | Help users find features in the app |
|
| 18 |
+
| **General Legal Assistant** | π¬ | Answer broad legal questions |
|
| 19 |
+
| **Document Validator** | π | Analyze and validate legal documents |
|
| 20 |
+
| **Legal Research** | π | Case law and statutory research |
|
| 21 |
+
| **Etymology Expert** | π | Explain legal term origins |
|
| 22 |
+
| **Case Management** | πΌ | Help organize and track cases |
|
| 23 |
+
| **Regulatory Updates** | π | Monitor legal and regulatory changes |
|
| 24 |
+
|
| 25 |
+
### π How It Works
|
| 26 |
+
|
| 27 |
+
1. User selects a mode from the dropdown
|
| 28 |
+
2. Mode-specific system prompt is loaded
|
| 29 |
+
3. AI responds with specialized knowledge
|
| 30 |
+
4. Context is maintained throughout conversation
|
| 31 |
+
|
| 32 |
+
---
|
| 33 |
+
|
| 34 |
+
## π Files Created
|
| 35 |
+
|
| 36 |
+
### Main Integration File
|
| 37 |
+
**`integrated_chatbot_app.py`**
|
| 38 |
+
- Complete Gradio app with your chatbot
|
| 39 |
+
- All 7 modes integrated
|
| 40 |
+
- Professional UI design
|
| 41 |
+
- Ready to deploy
|
| 42 |
+
|
| 43 |
+
### Deployment Options
|
| 44 |
+
|
| 45 |
+
#### Option 1: Deploy as Main Landing Page
|
| 46 |
+
```bash
|
| 47 |
+
cd ProVerbS_LaW_mAiN_PAgE
|
| 48 |
+
|
| 49 |
+
# Replace app.py with integrated version
|
| 50 |
+
cp integrated_chatbot_app.py app.py
|
| 51 |
+
|
| 52 |
+
# Deploy
|
| 53 |
+
python deploy_to_hf.py
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
#### Option 2: Keep Both Versions
|
| 57 |
+
```bash
|
| 58 |
+
# Deploy integrated version to new Space
|
| 59 |
+
# Edit deploy_to_hf.py to point to integrated_chatbot_app.py
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
---
|
| 63 |
+
|
| 64 |
+
## π¨ Mode Details
|
| 65 |
+
|
| 66 |
+
### 1. π Navigation Guide
|
| 67 |
+
**Purpose**: Help users navigate the platform
|
| 68 |
+
|
| 69 |
+
**System Prompt**:
|
| 70 |
+
- Guides users to appropriate features
|
| 71 |
+
- Explains how to use each module
|
| 72 |
+
- Provides feature recommendations
|
| 73 |
+
|
| 74 |
+
**Example Questions**:
|
| 75 |
+
- "How do I analyze a document?"
|
| 76 |
+
- "Where can I do legal research?"
|
| 77 |
+
- "Show me the document generation feature"
|
| 78 |
+
|
| 79 |
+
### 2. π¬ General Legal Assistant
|
| 80 |
+
**Purpose**: Answer broad legal questions
|
| 81 |
+
|
| 82 |
+
**System Prompt**:
|
| 83 |
+
- Provides accurate legal information
|
| 84 |
+
- Notes it cannot give legal advice
|
| 85 |
+
- Recommends attorney consultation
|
| 86 |
+
- Professional and thorough
|
| 87 |
+
|
| 88 |
+
**Example Questions**:
|
| 89 |
+
- "What is the difference between civil and criminal law?"
|
| 90 |
+
- "Explain contract law basics"
|
| 91 |
+
- "What are my rights in this situation?"
|
| 92 |
+
|
| 93 |
+
### 3. π Document Validator
|
| 94 |
+
**Purpose**: Analyze legal documents
|
| 95 |
+
|
| 96 |
+
**System Prompt**:
|
| 97 |
+
- Checks for completeness
|
| 98 |
+
- Verifies legal terminology
|
| 99 |
+
- Identifies structural issues
|
| 100 |
+
- Flags potential problems
|
| 101 |
+
|
| 102 |
+
**Example Questions**:
|
| 103 |
+
- "Can you validate this contract?"
|
| 104 |
+
- "Is this document complete?"
|
| 105 |
+
- "Check this agreement for issues"
|
| 106 |
+
|
| 107 |
+
### 4. π Legal Research
|
| 108 |
+
**Purpose**: Research assistance
|
| 109 |
+
|
| 110 |
+
**System Prompt**:
|
| 111 |
+
- Find relevant case law
|
| 112 |
+
- Explain statutes and regulations
|
| 113 |
+
- Research legal principles
|
| 114 |
+
- Provide citations
|
| 115 |
+
|
| 116 |
+
**Example Questions**:
|
| 117 |
+
- "Find cases about contract disputes"
|
| 118 |
+
- "What does this statute say?"
|
| 119 |
+
- "Research precedents for this issue"
|
| 120 |
+
|
| 121 |
+
### 5. π Etymology Expert
|
| 122 |
+
**Purpose**: Explain legal terminology
|
| 123 |
+
|
| 124 |
+
**System Prompt**:
|
| 125 |
+
- Latin and historical roots
|
| 126 |
+
- Evolution of terms
|
| 127 |
+
- Modern usage
|
| 128 |
+
- Related concepts
|
| 129 |
+
|
| 130 |
+
**Example Questions**:
|
| 131 |
+
- "What does 'habeas corpus' mean?"
|
| 132 |
+
- "Origin of 'tort'"
|
| 133 |
+
- "Explain 'per se'"
|
| 134 |
+
|
| 135 |
+
### 6. πΌ Case Management
|
| 136 |
+
**Purpose**: Help organize cases
|
| 137 |
+
|
| 138 |
+
**System Prompt**:
|
| 139 |
+
- Organize case information
|
| 140 |
+
- Track deadlines
|
| 141 |
+
- Manage documents
|
| 142 |
+
- Coordinate activities
|
| 143 |
+
|
| 144 |
+
**Example Questions**:
|
| 145 |
+
- "How should I organize my case files?"
|
| 146 |
+
- "Help me track court deadlines"
|
| 147 |
+
- "What documents do I need?"
|
| 148 |
+
|
| 149 |
+
### 7. π Regulatory Updates
|
| 150 |
+
**Purpose**: Monitor legal changes
|
| 151 |
+
|
| 152 |
+
**System Prompt**:
|
| 153 |
+
- Recent legal changes
|
| 154 |
+
- Compliance updates
|
| 155 |
+
- Legislative developments
|
| 156 |
+
- Impact analysis
|
| 157 |
+
|
| 158 |
+
**Example Questions**:
|
| 159 |
+
- "What's new in business law?"
|
| 160 |
+
- "Recent regulatory changes?"
|
| 161 |
+
- "Updates affecting my industry?"
|
| 162 |
+
|
| 163 |
+
---
|
| 164 |
+
|
| 165 |
+
## π Deployment Instructions
|
| 166 |
+
|
| 167 |
+
### Quick Deploy (Replaces Current Landing Page)
|
| 168 |
+
|
| 169 |
+
```bash
|
| 170 |
+
cd ProVerbS_LaW_mAiN_PAgE
|
| 171 |
+
|
| 172 |
+
# Backup current app
|
| 173 |
+
cp app.py app_backup.py
|
| 174 |
+
|
| 175 |
+
# Use integrated version
|
| 176 |
+
cp integrated_chatbot_app.py app.py
|
| 177 |
+
|
| 178 |
+
# Deploy to HF
|
| 179 |
+
python deploy_to_hf.py
|
| 180 |
+
```
|
| 181 |
+
|
| 182 |
+
### Deploy to New Space
|
| 183 |
+
|
| 184 |
+
1. Create new Space on HF
|
| 185 |
+
2. Upload `integrated_chatbot_app.py` as `app.py`
|
| 186 |
+
3. Upload `requirements.txt`
|
| 187 |
+
4. Build and test
|
| 188 |
+
|
| 189 |
+
---
|
| 190 |
+
|
| 191 |
+
## π― User Experience Flow
|
| 192 |
+
|
| 193 |
+
### When User Opens App:
|
| 194 |
+
|
| 195 |
+
1. **Welcome Screen**
|
| 196 |
+
- Overview of platform
|
| 197 |
+
- List of 7 AI modes
|
| 198 |
+
- Feature highlights
|
| 199 |
+
|
| 200 |
+
2. **AI Legal Chatbot Tab**
|
| 201 |
+
- Mode selector dropdown
|
| 202 |
+
- Chat interface
|
| 203 |
+
- Example questions
|
| 204 |
+
- Tips for best results
|
| 205 |
+
|
| 206 |
+
3. **Mode Selection**
|
| 207 |
+
- User picks specialized mode
|
| 208 |
+
- System prompt updates
|
| 209 |
+
- Chat context maintained
|
| 210 |
+
|
| 211 |
+
4. **Conversation**
|
| 212 |
+
- Mode-specific responses
|
| 213 |
+
- Contextual follow-ups
|
| 214 |
+
- Professional formatting
|
| 215 |
+
|
| 216 |
+
---
|
| 217 |
+
|
| 218 |
+
## π§ Customization Options
|
| 219 |
+
|
| 220 |
+
### Add More Modes
|
| 221 |
+
|
| 222 |
+
Edit `integrated_chatbot_app.py` line 17:
|
| 223 |
+
|
| 224 |
+
```python
|
| 225 |
+
self.specialized_modes = {
|
| 226 |
+
"your_new_mode": "Your Mode Description",
|
| 227 |
+
# ... existing modes
|
| 228 |
+
}
|
| 229 |
+
```
|
| 230 |
+
|
| 231 |
+
Then add system prompt at line 35:
|
| 232 |
+
|
| 233 |
+
```python
|
| 234 |
+
def get_mode_system_prompt(self, mode: str) -> str:
|
| 235 |
+
prompts = {
|
| 236 |
+
"your_new_mode": "Your system prompt here...",
|
| 237 |
+
# ... existing prompts
|
| 238 |
+
}
|
| 239 |
+
```
|
| 240 |
+
|
| 241 |
+
### Change Mode Icons
|
| 242 |
+
|
| 243 |
+
Edit line 289:
|
| 244 |
+
|
| 245 |
+
```python
|
| 246 |
+
choices=list({
|
| 247 |
+
"navigation": "π Your Icon - Description",
|
| 248 |
+
# ... other modes
|
| 249 |
+
}.items())
|
| 250 |
+
```
|
| 251 |
+
|
| 252 |
+
### Modify UI Colors
|
| 253 |
+
|
| 254 |
+
Edit custom CSS at line 165:
|
| 255 |
+
|
| 256 |
+
```python
|
| 257 |
+
background: linear-gradient(135deg, #your-color 0%, #your-color 100%);
|
| 258 |
+
```
|
| 259 |
+
|
| 260 |
+
---
|
| 261 |
+
|
| 262 |
+
## π Comparison: Original vs Integrated
|
| 263 |
+
|
| 264 |
+
| Feature | Original Chatbot | Integrated Version |
|
| 265 |
+
|---------|------------------|-------------------|
|
| 266 |
+
| Platform | Streamlit | Gradio |
|
| 267 |
+
| Modes | 7 specialized | 7 specialized β
|
|
| 268 |
+
| UI | Streamlit widgets | Gradio interface |
|
| 269 |
+
| Deployment | Local/Streamlit Cloud | Hugging Face Spaces |
|
| 270 |
+
| Authentication | Built-in | HF OAuth |
|
| 271 |
+
| Streaming | Yes | Yes β
|
|
| 272 |
+
| Mobile | Responsive | Responsive β
|
|
| 273 |
+
| Integration | Standalone | Landing page tabs |
|
| 274 |
+
|
| 275 |
+
---
|
| 276 |
+
|
| 277 |
+
## π‘ Pro Tips
|
| 278 |
+
|
| 279 |
+
1. **Mode Selection**: Default mode is "Navigation" to help new users
|
| 280 |
+
2. **Example Questions**: Each mode has relevant examples
|
| 281 |
+
3. **System Prompts**: Highly specialized for each mode
|
| 282 |
+
4. **Context**: Maintains conversation context within mode
|
| 283 |
+
5. **Switching Modes**: Users can change modes mid-conversation
|
| 284 |
+
|
| 285 |
+
---
|
| 286 |
+
|
| 287 |
+
## π§ͺ Testing Checklist
|
| 288 |
+
|
| 289 |
+
Before deploying:
|
| 290 |
+
|
| 291 |
+
- [ ] Test all 7 modes
|
| 292 |
+
- [ ] Verify mode-specific responses
|
| 293 |
+
- [ ] Check example questions work
|
| 294 |
+
- [ ] Test mode switching
|
| 295 |
+
- [ ] Verify mobile responsiveness
|
| 296 |
+
- [ ] Test HF OAuth login
|
| 297 |
+
- [ ] Check streaming responses
|
| 298 |
+
- [ ] Test with long conversations
|
| 299 |
+
|
| 300 |
+
---
|
| 301 |
+
|
| 302 |
+
## π± Mobile Experience
|
| 303 |
+
|
| 304 |
+
The integrated chatbot is fully mobile-responsive:
|
| 305 |
+
- Large touch-friendly mode selector
|
| 306 |
+
- Optimized chat interface
|
| 307 |
+
- Easy-to-read messages
|
| 308 |
+
- Smooth scrolling
|
| 309 |
+
|
| 310 |
+
---
|
| 311 |
+
|
| 312 |
+
## π Ready to Deploy!
|
| 313 |
+
|
| 314 |
+
Your AI Legal Chatbot is now integrated into a beautiful Gradio landing page with all 7 specialized modes!
|
| 315 |
+
|
| 316 |
+
**Next Steps:**
|
| 317 |
+
1. Review `integrated_chatbot_app.py`
|
| 318 |
+
2. Test locally (optional): `python integrated_chatbot_app.py`
|
| 319 |
+
3. Deploy to your HF Space
|
| 320 |
+
4. Share with users!
|
| 321 |
+
|
| 322 |
+
---
|
| 323 |
+
|
| 324 |
+
**Questions? Check the main deployment guide or ask for help!**
|
DEPLOY_INTEGRATED_CHATBOT.bat
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@echo off
|
| 2 |
+
REM Deploy Integrated AI Legal Chatbot to Hugging Face
|
| 3 |
+
color 0A
|
| 4 |
+
|
| 5 |
+
echo.
|
| 6 |
+
echo ============================================================
|
| 7 |
+
echo Deploy AI Legal Chatbot Integration
|
| 8 |
+
echo ============================================================
|
| 9 |
+
echo.
|
| 10 |
+
|
| 11 |
+
echo [*] This will deploy your chatbot with 7 specialized modes:
|
| 12 |
+
echo.
|
| 13 |
+
echo 1. Navigation Guide
|
| 14 |
+
echo 2. General Legal Assistant
|
| 15 |
+
echo 3. Document Validator
|
| 16 |
+
echo 4. Legal Research
|
| 17 |
+
echo 5. Etymology Expert
|
| 18 |
+
echo 6. Case Management
|
| 19 |
+
echo 7. Regulatory Updates
|
| 20 |
+
echo.
|
| 21 |
+
|
| 22 |
+
set /p confirm="Continue with deployment? (Y/N): "
|
| 23 |
+
if /i not "%confirm%"=="Y" (
|
| 24 |
+
echo.
|
| 25 |
+
echo [X] Deployment cancelled
|
| 26 |
+
pause
|
| 27 |
+
exit /b 0
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
echo.
|
| 31 |
+
echo [*] Backing up current app.py...
|
| 32 |
+
if exist app.py (
|
| 33 |
+
copy app.py app_backup_%date:~-4,4%%date:~-7,2%%date:~-10,2%.py >nul
|
| 34 |
+
echo [OK] Backup created
|
| 35 |
+
) else (
|
| 36 |
+
echo [!] No existing app.py found
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
echo.
|
| 40 |
+
echo [*] Deploying integrated chatbot version...
|
| 41 |
+
copy integrated_chatbot_app.py app.py >nul
|
| 42 |
+
echo [OK] integrated_chatbot_app.py copied to app.py
|
| 43 |
+
|
| 44 |
+
echo.
|
| 45 |
+
echo [*] Starting deployment to Hugging Face...
|
| 46 |
+
python deploy_to_hf.py
|
| 47 |
+
|
| 48 |
+
echo.
|
| 49 |
+
echo ============================================================
|
| 50 |
+
echo Deployment Complete!
|
| 51 |
+
echo ============================================================
|
| 52 |
+
echo.
|
| 53 |
+
echo Your chatbot with 7 specialized modes is now live!
|
| 54 |
+
echo Visit: https://huggingface.co/spaces/Solomon7890/ProVerbS_LaW_mAiN_PAgE
|
| 55 |
+
echo.
|
| 56 |
+
pause
|
DEPLOY_NOW.bat
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@echo off
|
| 2 |
+
REM Quick Deploy Script for ProVerBs Landing Page
|
| 3 |
+
REM Deploys to Solomon7890/ProVerbS_LaW_mAiN_PAgE
|
| 4 |
+
|
| 5 |
+
color 0A
|
| 6 |
+
echo.
|
| 7 |
+
echo ============================================================
|
| 8 |
+
echo ProVerBs Legal AI - Quick Deploy to Hugging Face
|
| 9 |
+
echo ============================================================
|
| 10 |
+
echo.
|
| 11 |
+
|
| 12 |
+
REM Check Python
|
| 13 |
+
python --version >nul 2>&1
|
| 14 |
+
if errorlevel 1 (
|
| 15 |
+
echo [ERROR] Python is not installed or not in PATH
|
| 16 |
+
echo Please install Python from https://python.org
|
| 17 |
+
pause
|
| 18 |
+
exit /b 1
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
echo [OK] Python found
|
| 22 |
+
echo.
|
| 23 |
+
|
| 24 |
+
REM Check if logged in to HF
|
| 25 |
+
echo [*] Checking Hugging Face authentication...
|
| 26 |
+
huggingface-cli whoami >nul 2>&1
|
| 27 |
+
if errorlevel 1 (
|
| 28 |
+
echo [!] Not logged in to Hugging Face
|
| 29 |
+
echo.
|
| 30 |
+
echo Please login first:
|
| 31 |
+
echo 1. Get token from: https://huggingface.co/settings/tokens
|
| 32 |
+
echo 2. Run: huggingface-cli login
|
| 33 |
+
echo 3. Run this script again
|
| 34 |
+
echo.
|
| 35 |
+
pause
|
| 36 |
+
exit /b 1
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
echo [OK] Logged in to Hugging Face
|
| 40 |
+
echo.
|
| 41 |
+
|
| 42 |
+
REM Confirm deployment
|
| 43 |
+
echo ============================================================
|
| 44 |
+
echo Target Space: Solomon7890/ProVerbS_LaW_mAiN_PAgE
|
| 45 |
+
echo URL: https://huggingface.co/spaces/Solomon7890/ProVerbS_LaW_mAiN_PAgE
|
| 46 |
+
echo ============================================================
|
| 47 |
+
echo.
|
| 48 |
+
set /p confirm="Deploy enhanced landing page now? (Y/N): "
|
| 49 |
+
if /i not "%confirm%"=="Y" (
|
| 50 |
+
echo.
|
| 51 |
+
echo [X] Deployment cancelled
|
| 52 |
+
pause
|
| 53 |
+
exit /b 0
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
echo.
|
| 57 |
+
echo [*] Starting deployment...
|
| 58 |
+
echo.
|
| 59 |
+
|
| 60 |
+
REM Run deployment script
|
| 61 |
+
python deploy_to_hf.py
|
| 62 |
+
|
| 63 |
+
echo.
|
| 64 |
+
echo ============================================================
|
| 65 |
+
echo Deployment Complete!
|
| 66 |
+
echo ============================================================
|
| 67 |
+
echo.
|
| 68 |
+
pause
|
DEPLOY_WITH_LOGOS.bat
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@echo off
|
| 2 |
+
REM Deploy AI Legal Chatbot with Rotating Logos
|
| 3 |
+
color 0A
|
| 4 |
+
|
| 5 |
+
echo.
|
| 6 |
+
echo ============================================================
|
| 7 |
+
echo Deploy ProVerBs with Rotating Logos
|
| 8 |
+
echo ============================================================
|
| 9 |
+
echo.
|
| 10 |
+
|
| 11 |
+
echo [*] Your deployment includes:
|
| 12 |
+
echo - 7 Specialized AI Modes
|
| 13 |
+
echo - 3 Rotating Logos (60 sec rotation)
|
| 14 |
+
echo - Professional Header Design
|
| 15 |
+
echo - Complete Landing Page
|
| 16 |
+
echo.
|
| 17 |
+
|
| 18 |
+
REM Check for assets folder
|
| 19 |
+
if not exist "assets\" (
|
| 20 |
+
echo [ERROR] Assets folder not found!
|
| 21 |
+
echo Please ensure assets folder with logos exists.
|
| 22 |
+
pause
|
| 23 |
+
exit /b 1
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
echo [OK] Assets folder found with logos
|
| 27 |
+
echo.
|
| 28 |
+
|
| 29 |
+
REM Check for logo files
|
| 30 |
+
set "missing=0"
|
| 31 |
+
if not exist "assets\logo_1.jpg" (
|
| 32 |
+
echo [!] logo_1.jpg missing
|
| 33 |
+
set "missing=1"
|
| 34 |
+
)
|
| 35 |
+
if not exist "assets\logo_2.jpg" (
|
| 36 |
+
echo [!] logo_2.jpg missing
|
| 37 |
+
set "missing=1"
|
| 38 |
+
)
|
| 39 |
+
if not exist "assets\logo_3.jpg" (
|
| 40 |
+
echo [!] logo_3.jpg missing
|
| 41 |
+
set "missing=1"
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
if "%missing%"=="1" (
|
| 45 |
+
echo [ERROR] Some logo files are missing!
|
| 46 |
+
pause
|
| 47 |
+
exit /b 1
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
echo [OK] All 3 rotating logos found
|
| 51 |
+
echo.
|
| 52 |
+
|
| 53 |
+
set /p confirm="Deploy with rotating logos? (Y/N): "
|
| 54 |
+
if /i not "%confirm%"=="Y" (
|
| 55 |
+
echo.
|
| 56 |
+
echo [X] Deployment cancelled
|
| 57 |
+
pause
|
| 58 |
+
exit /b 0
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
echo.
|
| 62 |
+
echo [*] Backing up current app.py...
|
| 63 |
+
if exist app.py (
|
| 64 |
+
copy app.py app_backup_%date:~-4,4%%date:~-7,2%%date:~-10,2%.py >nul
|
| 65 |
+
echo [OK] Backup created
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
echo.
|
| 69 |
+
echo [*] Deploying version with rotating logos...
|
| 70 |
+
copy integrated_chatbot_with_logos.py app.py >nul
|
| 71 |
+
echo [OK] App file ready
|
| 72 |
+
|
| 73 |
+
echo.
|
| 74 |
+
echo [*] Starting deployment to Hugging Face...
|
| 75 |
+
echo [*] This will upload app.py AND assets folder
|
| 76 |
+
echo.
|
| 77 |
+
|
| 78 |
+
python deploy_to_hf.py
|
| 79 |
+
|
| 80 |
+
echo.
|
| 81 |
+
echo ============================================================
|
| 82 |
+
echo Deployment Complete!
|
| 83 |
+
echo ============================================================
|
| 84 |
+
echo.
|
| 85 |
+
echo Your Space with rotating logos is now live!
|
| 86 |
+
echo Visit: https://huggingface.co/spaces/Solomon7890/ProVerbS_LaW_mAiN_PAgE
|
| 87 |
+
echo.
|
| 88 |
+
echo NOTE: Wait 60 seconds to see the logos rotate!
|
| 89 |
+
echo.
|
| 90 |
+
pause
|
LOCAL_PREVIEW_GUIDE.md
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# πΊ Local Preview Guide - Test Before Deploy
|
| 2 |
+
|
| 3 |
+
## β
Your Rule: ALWAYS Preview Locally First!
|
| 4 |
+
|
| 5 |
+
Before any deployment to Hugging Face, you MUST preview locally to ensure everything works perfectly.
|
| 6 |
+
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
## π Quick Preview (One-Click)
|
| 10 |
+
|
| 11 |
+
### Windows:
|
| 12 |
+
```
|
| 13 |
+
Double-click: PREVIEW_LOCALLY.bat
|
| 14 |
+
```
|
| 15 |
+
|
| 16 |
+
This will:
|
| 17 |
+
1. β
Check that Python is installed
|
| 18 |
+
2. β
Verify all required files exist
|
| 19 |
+
3. β
Start local server at http://localhost:7860
|
| 20 |
+
4. β
Open in your browser automatically
|
| 21 |
+
|
| 22 |
+
---
|
| 23 |
+
|
| 24 |
+
## π― Complete Workflow (Preview + Deploy)
|
| 25 |
+
|
| 26 |
+
### Windows:
|
| 27 |
+
```
|
| 28 |
+
Double-click: PREVIEW_THEN_DEPLOY.bat
|
| 29 |
+
```
|
| 30 |
+
|
| 31 |
+
This will:
|
| 32 |
+
1. **STEP 1**: Start local preview
|
| 33 |
+
2. Let you test everything
|
| 34 |
+
3. **STEP 2**: Ask if you want to deploy
|
| 35 |
+
4. Only deploy after you confirm
|
| 36 |
+
|
| 37 |
+
---
|
| 38 |
+
|
| 39 |
+
## π Local Preview Checklist
|
| 40 |
+
|
| 41 |
+
When previewing locally, check these items:
|
| 42 |
+
|
| 43 |
+
### Visual Checks:
|
| 44 |
+
- [ ] Header displays correctly
|
| 45 |
+
- [ ] Logo 1 appears initially
|
| 46 |
+
- [ ] After 60 seconds, Logo 2 appears
|
| 47 |
+
- [ ] After 120 seconds, Logo 3 appears
|
| 48 |
+
- [ ] Logos are circular with border
|
| 49 |
+
- [ ] Fade transition is smooth
|
| 50 |
+
|
| 51 |
+
### Functionality Checks:
|
| 52 |
+
- [ ] All 4 tabs are clickable
|
| 53 |
+
- [ ] Welcome tab displays correctly
|
| 54 |
+
- [ ] AI Chatbot tab loads
|
| 55 |
+
- [ ] Mode selector dropdown works
|
| 56 |
+
- [ ] Chat interface accepts input
|
| 57 |
+
- [ ] Features tab displays
|
| 58 |
+
- [ ] About tab displays
|
| 59 |
+
|
| 60 |
+
### AI Mode Checks:
|
| 61 |
+
Test each mode with a sample question:
|
| 62 |
+
- [ ] π Navigation Guide mode
|
| 63 |
+
- [ ] π¬ General Legal Assistant mode
|
| 64 |
+
- [ ] π Document Validator mode
|
| 65 |
+
- [ ] π Legal Research mode
|
| 66 |
+
- [ ] π Etymology Expert mode
|
| 67 |
+
- [ ] πΌ Case Management mode
|
| 68 |
+
- [ ] π Regulatory Updates mode
|
| 69 |
+
|
| 70 |
+
### Responsive Design:
|
| 71 |
+
- [ ] Resize browser window (mobile view)
|
| 72 |
+
- [ ] Check that layout adjusts
|
| 73 |
+
- [ ] Test on different browsers
|
| 74 |
+
|
| 75 |
+
---
|
| 76 |
+
|
| 77 |
+
## π₯οΈ Command Line Preview
|
| 78 |
+
|
| 79 |
+
### Start Preview:
|
| 80 |
+
```bash
|
| 81 |
+
cd ProVerbS_LaW_mAiN_PAgE
|
| 82 |
+
python integrated_chatbot_with_logos.py
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
### Stop Preview:
|
| 86 |
+
Press `Ctrl+C` in the terminal
|
| 87 |
+
|
| 88 |
+
### Manual Open in Browser:
|
| 89 |
+
Visit: `http://localhost:7860`
|
| 90 |
+
|
| 91 |
+
---
|
| 92 |
+
|
| 93 |
+
## β±οΈ How Long to Preview
|
| 94 |
+
|
| 95 |
+
### Minimum Time: **2-3 minutes**
|
| 96 |
+
- Navigate through all tabs (30 sec)
|
| 97 |
+
- Test one AI mode (1 min)
|
| 98 |
+
- Wait for logo rotation (60+ sec)
|
| 99 |
+
- Quick responsive check (30 sec)
|
| 100 |
+
|
| 101 |
+
### Recommended Time: **5 minutes**
|
| 102 |
+
- Test all 7 AI modes (3 min)
|
| 103 |
+
- Watch full logo rotation cycle (2 min)
|
| 104 |
+
- Check on different screen sizes
|
| 105 |
+
|
| 106 |
+
### Thorough Testing: **10 minutes**
|
| 107 |
+
- Test all features extensively
|
| 108 |
+
- Multiple logo rotation cycles
|
| 109 |
+
- Test different browsers
|
| 110 |
+
- Test all AI modes with various questions
|
| 111 |
+
|
| 112 |
+
---
|
| 113 |
+
|
| 114 |
+
## π§ Troubleshooting Local Preview
|
| 115 |
+
|
| 116 |
+
### Issue: Server won't start
|
| 117 |
+
|
| 118 |
+
**Check 1**: Python installed?
|
| 119 |
+
```bash
|
| 120 |
+
python --version
|
| 121 |
+
```
|
| 122 |
+
|
| 123 |
+
**Check 2**: In correct folder?
|
| 124 |
+
```bash
|
| 125 |
+
cd ProVerbS_LaW_mAiN_PAgE
|
| 126 |
+
```
|
| 127 |
+
|
| 128 |
+
**Check 3**: File exists?
|
| 129 |
+
```bash
|
| 130 |
+
dir integrated_chatbot_with_logos.py
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
+
### Issue: Logos don't display
|
| 134 |
+
|
| 135 |
+
**Solution**: Check assets folder exists
|
| 136 |
+
```bash
|
| 137 |
+
dir assets
|
| 138 |
+
```
|
| 139 |
+
|
| 140 |
+
Should show:
|
| 141 |
+
- logo_1.jpg
|
| 142 |
+
- logo_2.jpg
|
| 143 |
+
- logo_3.jpg
|
| 144 |
+
- logo_main.jpg
|
| 145 |
+
|
| 146 |
+
### Issue: Logos don't rotate
|
| 147 |
+
|
| 148 |
+
**Solution**: Wait full 60 seconds
|
| 149 |
+
- Logo changes happen exactly at 60-second intervals
|
| 150 |
+
- Be patient and watch the timer
|
| 151 |
+
|
| 152 |
+
### Issue: AI doesn't respond
|
| 153 |
+
|
| 154 |
+
**Solution**: Need Hugging Face token
|
| 155 |
+
- Login required for AI inference
|
| 156 |
+
- Or test the UI/layout only
|
| 157 |
+
|
| 158 |
+
### Issue: Port already in use
|
| 159 |
+
|
| 160 |
+
**Solution**: Change port
|
| 161 |
+
Edit `integrated_chatbot_with_logos.py` line 595:
|
| 162 |
+
```python
|
| 163 |
+
server_port=7861, # Changed from 7860
|
| 164 |
+
```
|
| 165 |
+
|
| 166 |
+
---
|
| 167 |
+
|
| 168 |
+
## π What to Look For
|
| 169 |
+
|
| 170 |
+
### β
Good Signs:
|
| 171 |
+
- Logos display clearly
|
| 172 |
+
- Logos rotate smoothly
|
| 173 |
+
- Chat interface is responsive
|
| 174 |
+
- All tabs work
|
| 175 |
+
- Mode selector changes modes
|
| 176 |
+
- Layout looks professional
|
| 177 |
+
|
| 178 |
+
### β Warning Signs:
|
| 179 |
+
- Logos don't appear
|
| 180 |
+
- Logos are stretched/distorted
|
| 181 |
+
- Chat doesn't respond (expected without HF token locally)
|
| 182 |
+
- Tabs don't switch
|
| 183 |
+
- Layout is broken
|
| 184 |
+
- Mobile view is cramped
|
| 185 |
+
|
| 186 |
+
---
|
| 187 |
+
|
| 188 |
+
## π¨ Testing Logo Rotation
|
| 189 |
+
|
| 190 |
+
### Method 1: Watch in Real-Time
|
| 191 |
+
1. Start preview
|
| 192 |
+
2. Note the current time
|
| 193 |
+
3. At 0:00 - Logo 1 should display
|
| 194 |
+
4. At 1:00 - Logo 2 should fade in
|
| 195 |
+
5. At 2:00 - Logo 3 should fade in
|
| 196 |
+
6. At 3:00 - Logo 1 returns
|
| 197 |
+
|
| 198 |
+
### Method 2: Use Browser DevTools
|
| 199 |
+
1. Right-click on logo β Inspect
|
| 200 |
+
2. Watch CSS classes change
|
| 201 |
+
3. See `display: block` / `display: none` toggle
|
| 202 |
+
|
| 203 |
+
### Method 3: Speed Up (For Testing)
|
| 204 |
+
Temporarily edit the rotation speed:
|
| 205 |
+
|
| 206 |
+
In `integrated_chatbot_with_logos.py` line 298:
|
| 207 |
+
```javascript
|
| 208 |
+
// Change from 60000 (60 sec) to 10000 (10 sec) for testing
|
| 209 |
+
setInterval(showNextLogo, 10000);
|
| 210 |
+
```
|
| 211 |
+
|
| 212 |
+
**Remember to change it back before deploying!**
|
| 213 |
+
|
| 214 |
+
---
|
| 215 |
+
|
| 216 |
+
## π Preview vs Live Deployment
|
| 217 |
+
|
| 218 |
+
| Feature | Local Preview | Live Deployment |
|
| 219 |
+
|---------|---------------|-----------------|
|
| 220 |
+
| **Logos** | β
Display | β
Display |
|
| 221 |
+
| **Rotation** | β
Works | β
Works |
|
| 222 |
+
| **Layout** | β
Same | β
Same |
|
| 223 |
+
| **Tabs** | β
Work | β
Work |
|
| 224 |
+
| **AI Chat** | β οΈ Need token | β
HF OAuth |
|
| 225 |
+
| **Speed** | β‘ Instant | β³ 2-3 min build |
|
| 226 |
+
| **URL** | localhost:7860 | HF Space URL |
|
| 227 |
+
|
| 228 |
+
---
|
| 229 |
+
|
| 230 |
+
## π Preview Approval Checklist
|
| 231 |
+
|
| 232 |
+
Before you deploy, confirm all these are β
:
|
| 233 |
+
|
| 234 |
+
### Must-Have (Critical):
|
| 235 |
+
- [ ] All logos display
|
| 236 |
+
- [ ] Logos rotate every 60 seconds
|
| 237 |
+
- [ ] All 4 tabs are accessible
|
| 238 |
+
- [ ] Layout looks professional
|
| 239 |
+
- [ ] No obvious visual bugs
|
| 240 |
+
|
| 241 |
+
### Should-Have (Important):
|
| 242 |
+
- [ ] Mode selector works
|
| 243 |
+
- [ ] Chat interface loads
|
| 244 |
+
- [ ] Mobile view looks good
|
| 245 |
+
- [ ] All text is readable
|
| 246 |
+
- [ ] Colors look correct
|
| 247 |
+
|
| 248 |
+
### Nice-to-Have (Optional):
|
| 249 |
+
- [ ] Tested all 7 AI modes
|
| 250 |
+
- [ ] Checked multiple browsers
|
| 251 |
+
- [ ] Tested on actual mobile device
|
| 252 |
+
- [ ] Full 3-minute rotation cycle observed
|
| 253 |
+
|
| 254 |
+
---
|
| 255 |
+
|
| 256 |
+
## π After Approval
|
| 257 |
+
|
| 258 |
+
Once everything looks good in preview:
|
| 259 |
+
|
| 260 |
+
### Option 1: Use PREVIEW_THEN_DEPLOY.bat
|
| 261 |
+
- Already running? Just confirm "Yes" when asked
|
| 262 |
+
- It will automatically proceed to deployment
|
| 263 |
+
|
| 264 |
+
### Option 2: Manual Deploy
|
| 265 |
+
```bash
|
| 266 |
+
# Stop preview (Ctrl+C)
|
| 267 |
+
cp integrated_chatbot_with_logos.py app.py
|
| 268 |
+
python deploy_to_hf.py
|
| 269 |
+
```
|
| 270 |
+
|
| 271 |
+
### Option 3: Use DEPLOY_WITH_LOGOS.bat
|
| 272 |
+
```bash
|
| 273 |
+
# Stop preview (Ctrl+C)
|
| 274 |
+
# Then run:
|
| 275 |
+
DEPLOY_WITH_LOGOS.bat
|
| 276 |
+
```
|
| 277 |
+
|
| 278 |
+
---
|
| 279 |
+
|
| 280 |
+
## π‘ Pro Tips
|
| 281 |
+
|
| 282 |
+
1. **Test Logo Rotation First**: This is your unique feature - make sure it works!
|
| 283 |
+
2. **Use Stopwatch**: Time the 60-second intervals precisely
|
| 284 |
+
3. **Check Assets**: Before starting, verify all logo files exist
|
| 285 |
+
4. **Multiple Browsers**: Test in Chrome, Firefox, Edge if possible
|
| 286 |
+
5. **Take Screenshots**: Capture what works well for reference
|
| 287 |
+
6. **Note Issues**: Write down anything that needs fixing
|
| 288 |
+
7. **Test Mobile**: Resize browser window to mobile size
|
| 289 |
+
8. **Fresh Eyes**: If possible, show someone else for feedback
|
| 290 |
+
|
| 291 |
+
---
|
| 292 |
+
|
| 293 |
+
## π― Preview Workflow Summary
|
| 294 |
+
|
| 295 |
+
```
|
| 296 |
+
1. Run PREVIEW_LOCALLY.bat (or PREVIEW_THEN_DEPLOY.bat)
|
| 297 |
+
β
|
| 298 |
+
2. App opens at http://localhost:7860
|
| 299 |
+
β
|
| 300 |
+
3. Check all items on checklist (2-10 minutes)
|
| 301 |
+
β
|
| 302 |
+
4. Watch logos rotate (minimum 60+ seconds)
|
| 303 |
+
β
|
| 304 |
+
5. Test all features and tabs
|
| 305 |
+
β
|
| 306 |
+
6. If everything looks good β Approve for deployment
|
| 307 |
+
β
|
| 308 |
+
7. If issues found β Fix them and preview again
|
| 309 |
+
β
|
| 310 |
+
8. Once approved β Deploy to Hugging Face
|
| 311 |
+
β
|
| 312 |
+
9. Wait 2-3 minutes for live build
|
| 313 |
+
β
|
| 314 |
+
10. Visit live Space and verify again
|
| 315 |
+
```
|
| 316 |
+
|
| 317 |
+
---
|
| 318 |
+
|
| 319 |
+
## β οΈ Important Reminders
|
| 320 |
+
|
| 321 |
+
1. **NEVER deploy without previewing first**
|
| 322 |
+
2. **ALWAYS watch at least one logo rotation (60+ sec)**
|
| 323 |
+
3. **CHECK the assets folder exists before starting**
|
| 324 |
+
4. **TEST on mobile view by resizing browser**
|
| 325 |
+
5. **STOP the server (Ctrl+C) before deploying**
|
| 326 |
+
|
| 327 |
+
---
|
| 328 |
+
|
| 329 |
+
## β
Ready to Preview?
|
| 330 |
+
|
| 331 |
+
Run one of these:
|
| 332 |
+
|
| 333 |
+
### Quick Preview:
|
| 334 |
+
```
|
| 335 |
+
Double-click: PREVIEW_LOCALLY.bat
|
| 336 |
+
```
|
| 337 |
+
|
| 338 |
+
### Preview + Deploy Workflow:
|
| 339 |
+
```
|
| 340 |
+
Double-click: PREVIEW_THEN_DEPLOY.bat
|
| 341 |
+
```
|
| 342 |
+
|
| 343 |
+
### Manual:
|
| 344 |
+
```bash
|
| 345 |
+
cd ProVerbS_LaW_mAiN_PAgE
|
| 346 |
+
python integrated_chatbot_with_logos.py
|
| 347 |
+
```
|
| 348 |
+
|
| 349 |
+
---
|
| 350 |
+
|
| 351 |
+
**Your Rule**: **ALWAYS preview locally before ANY deployment!** β
|
| 352 |
+
|
| 353 |
+
**This ensures**: Everything works perfectly before going live! π
|
LOGO_DEPLOYMENT_GUIDE.md
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# π¨ Logo Integration Guide - Rotating Logos
|
| 2 |
+
|
| 3 |
+
## β
What's Been Done
|
| 4 |
+
|
| 5 |
+
### Logos Copied
|
| 6 |
+
I've copied your images to the project:
|
| 7 |
+
|
| 8 |
+
```
|
| 9 |
+
ProVerbS_LaW_mAiN_PAgE/assets/
|
| 10 |
+
βββ logo_main.jpg (128.21 KB) - Main/fallback logo
|
| 11 |
+
βββ logo_1.jpg (90.95 KB) - Rotating logo 1
|
| 12 |
+
βββ logo_2.jpg (60.84 KB) - Rotating logo 2
|
| 13 |
+
βββ logo_3.jpg (70.82 KB) - Rotating logo 3
|
| 14 |
+
```
|
| 15 |
+
|
| 16 |
+
### Features Added
|
| 17 |
+
β
**Rotating Logo System** - Logos change every 60 seconds
|
| 18 |
+
β
**Professional Styling** - Circular design with border and shadow
|
| 19 |
+
β
**Smooth Transitions** - Fade in/out animation
|
| 20 |
+
β
**Responsive Design** - Works on all devices
|
| 21 |
+
|
| 22 |
+
---
|
| 23 |
+
|
| 24 |
+
## π― How It Works
|
| 25 |
+
|
| 26 |
+
### Rotation Cycle (60 seconds each)
|
| 27 |
+
```
|
| 28 |
+
0-60 sec: Logo 1 displays
|
| 29 |
+
60-120 sec: Logo 2 displays
|
| 30 |
+
120-180 sec: Logo 3 displays
|
| 31 |
+
Then repeats...
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
### Animation Details
|
| 35 |
+
- **Fade Duration**: Smooth 2-second fade between logos
|
| 36 |
+
- **Logo Size**: 150x150 pixels (circular)
|
| 37 |
+
- **Border**: 4px white border with shadow
|
| 38 |
+
- **Position**: Centered in header above title
|
| 39 |
+
|
| 40 |
+
---
|
| 41 |
+
|
| 42 |
+
## π Deployment Options
|
| 43 |
+
|
| 44 |
+
### Option 1: Deploy with Rotating Logos (Recommended) β
|
| 45 |
+
|
| 46 |
+
```bash
|
| 47 |
+
cd ProVerbS_LaW_mAiN_PAgE
|
| 48 |
+
|
| 49 |
+
# Use the version with logos
|
| 50 |
+
cp integrated_chatbot_with_logos.py app.py
|
| 51 |
+
|
| 52 |
+
# Deploy
|
| 53 |
+
python deploy_to_hf.py
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
**Important**: The `assets` folder with logos will be deployed automatically!
|
| 57 |
+
|
| 58 |
+
### Option 2: Test Locally First
|
| 59 |
+
|
| 60 |
+
```bash
|
| 61 |
+
cd ProVerbS_LaW_mAiN_PAgE
|
| 62 |
+
|
| 63 |
+
# Run locally to see the rotating logos
|
| 64 |
+
python integrated_chatbot_with_logos.py
|
| 65 |
+
|
| 66 |
+
# Visit: http://localhost:7860
|
| 67 |
+
# Watch the logos rotate every 60 seconds!
|
| 68 |
+
```
|
| 69 |
+
|
| 70 |
+
### Option 3: Windows One-Click
|
| 71 |
+
|
| 72 |
+
Create a new batch file or use existing one:
|
| 73 |
+
```bash
|
| 74 |
+
cd ProVerbS_LaW_mAiN_PAgE
|
| 75 |
+
cp integrated_chatbot_with_logos.py app.py
|
| 76 |
+
DEPLOY_NOW.bat
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
---
|
| 80 |
+
|
| 81 |
+
## π File Structure for Deployment
|
| 82 |
+
|
| 83 |
+
When you deploy, make sure these files are included:
|
| 84 |
+
|
| 85 |
+
```
|
| 86 |
+
ProVerbS_LaW_mAiN_PAgE/
|
| 87 |
+
βββ app.py (or integrated_chatbot_with_logos.py renamed)
|
| 88 |
+
βββ README.md
|
| 89 |
+
βββ requirements.txt (if you have one)
|
| 90 |
+
βββ assets/
|
| 91 |
+
βββ logo_1.jpg
|
| 92 |
+
βββ logo_2.jpg
|
| 93 |
+
βββ logo_3.jpg
|
| 94 |
+
βββ logo_main.jpg
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
---
|
| 98 |
+
|
| 99 |
+
## π¨ Customization Options
|
| 100 |
+
|
| 101 |
+
### Change Rotation Speed
|
| 102 |
+
|
| 103 |
+
Edit `integrated_chatbot_with_logos.py` line 298:
|
| 104 |
+
|
| 105 |
+
```javascript
|
| 106 |
+
// Change from 60000 (60 sec) to your desired time in milliseconds
|
| 107 |
+
setInterval(showNextLogo, 60000); // 60 seconds
|
| 108 |
+
setInterval(showNextLogo, 30000); // 30 seconds
|
| 109 |
+
setInterval(showNextLogo, 120000); // 2 minutes
|
| 110 |
+
```
|
| 111 |
+
|
| 112 |
+
### Change Logo Size
|
| 113 |
+
|
| 114 |
+
Edit CSS at line 228:
|
| 115 |
+
|
| 116 |
+
```css
|
| 117 |
+
.rotating-logo {
|
| 118 |
+
width: 150px; /* Change size */
|
| 119 |
+
height: 150px; /* Keep same as width for circle */
|
| 120 |
+
border-radius: 50%;
|
| 121 |
+
/* ... */
|
| 122 |
+
}
|
| 123 |
+
```
|
| 124 |
+
|
| 125 |
+
### Change Logo Border/Shadow
|
| 126 |
+
|
| 127 |
+
Edit CSS at line 233:
|
| 128 |
+
|
| 129 |
+
```css
|
| 130 |
+
border: 4px solid rgba(255, 255, 255, 0.8); /* Border thickness and color */
|
| 131 |
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3); /* Shadow */
|
| 132 |
+
```
|
| 133 |
+
|
| 134 |
+
### Add More Logos
|
| 135 |
+
|
| 136 |
+
1. Copy additional logo images to `assets/` folder:
|
| 137 |
+
```bash
|
| 138 |
+
copy "your_logo_4.jpg" "assets/logo_4.jpg"
|
| 139 |
+
```
|
| 140 |
+
|
| 141 |
+
2. Edit the HTML section (line 288) to add logo_4:
|
| 142 |
+
```html
|
| 143 |
+
<img src="file/assets/logo_4.jpg" class="rotating-logo logo-4" alt="ProVerBs Logo 4" style="display: none;">
|
| 144 |
+
```
|
| 145 |
+
|
| 146 |
+
3. Update JavaScript to include 4 logos in rotation
|
| 147 |
+
|
| 148 |
+
---
|
| 149 |
+
|
| 150 |
+
## π§ Troubleshooting
|
| 151 |
+
|
| 152 |
+
### Issue: Logos don't appear after deployment
|
| 153 |
+
|
| 154 |
+
**Solution 1**: Check that assets folder is uploaded
|
| 155 |
+
- Go to your Space on HF
|
| 156 |
+
- Click "Files" tab
|
| 157 |
+
- Verify `assets/` folder exists with all logos
|
| 158 |
+
|
| 159 |
+
**Solution 2**: Re-upload assets manually
|
| 160 |
+
- In HF Space, click "Files" β "Add file" β "Upload files"
|
| 161 |
+
- Upload the entire `assets` folder
|
| 162 |
+
|
| 163 |
+
### Issue: Logos don't rotate
|
| 164 |
+
|
| 165 |
+
**Solution**: Clear browser cache and refresh
|
| 166 |
+
- Press Ctrl+F5 (Windows) or Cmd+Shift+R (Mac)
|
| 167 |
+
- JavaScript may be cached
|
| 168 |
+
|
| 169 |
+
### Issue: Logos appear stretched/distorted
|
| 170 |
+
|
| 171 |
+
**Solution**: Check image aspect ratio
|
| 172 |
+
- Logos should be square (1:1 aspect ratio)
|
| 173 |
+
- Or adjust CSS to `object-fit: contain` instead of `cover`
|
| 174 |
+
|
| 175 |
+
### Issue: First logo doesn't show
|
| 176 |
+
|
| 177 |
+
**Solution**: Check that logo_1.jpg has `display: block` in HTML:
|
| 178 |
+
```html
|
| 179 |
+
<img src="file/assets/logo_1.jpg" class="rotating-logo logo-1" alt="ProVerBs Logo 1" style="display: block;">
|
| 180 |
+
```
|
| 181 |
+
|
| 182 |
+
---
|
| 183 |
+
|
| 184 |
+
## π Deployment Checklist
|
| 185 |
+
|
| 186 |
+
Before deploying:
|
| 187 |
+
- [ ] Assets folder exists in ProVerbS_LaW_mAiN_PAgE/
|
| 188 |
+
- [ ] All 4 logo files are in assets/ folder
|
| 189 |
+
- [ ] Logo files are named correctly (logo_1.jpg, logo_2.jpg, logo_3.jpg)
|
| 190 |
+
- [ ] `integrated_chatbot_with_logos.py` is ready
|
| 191 |
+
- [ ] (Optional) Tested locally first
|
| 192 |
+
|
| 193 |
+
Deploy:
|
| 194 |
+
- [ ] Copy integrated_chatbot_with_logos.py to app.py
|
| 195 |
+
- [ ] Run deployment script
|
| 196 |
+
- [ ] Include assets folder in deployment
|
| 197 |
+
|
| 198 |
+
After deployment:
|
| 199 |
+
- [ ] Check that logos display
|
| 200 |
+
- [ ] Verify rotation works (wait 60+ seconds)
|
| 201 |
+
- [ ] Test on mobile device
|
| 202 |
+
- [ ] Check different browsers
|
| 203 |
+
|
| 204 |
+
---
|
| 205 |
+
|
| 206 |
+
## π Logo Display Details
|
| 207 |
+
|
| 208 |
+
### Header Layout
|
| 209 |
+
```
|
| 210 |
+
ββββββββββββοΏ½οΏ½ββββββββββββββββββββββ
|
| 211 |
+
β β
|
| 212 |
+
β [Rotating Logo] β β 150x150px circle
|
| 213 |
+
β β
|
| 214 |
+
β βοΈ ProVerBs Legal AI Platform β
|
| 215 |
+
β β
|
| 216 |
+
β Lawful vs. Legal: Dual Analysisβ
|
| 217 |
+
β β
|
| 218 |
+
βββββββββββββββββββββββββββββββββββ
|
| 219 |
+
```
|
| 220 |
+
|
| 221 |
+
### CSS Classes Applied
|
| 222 |
+
- `.rotating-logo` - Base styling for all logos
|
| 223 |
+
- `.logo-1`, `.logo-2`, `.logo-3` - Individual logo selectors
|
| 224 |
+
- Animation delays: 0s, 20s, 40s for smooth rotation
|
| 225 |
+
|
| 226 |
+
---
|
| 227 |
+
|
| 228 |
+
## π HF Space File Paths
|
| 229 |
+
|
| 230 |
+
In your deployed Space, logos are accessed via:
|
| 231 |
+
```
|
| 232 |
+
file/assets/logo_1.jpg
|
| 233 |
+
file/assets/logo_2.jpg
|
| 234 |
+
file/assets/logo_3.jpg
|
| 235 |
+
```
|
| 236 |
+
|
| 237 |
+
This is Gradio's special file serving path for static assets.
|
| 238 |
+
|
| 239 |
+
---
|
| 240 |
+
|
| 241 |
+
## π‘ Pro Tips
|
| 242 |
+
|
| 243 |
+
1. **Image Format**: JPG is good for photos, PNG for graphics with transparency
|
| 244 |
+
2. **Image Size**: Keep under 200KB for fast loading
|
| 245 |
+
3. **Aspect Ratio**: Square images (1:1) work best for circular display
|
| 246 |
+
4. **Quality**: Use good quality but compress for web
|
| 247 |
+
5. **Testing**: Always test locally before deploying
|
| 248 |
+
|
| 249 |
+
---
|
| 250 |
+
|
| 251 |
+
## πΈ Your Logo Files
|
| 252 |
+
|
| 253 |
+
**Source Location**:
|
| 254 |
+
```
|
| 255 |
+
C:\Users\freet\OneDrive\Documents\SOLO'CODES\MODULES\New folder\
|
| 256 |
+
```
|
| 257 |
+
|
| 258 |
+
**Copied To**:
|
| 259 |
+
```
|
| 260 |
+
ProVerbS_LaW_mAiN_PAgE\assets\
|
| 261 |
+
```
|
| 262 |
+
|
| 263 |
+
**Main Logo**: 20250515_061525560_iOS.jpg β logo_main.jpg (128.21 KB)
|
| 264 |
+
|
| 265 |
+
**Rotating Logos**:
|
| 266 |
+
- 20250515_061454922_iOS.jpg β logo_1.jpg (90.95 KB)
|
| 267 |
+
- 20250515_061533625_iOS.jpg β logo_2.jpg (60.84 KB)
|
| 268 |
+
- 20250515_061538456_iOS.jpg β logo_3.jpg (70.82 KB)
|
| 269 |
+
|
| 270 |
+
---
|
| 271 |
+
|
| 272 |
+
## β
Ready to Deploy!
|
| 273 |
+
|
| 274 |
+
Your logos are integrated and ready to go!
|
| 275 |
+
|
| 276 |
+
**Quick Deploy**:
|
| 277 |
+
```bash
|
| 278 |
+
cd ProVerbS_LaW_mAiN_PAgE
|
| 279 |
+
cp integrated_chatbot_with_logos.py app.py
|
| 280 |
+
python deploy_to_hf.py
|
| 281 |
+
```
|
| 282 |
+
|
| 283 |
+
**Your rotating logos will be live at:**
|
| 284 |
+
https://huggingface.co/spaces/Solomon7890/ProVerbS_LaW_mAiN_PAgE
|
| 285 |
+
|
| 286 |
+
---
|
| 287 |
+
|
| 288 |
+
**Questions? Need to adjust the rotation speed or styling? Just ask!**
|
MULTI_AI_GUIDE.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# π€ Multi-AI Integration Guide
|
| 2 |
+
|
| 3 |
+
## β
What's Been Added
|
| 4 |
+
|
| 5 |
+
### New File: `integrated_chatbot_full_ai.py`
|
| 6 |
+
|
| 7 |
+
**The Most Advanced Version** - Combines 4 AI Models!
|
| 8 |
+
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
## π 4 AI Models Integrated
|
| 12 |
+
|
| 13 |
+
### 1. **DeepSeek-OCR**
|
| 14 |
+
- Extract text from scanned documents
|
| 15 |
+
- High-accuracy OCR
|
| 16 |
+
|
| 17 |
+
### 2. **ERNIE-4.5-VL** (Baidu) β NEW!
|
| 18 |
+
- Vision-language understanding
|
| 19 |
+
- Visual document analysis
|
| 20 |
+
- Image question answering
|
| 21 |
+
|
| 22 |
+
### 3. **OpenAI GDPVAL** β NEW!
|
| 23 |
+
- Legal knowledge dataset
|
| 24 |
+
- Case law and precedents
|
| 25 |
+
- Research capabilities
|
| 26 |
+
|
| 27 |
+
### 4. **Meta Llama 3.3**
|
| 28 |
+
- General AI assistance
|
| 29 |
+
- Natural conversation
|
| 30 |
+
|
| 31 |
+
---
|
| 32 |
+
|
| 33 |
+
## π― Enhanced Features
|
| 34 |
+
|
| 35 |
+
### Document Validator Mode:
|
| 36 |
+
**Before**: OCR text extraction only
|
| 37 |
+
**Now**:
|
| 38 |
+
- β
OCR text extraction (DeepSeek)
|
| 39 |
+
- β
Visual understanding (ERNIE-4.5-VL)
|
| 40 |
+
- β
Legal analysis (Llama)
|
| 41 |
+
|
| 42 |
+
### Legal Research Mode:
|
| 43 |
+
**Before**: AI responses only
|
| 44 |
+
**Now**:
|
| 45 |
+
- β
GDPVAL dataset search
|
| 46 |
+
- β
Knowledge base access
|
| 47 |
+
- β
Enhanced research
|
| 48 |
+
|
| 49 |
+
---
|
| 50 |
+
|
| 51 |
+
## π Version Comparison
|
| 52 |
+
|
| 53 |
+
| Version | Logos | OCR | Vision AI | GDPVAL | Best For |
|
| 54 |
+
|---------|-------|-----|-----------|--------|----------|
|
| 55 |
+
| v1.0 Basic | β
| β | β | β | Simple |
|
| 56 |
+
| v1.1 OCR | β
| β
| β | β | Documents |
|
| 57 |
+
| **v2.0 Full** | β
| β
| β
| β
| **Everything** β |
|
| 58 |
+
|
| 59 |
+
---
|
| 60 |
+
|
| 61 |
+
## π Deployment
|
| 62 |
+
|
| 63 |
+
```bash
|
| 64 |
+
cd ProVerbS_LaW_mAiN_PAgE
|
| 65 |
+
cp integrated_chatbot_full_ai.py app.py
|
| 66 |
+
python deploy_to_hf.py
|
| 67 |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
|
| 10 |
+
|
| 11 |
+
### 1. **OCR-Enhanced Document Validator**
|
| 12 |
+
- Extract text from scanned documents
|
| 13 |
+
- Process images of contracts and legal forms
|
| 14 |
+
- Automatic text recognition
|
| 15 |
+
- Legal document analysis
|
| 16 |
+
|
| 17 |
+
### 2. **New File Created**
|
| 18 |
+
**`integrated_chatbot_with_ocr.py`**
|
| 19 |
+
- All 7 AI modes
|
| 20 |
+
- Rotating logos
|
| 21 |
+
- DeepSeek-OCR integration
|
| 22 |
+
- Enhanced Document Validator mode
|
| 23 |
+
|
| 24 |
+
---
|
| 25 |
+
|
| 26 |
+
## π― How OCR Works
|
| 27 |
+
|
| 28 |
+
### Document Validator Mode Now Includes:
|
| 29 |
+
|
| 30 |
+
1. **Text Extraction** - Upload scanned document images
|
| 31 |
+
2. **Auto-Processing** - DeepSeek-OCR extracts text automatically
|
| 32 |
+
3. **Legal Analysis** - AI analyzes the extracted content
|
| 33 |
+
4. **Validation** - Checks for completeness and legal terms
|
| 34 |
+
|
| 35 |
+
---
|
| 36 |
+
|
| 37 |
+
## π Updated Requirements
|
| 38 |
+
|
| 39 |
+
New dependencies added to `requirements.txt`:
|
| 40 |
+
```
|
| 41 |
+
transformers>=4.35.0 # For DeepSeek-OCR
|
| 42 |
+
torch>=2.0.0 # Required by transformers
|
| 43 |
+
pillow>=10.0.0 # Image processing
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
---
|
| 47 |
+
|
| 48 |
+
## π Deployment Options
|
| 49 |
+
|
| 50 |
+
### Option 1: Deploy OCR Version (Most Advanced) β
|
| 51 |
+
```bash
|
| 52 |
+
cd ProVerbS_LaW_mAiN_PAgE
|
| 53 |
+
cp integrated_chatbot_with_ocr.py app.py
|
| 54 |
+
python deploy_to_hf.py
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
**Includes:**
|
| 58 |
+
- β
7 AI modes
|
| 59 |
+
- β
3 rotating logos
|
| 60 |
+
- β
OCR document processing
|
| 61 |
+
- β
DeepSeek-OCR integration
|
| 62 |
+
|
| 63 |
+
### Option 2: Deploy Without OCR
|
| 64 |
+
```bash
|
| 65 |
+
cd ProVerbS_LaW_mAiN_PAgE
|
| 66 |
+
cp integrated_chatbot_with_logos.py app.py
|
| 67 |
+
python deploy_to_hf.py
|
| 68 |
+
```
|
| 69 |
+
|
| 70 |
+
**Includes:**
|
| 71 |
+
- β
7 AI modes
|
| 72 |
+
- β
3 rotating logos
|
| 73 |
+
- β No OCR (lighter, faster)
|
| 74 |
+
|
| 75 |
+
---
|
| 76 |
+
|
| 77 |
+
## π¨ What Changed
|
| 78 |
+
|
| 79 |
+
### Document Validator Mode - Before:
|
| 80 |
+
- Text-based document analysis only
|
| 81 |
+
- Manual text paste required
|
| 82 |
+
|
| 83 |
+
### Document Validator Mode - Now: β
|
| 84 |
+
- β
Upload scanned document images
|
| 85 |
+
- β
Automatic text extraction (OCR)
|
| 86 |
+
- β
Image format support (JPG, PNG, PDF)
|
| 87 |
+
- β
Legal term detection
|
| 88 |
+
- β
Enhanced analysis
|
| 89 |
+
|
| 90 |
+
---
|
| 91 |
+
|
| 92 |
+
## π‘ Use Cases
|
| 93 |
+
|
| 94 |
+
### 1. Scanned Contracts
|
| 95 |
+
Upload a photo of a contract β OCR extracts text β AI analyzes
|
| 96 |
+
|
| 97 |
+
### 2. Legal Forms
|
| 98 |
+
Upload scanned legal forms β Auto-extract β Validate completeness
|
| 99 |
+
|
| 100 |
+
### 3. Historical Documents
|
| 101 |
+
Process old/scanned legal documents β Extract β Analyze
|
| 102 |
+
|
| 103 |
+
### 4. Mobile Photos
|
| 104 |
+
Take phone photo of document β Upload β Get instant analysis
|
| 105 |
+
|
| 106 |
+
---
|
| 107 |
+
|
| 108 |
+
## π§ Technical Details
|
| 109 |
+
|
| 110 |
+
### DeepSeek-OCR Model:
|
| 111 |
+
- **Model**: `deepseek-ai/DeepSeek-OCR`
|
| 112 |
+
- **Type**: Image-text-to-text pipeline
|
| 113 |
+
- **Capability**: Extract text from document images
|
| 114 |
+
- **Accuracy**: High-quality OCR for legal documents
|
| 115 |
+
|
| 116 |
+
### Integration Points:
|
| 117 |
+
```python
|
| 118 |
+
# OCR Pipeline
|
| 119 |
+
self.ocr_pipeline = pipeline(
|
| 120 |
+
"image-text-to-text",
|
| 121 |
+
model="deepseek-ai/DeepSeek-OCR",
|
| 122 |
+
trust_remote_code=True
|
| 123 |
+
)
|
| 124 |
+
|
| 125 |
+
# Process document
|
| 126 |
+
def process_document_with_ocr(self, image_path: str) -> str:
|
| 127 |
+
result = self.ocr_pipeline(image_path)
|
| 128 |
+
extracted_text = result[0]['generated_text']
|
| 129 |
+
return extracted_text
|
| 130 |
+
```
|
| 131 |
+
|
| 132 |
+
---
|
| 133 |
+
|
| 134 |
+
## β οΈ Important Notes
|
| 135 |
+
|
| 136 |
+
### Model Size:
|
| 137 |
+
- DeepSeek-OCR is a **large model**
|
| 138 |
+
- Requires significant GPU/CPU resources
|
| 139 |
+
- First load may take 1-2 minutes on HF Spaces
|
| 140 |
+
|
| 141 |
+
### Hardware Recommendations:
|
| 142 |
+
- **Free Tier**: Works but slower
|
| 143 |
+
- **CPU Upgrade**: Better performance
|
| 144 |
+
- **T4 GPU**: Best performance for OCR
|
| 145 |
+
|
| 146 |
+
### Fallback:
|
| 147 |
+
- If OCR model fails to load, app still works
|
| 148 |
+
- Document Validator mode functions without OCR
|
| 149 |
+
- Error messages guide users
|
| 150 |
+
|
| 151 |
+
---
|
| 152 |
+
|
| 153 |
+
## π Feature Comparison
|
| 154 |
+
|
| 155 |
+
| Feature | Without OCR | With OCR β |
|
| 156 |
+
|---------|-------------|-------------|
|
| 157 |
+
| Text analysis | β
| β
|
|
| 158 |
+
| Image upload | β | β
|
|
| 159 |
+
| Scanned docs | β | β
|
|
| 160 |
+
| Auto text extract | β | β
|
|
| 161 |
+
| Legal term detection | β
| β
Enhanced |
|
| 162 |
+
| Model size | Smaller | Larger |
|
| 163 |
+
| Load time | Faster | Slower (first load) |
|
| 164 |
+
| HF Hardware | Free tier OK | Upgrade recommended |
|
| 165 |
+
|
| 166 |
+
---
|
| 167 |
+
|
| 168 |
+
## π§ͺ Testing OCR Feature
|
| 169 |
+
|
| 170 |
+
### Local Preview:
|
| 171 |
+
```bash
|
| 172 |
+
cd ProVerbS_LaW_mAiN_PAgE
|
| 173 |
+
python integrated_chatbot_with_ocr.py
|
| 174 |
+
```
|
| 175 |
+
|
| 176 |
+
### Test Steps:
|
| 177 |
+
1. Go to "AI Legal Chatbot" tab
|
| 178 |
+
2. Select "Document Validator" mode
|
| 179 |
+
3. Upload a document image
|
| 180 |
+
4. Watch OCR extract text
|
| 181 |
+
5. Get AI analysis
|
| 182 |
+
|
| 183 |
+
---
|
| 184 |
+
|
| 185 |
+
## π Version History
|
| 186 |
+
|
| 187 |
+
### Version 1.0.0:
|
| 188 |
+
- 7 AI modes
|
| 189 |
+
- Rotating logos
|
| 190 |
+
- Text-based analysis
|
| 191 |
+
|
| 192 |
+
### Version 1.1.0 (Current): β
|
| 193 |
+
- β
All v1.0 features
|
| 194 |
+
- β
DeepSeek-OCR integration
|
| 195 |
+
- β
Image document processing
|
| 196 |
+
- β
Enhanced Document Validator
|
| 197 |
+
|
| 198 |
+
---
|
| 199 |
+
|
| 200 |
+
## π» Code Example
|
| 201 |
+
|
| 202 |
+
### Using OCR in Document Validator:
|
| 203 |
+
|
| 204 |
+
```python
|
| 205 |
+
# User uploads scanned contract image
|
| 206 |
+
uploaded_image = "contract_scan.jpg"
|
| 207 |
+
|
| 208 |
+
# OCR extracts text
|
| 209 |
+
extracted_text = chatbot.process_document_with_ocr(uploaded_image)
|
| 210 |
+
|
| 211 |
+
# AI analyzes extracted text
|
| 212 |
+
analysis = validate_document(extracted_text)
|
| 213 |
+
|
| 214 |
+
# Returns: Legal analysis of the contract
|
| 215 |
+
```
|
| 216 |
+
|
| 217 |
+
---
|
| 218 |
+
|
| 219 |
+
## π User Instructions
|
| 220 |
+
|
| 221 |
+
When using Document Validator mode:
|
| 222 |
+
|
| 223 |
+
1. **Select Mode**: Choose "Document Validator with OCR"
|
| 224 |
+
2. **Upload Image**: Use file upload for scanned documents
|
| 225 |
+
3. **Wait**: OCR processes image (may take 5-10 seconds)
|
| 226 |
+
4. **Review**: Check extracted text
|
| 227 |
+
5. **Analyze**: AI provides validation feedback
|
| 228 |
+
|
| 229 |
+
---
|
| 230 |
+
|
| 231 |
+
## π Troubleshooting
|
| 232 |
+
|
| 233 |
+
### Issue: OCR model won't load
|
| 234 |
+
|
| 235 |
+
**Solution**: Model requires transformers and torch
|
| 236 |
+
```bash
|
| 237 |
+
pip install transformers torch pillow
|
| 238 |
+
```
|
| 239 |
+
|
| 240 |
+
### Issue: Out of memory on HF Spaces
|
| 241 |
+
|
| 242 |
+
**Solution**: Upgrade to CPU Upgrade or T4 Small hardware tier
|
| 243 |
+
|
| 244 |
+
### Issue: OCR extraction inaccurate
|
| 245 |
+
|
| 246 |
+
**Solutions**:
|
| 247 |
+
- Ensure image is clear and high-resolution
|
| 248 |
+
- Image should be well-lit
|
| 249 |
+
- Text should be legible
|
| 250 |
+
- Try different image format (PNG vs JPG)
|
| 251 |
+
|
| 252 |
+
---
|
| 253 |
+
|
| 254 |
+
## π― Deployment Recommendation
|
| 255 |
+
|
| 256 |
+
### For Most Users: β
|
| 257 |
+
**Deploy OCR version** - Full features including document scanning
|
| 258 |
+
|
| 259 |
+
### For Basic Use:
|
| 260 |
+
**Deploy without OCR** - Faster, lighter, still fully functional
|
| 261 |
+
|
| 262 |
+
---
|
| 263 |
+
|
| 264 |
+
## β
Ready to Deploy with OCR?
|
| 265 |
+
|
| 266 |
+
### Quick Deploy:
|
| 267 |
+
```bash
|
| 268 |
+
cd ProVerbS_LaW_mAiN_PAgE
|
| 269 |
+
cp integrated_chatbot_with_ocr.py app.py
|
| 270 |
+
python deploy_to_hf.py
|
| 271 |
+
```
|
| 272 |
+
|
| 273 |
+
### Preview First:
|
| 274 |
+
```bash
|
| 275 |
+
python integrated_chatbot_with_ocr.py
|
| 276 |
+
# Test at http://localhost:7860
|
| 277 |
+
```
|
| 278 |
+
|
| 279 |
+
---
|
| 280 |
+
|
| 281 |
+
**Your Platform Now Has:**
|
| 282 |
+
- β
7 Specialized AI Modes
|
| 283 |
+
- β
3 Rotating Custom Logos
|
| 284 |
+
- β
OCR Document Processing β NEW!
|
| 285 |
+
- β
Complete Legal AI Solution
|
| 286 |
+
|
| 287 |
+
**Ready to deploy this advanced version?** π
|
PREVIEW_LOCALLY.bat
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@echo off
|
| 2 |
+
REM Local Preview - Test Before Deploying
|
| 3 |
+
color 0B
|
| 4 |
+
|
| 5 |
+
echo.
|
| 6 |
+
echo ============================================================
|
| 7 |
+
echo LOCAL PREVIEW - Test Your App Before Deployment
|
| 8 |
+
echo ============================================================
|
| 9 |
+
echo.
|
| 10 |
+
|
| 11 |
+
echo [*] This will start a local server so you can preview:
|
| 12 |
+
echo - Your rotating logos (watch them change every 60 sec)
|
| 13 |
+
echo - All 7 AI assistant modes
|
| 14 |
+
echo - Complete landing page design
|
| 15 |
+
echo - All features and tabs
|
| 16 |
+
echo.
|
| 17 |
+
|
| 18 |
+
REM Check Python
|
| 19 |
+
python --version >nul 2>&1
|
| 20 |
+
if errorlevel 1 (
|
| 21 |
+
echo [ERROR] Python is not installed or not in PATH
|
| 22 |
+
pause
|
| 23 |
+
exit /b 1
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
echo [OK] Python found
|
| 27 |
+
echo.
|
| 28 |
+
|
| 29 |
+
REM Check for required files
|
| 30 |
+
if not exist "integrated_chatbot_with_logos.py" (
|
| 31 |
+
echo [ERROR] integrated_chatbot_with_logos.py not found!
|
| 32 |
+
echo Please ensure you're in the ProVerbS_LaW_mAiN_PAgE folder
|
| 33 |
+
pause
|
| 34 |
+
exit /b 1
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
if not exist "assets\" (
|
| 38 |
+
echo [ERROR] Assets folder not found!
|
| 39 |
+
echo Your logos won't display without the assets folder
|
| 40 |
+
pause
|
| 41 |
+
exit /b 1
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
echo [OK] All files found
|
| 45 |
+
echo.
|
| 46 |
+
|
| 47 |
+
echo ============================================================
|
| 48 |
+
echo Starting Local Preview Server...
|
| 49 |
+
echo ============================================================
|
| 50 |
+
echo.
|
| 51 |
+
echo [*] The app will open in your browser automatically
|
| 52 |
+
echo [*] Server URL: http://localhost:7860
|
| 53 |
+
echo.
|
| 54 |
+
echo [*] IMPORTANT: Watch the logos rotate every 60 seconds!
|
| 55 |
+
echo.
|
| 56 |
+
echo [!] Press Ctrl+C to stop the server when done previewing
|
| 57 |
+
echo.
|
| 58 |
+
echo ============================================================
|
| 59 |
+
echo.
|
| 60 |
+
|
| 61 |
+
REM Run the app locally
|
| 62 |
+
python integrated_chatbot_with_logos.py
|
| 63 |
+
|
| 64 |
+
echo.
|
| 65 |
+
echo ============================================================
|
| 66 |
+
echo Preview Ended
|
| 67 |
+
echo ============================================================
|
| 68 |
+
echo.
|
| 69 |
+
pause
|
PREVIEW_TESTING_GUIDE.md
ADDED
|
@@ -0,0 +1,272 @@
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# π§ͺ Complete Preview Testing Guide
|
| 2 |
+
|
| 3 |
+
## Your Preview URL: http://localhost:7860
|
| 4 |
+
|
| 5 |
+
---
|
| 6 |
+
|
| 7 |
+
## β
TAB 1: WELCOME TAB
|
| 8 |
+
|
| 9 |
+
### What to Check:
|
| 10 |
+
1. **Click "π Welcome" tab**
|
| 11 |
+
2. **Look for:**
|
| 12 |
+
- [ ] Welcome heading displays
|
| 13 |
+
- [ ] "5 AI Models Integrated" section
|
| 14 |
+
- [ ] List of 7 specialized modes
|
| 15 |
+
- [ ] Information about features
|
| 16 |
+
- [ ] Text is readable
|
| 17 |
+
- [ ] Background watermarks visible (subtle)
|
| 18 |
+
|
| 19 |
+
### Expected Content:
|
| 20 |
+
- Welcome message
|
| 21 |
+
- Description of 5 AI models (DeepSeek, ERNIE, GDPVAL, Llama, MiniMax)
|
| 22 |
+
- List of 7 modes
|
| 23 |
+
- Feature highlights
|
| 24 |
+
|
| 25 |
+
---
|
| 26 |
+
|
| 27 |
+
## β
TAB 2: AI LEGAL CHATBOT TAB
|
| 28 |
+
|
| 29 |
+
### What to Check:
|
| 30 |
+
1. **Click "π€ AI Legal Chatbot" tab**
|
| 31 |
+
2. **Look for:**
|
| 32 |
+
- [ ] Chat interface loads
|
| 33 |
+
- [ ] **Mode selector dropdown** appears (7 modes)
|
| 34 |
+
- [ ] **AI Model selector dropdown** appears (Llama 3.3 / MiniMax-M2) β
|
| 35 |
+
- [ ] Chat input box visible
|
| 36 |
+
- [ ] Example questions display
|
| 37 |
+
- [ ] Max Tokens slider
|
| 38 |
+
- [ ] Temperature slider
|
| 39 |
+
- [ ] Top-p slider
|
| 40 |
+
|
| 41 |
+
### Test Interactions:
|
| 42 |
+
1. **Click Mode Selector Dropdown**
|
| 43 |
+
- Should show:
|
| 44 |
+
- navigation
|
| 45 |
+
- general
|
| 46 |
+
- document_validation
|
| 47 |
+
- legal_research
|
| 48 |
+
- etymology
|
| 49 |
+
- case_management
|
| 50 |
+
- regulatory_updates
|
| 51 |
+
|
| 52 |
+
2. **Click AI Model Selector Dropdown** β
|
| 53 |
+
- Should show:
|
| 54 |
+
- Meta Llama 3.3
|
| 55 |
+
- MiniMax-M2
|
| 56 |
+
|
| 57 |
+
3. **Try Typing in Chat**
|
| 58 |
+
- Type: "Hello"
|
| 59 |
+
- See if input works (response may need HF login)
|
| 60 |
+
|
| 61 |
+
4. **Click Example Questions**
|
| 62 |
+
- Should auto-fill the chat
|
| 63 |
+
|
| 64 |
+
---
|
| 65 |
+
|
| 66 |
+
## β
TAB 3: FEATURES TAB
|
| 67 |
+
|
| 68 |
+
### What to Check:
|
| 69 |
+
1. **Click "β¨ Features" tab**
|
| 70 |
+
2. **Look for:**
|
| 71 |
+
- [ ] "Advanced AI Features" heading
|
| 72 |
+
- [ ] List of 5 AI models with descriptions
|
| 73 |
+
- [ ] DeepSeek-OCR info
|
| 74 |
+
- [ ] ERNIE-4.5-VL info
|
| 75 |
+
- [ ] OpenAI GDPVAL info
|
| 76 |
+
- [ ] Meta Llama 3.3 info
|
| 77 |
+
- [ ] MiniMax-M2 info β
|
| 78 |
+
- [ ] "What This Means" section
|
| 79 |
+
- [ ] Text formatting is correct
|
| 80 |
+
|
| 81 |
+
### Expected Content:
|
| 82 |
+
- Detailed explanation of each AI model
|
| 83 |
+
- What each model does
|
| 84 |
+
- Benefits of multi-AI approach
|
| 85 |
+
|
| 86 |
+
---
|
| 87 |
+
|
| 88 |
+
## β
TAB 4: ABOUT TAB
|
| 89 |
+
|
| 90 |
+
### What to Check:
|
| 91 |
+
1. **Click "βΉοΈ About" tab**
|
| 92 |
+
2. **Look for:**
|
| 93 |
+
- [ ] "About ProVerBs Legal AI" heading
|
| 94 |
+
- [ ] Version number (2.1.0)
|
| 95 |
+
- [ ] "Complete AI Edition" mentioned
|
| 96 |
+
- [ ] List of features (7 modes, 5 models, etc.)
|
| 97 |
+
- [ ] Technical Stack section
|
| 98 |
+
- [ ] Disclaimer text
|
| 99 |
+
- [ ] Footer with version info
|
| 100 |
+
|
| 101 |
+
### Expected Content:
|
| 102 |
+
- Version 2.1.0 info
|
| 103 |
+
- Complete feature list
|
| 104 |
+
- Technical details
|
| 105 |
+
- Legal disclaimer
|
| 106 |
+
|
| 107 |
+
---
|
| 108 |
+
|
| 109 |
+
## π¨ VISUAL CHECKS (All Tabs)
|
| 110 |
+
|
| 111 |
+
### Watermarks (Test on ANY tab):
|
| 112 |
+
1. **Look in corners and center** - Should see 5 subtle logos
|
| 113 |
+
2. **Start 30-second timer** - Watch watermarks fade and change
|
| 114 |
+
3. **Observe random selection** - Each position picks random logo
|
| 115 |
+
4. **Check opacity** - Should be subtle (8%), not distracting
|
| 116 |
+
|
| 117 |
+
### Header Logo:
|
| 118 |
+
1. **Look at top of page** - Circular logo in purple gradient
|
| 119 |
+
2. **Start 60-second timer** - Watch it change (Logo 1 β 2 β 3)
|
| 120 |
+
3. **Check border and shadow** - Should look professional
|
| 121 |
+
|
| 122 |
+
### Overall Design:
|
| 123 |
+
- [ ] Purple gradient header
|
| 124 |
+
- [ ] Clean, professional layout
|
| 125 |
+
- [ ] Text is readable over watermarks
|
| 126 |
+
- [ ] No layout issues
|
| 127 |
+
- [ ] Mobile responsive (resize browser)
|
| 128 |
+
|
| 129 |
+
---
|
| 130 |
+
|
| 131 |
+
## β±οΈ TIMING TESTS
|
| 132 |
+
|
| 133 |
+
### 30-Second Test (Watermarks):
|
| 134 |
+
1. **Start timer when page loads**
|
| 135 |
+
2. **At 0:30** - All 5 watermarks should fade and change
|
| 136 |
+
3. **At 1:00** - Header logo changes
|
| 137 |
+
4. **At 1:30** - Watermarks change again
|
| 138 |
+
5. **At 2:00** - Header logo changes again
|
| 139 |
+
|
| 140 |
+
### What Should Happen:
|
| 141 |
+
- **Watermarks**: Change every 30 seconds, random logos
|
| 142 |
+
- **Header**: Changes every 60 seconds, sequential (1β2β3)
|
| 143 |
+
- **Transitions**: Smooth 2-second fade
|
| 144 |
+
|
| 145 |
+
---
|
| 146 |
+
|
| 147 |
+
## π±οΈ INTERACTION TESTS
|
| 148 |
+
|
| 149 |
+
### Navigation:
|
| 150 |
+
- [ ] Click between all 4 tabs multiple times
|
| 151 |
+
- [ ] Tabs switch smoothly
|
| 152 |
+
- [ ] Content updates correctly
|
| 153 |
+
|
| 154 |
+
### Dropdowns:
|
| 155 |
+
- [ ] Mode selector opens and closes
|
| 156 |
+
- [ ] AI Model selector opens and closes
|
| 157 |
+
- [ ] Can select different options
|
| 158 |
+
|
| 159 |
+
### Sliders:
|
| 160 |
+
- [ ] Max Tokens slider moves
|
| 161 |
+
- [ ] Temperature slider moves
|
| 162 |
+
- [ ] Top-p slider moves
|
| 163 |
+
|
| 164 |
+
### Scrolling:
|
| 165 |
+
- [ ] Page scrolls smoothly
|
| 166 |
+
- [ ] Watermarks stay fixed (don't scroll with page)
|
| 167 |
+
- [ ] Header stays at top
|
| 168 |
+
|
| 169 |
+
---
|
| 170 |
+
|
| 171 |
+
## π± MOBILE/RESPONSIVE TEST
|
| 172 |
+
|
| 173 |
+
### Resize Browser Window:
|
| 174 |
+
1. **Make window narrow** (mobile size)
|
| 175 |
+
2. **Check:**
|
| 176 |
+
- [ ] Layout adjusts
|
| 177 |
+
- [ ] Text remains readable
|
| 178 |
+
- [ ] Tabs still work
|
| 179 |
+
- [ ] Watermarks still visible
|
| 180 |
+
- [ ] No horizontal scroll
|
| 181 |
+
|
| 182 |
+
---
|
| 183 |
+
|
| 184 |
+
## π¨ ISSUE CHECKLIST
|
| 185 |
+
|
| 186 |
+
### If You See Problems:
|
| 187 |
+
|
| 188 |
+
**Watermarks not visible:**
|
| 189 |
+
- Check corners and center carefully
|
| 190 |
+
- They're subtle (8% opacity)
|
| 191 |
+
- Try different tabs
|
| 192 |
+
|
| 193 |
+
**Watermarks not changing:**
|
| 194 |
+
- Wait full 30 seconds
|
| 195 |
+
- Check browser console for errors
|
| 196 |
+
|
| 197 |
+
**Header logo not changing:**
|
| 198 |
+
- Wait full 60 seconds
|
| 199 |
+
- Check if images loaded
|
| 200 |
+
|
| 201 |
+
**Tabs not working:**
|
| 202 |
+
- Try refreshing page
|
| 203 |
+
- Check browser console
|
| 204 |
+
|
| 205 |
+
**Dropdowns not appearing:**
|
| 206 |
+
- Make sure you're on "AI Legal Chatbot" tab
|
| 207 |
+
- They only show in that tab
|
| 208 |
+
|
| 209 |
+
---
|
| 210 |
+
|
| 211 |
+
## β
FINAL CHECKLIST
|
| 212 |
+
|
| 213 |
+
Before approving for deployment:
|
| 214 |
+
|
| 215 |
+
**Visual:**
|
| 216 |
+
- [ ] All 4 tabs display correctly
|
| 217 |
+
- [ ] 5 watermarks visible in background
|
| 218 |
+
- [ ] Header logo displays and rotates
|
| 219 |
+
- [ ] Professional appearance
|
| 220 |
+
- [ ] No visual glitches
|
| 221 |
+
|
| 222 |
+
**Functionality:**
|
| 223 |
+
- [ ] All tabs clickable
|
| 224 |
+
- [ ] Mode selector works
|
| 225 |
+
- [ ] AI Model selector works
|
| 226 |
+
- [ ] Chat input accepts text
|
| 227 |
+
- [ ] Sliders move
|
| 228 |
+
|
| 229 |
+
**Timing:**
|
| 230 |
+
- [ ] Watched watermarks change at 30 sec
|
| 231 |
+
- [ ] Watched header logo change at 60 sec
|
| 232 |
+
- [ ] Smooth transitions
|
| 233 |
+
|
| 234 |
+
**Performance:**
|
| 235 |
+
- [ ] Page loads quickly
|
| 236 |
+
- [ ] Smooth scrolling
|
| 237 |
+
- [ ] No lag or freezing
|
| 238 |
+
|
| 239 |
+
---
|
| 240 |
+
|
| 241 |
+
## π TEST RESULTS
|
| 242 |
+
|
| 243 |
+
**Date Tested:** _______________
|
| 244 |
+
|
| 245 |
+
**Overall Rating:** βββββ
|
| 246 |
+
|
| 247 |
+
**Issues Found:**
|
| 248 |
+
- [ ] None - Ready to deploy! β
|
| 249 |
+
- [ ] Minor issues (list below)
|
| 250 |
+
- [ ] Major issues (needs fixing)
|
| 251 |
+
|
| 252 |
+
**Notes:**
|
| 253 |
+
_________________________________
|
| 254 |
+
_________________________________
|
| 255 |
+
_________________________________
|
| 256 |
+
|
| 257 |
+
---
|
| 258 |
+
|
| 259 |
+
## π― AFTER TESTING
|
| 260 |
+
|
| 261 |
+
**If everything looks good:**
|
| 262 |
+
β
Say "Looks great, deploy it!"
|
| 263 |
+
|
| 264 |
+
**If you need adjustments:**
|
| 265 |
+
β οΈ Describe what needs changing
|
| 266 |
+
|
| 267 |
+
**If you want to test more:**
|
| 268 |
+
π Keep testing and exploring!
|
| 269 |
+
|
| 270 |
+
---
|
| 271 |
+
|
| 272 |
+
**Happy Testing! π§ͺ**
|
PREVIEW_THEN_DEPLOY.bat
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@echo off
|
| 2 |
+
REM Complete Workflow: Preview Locally THEN Deploy
|
| 3 |
+
color 0A
|
| 4 |
+
|
| 5 |
+
echo.
|
| 6 |
+
echo ============================================================
|
| 7 |
+
echo PREVIEW THEN DEPLOY - Safe Deployment Workflow
|
| 8 |
+
echo ============================================================
|
| 9 |
+
echo.
|
| 10 |
+
|
| 11 |
+
echo STEP 1: PREVIEW LOCALLY
|
| 12 |
+
echo ============================================================
|
| 13 |
+
echo.
|
| 14 |
+
echo [*] First, we'll start a local preview so you can test
|
| 15 |
+
echo everything before deploying to Hugging Face.
|
| 16 |
+
echo.
|
| 17 |
+
set /p preview="Start local preview now? (Y/N): "
|
| 18 |
+
if /i not "%preview%"=="Y" (
|
| 19 |
+
echo.
|
| 20 |
+
echo [X] Preview cancelled
|
| 21 |
+
pause
|
| 22 |
+
exit /b 0
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
echo.
|
| 26 |
+
echo [*] Starting local preview...
|
| 27 |
+
echo [*] The app will open at http://localhost:7860
|
| 28 |
+
echo.
|
| 29 |
+
echo PREVIEW CHECKLIST:
|
| 30 |
+
echo [ ] Check that all 3 logos display
|
| 31 |
+
echo [ ] Wait 60+ seconds to see logos rotate
|
| 32 |
+
echo [ ] Test all 7 AI assistant modes
|
| 33 |
+
echo [ ] Navigate through all tabs
|
| 34 |
+
echo [ ] Test on mobile view (resize browser)
|
| 35 |
+
echo [ ] Check that everything looks good
|
| 36 |
+
echo.
|
| 37 |
+
echo [!] Press Ctrl+C when you're done previewing
|
| 38 |
+
echo.
|
| 39 |
+
pause
|
| 40 |
+
|
| 41 |
+
REM Run local preview
|
| 42 |
+
python integrated_chatbot_with_logos.py
|
| 43 |
+
|
| 44 |
+
echo.
|
| 45 |
+
echo ============================================================
|
| 46 |
+
echo.
|
| 47 |
+
|
| 48 |
+
echo STEP 2: DEPLOY TO HUGGING FACE
|
| 49 |
+
echo ============================================================
|
| 50 |
+
echo.
|
| 51 |
+
echo [*] Did everything look good in the preview?
|
| 52 |
+
echo [*] Are you ready to deploy to Hugging Face?
|
| 53 |
+
echo.
|
| 54 |
+
set /p deploy="Deploy to Hugging Face now? (Y/N): "
|
| 55 |
+
if /i not "%deploy%"=="Y" (
|
| 56 |
+
echo.
|
| 57 |
+
echo [X] Deployment cancelled
|
| 58 |
+
echo.
|
| 59 |
+
echo You can run this script again when ready!
|
| 60 |
+
pause
|
| 61 |
+
exit /b 0
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
echo.
|
| 65 |
+
echo [*] Great! Proceeding with deployment...
|
| 66 |
+
echo.
|
| 67 |
+
|
| 68 |
+
REM Backup current app.py
|
| 69 |
+
if exist app.py (
|
| 70 |
+
echo [*] Backing up current app.py...
|
| 71 |
+
copy app.py app_backup_%date:~-4,4%%date:~-7,2%%date:~-10,2%.py >nul
|
| 72 |
+
echo [OK] Backup created
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
echo.
|
| 76 |
+
echo [*] Preparing deployment files...
|
| 77 |
+
copy integrated_chatbot_with_logos.py app.py >nul
|
| 78 |
+
echo [OK] App file ready
|
| 79 |
+
|
| 80 |
+
echo.
|
| 81 |
+
echo [*] Starting deployment to Hugging Face...
|
| 82 |
+
echo.
|
| 83 |
+
|
| 84 |
+
python deploy_to_hf.py
|
| 85 |
+
|
| 86 |
+
echo.
|
| 87 |
+
echo ============================================================
|
| 88 |
+
echo Deployment Complete!
|
| 89 |
+
echo ============================================================
|
| 90 |
+
echo.
|
| 91 |
+
echo Your Space is now live with rotating logos!
|
| 92 |
+
echo Visit: https://huggingface.co/spaces/Solomon7890/ProVerbS_LaW_mAiN_PAgE
|
| 93 |
+
echo.
|
| 94 |
+
echo Remember: Wait 60+ seconds to see the logos rotate on the live site!
|
| 95 |
+
echo.
|
| 96 |
+
pause
|
README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: ProVerbS LaW MAiN PAgE
|
| 3 |
+
emoji: π¬
|
| 4 |
+
colorFrom: yellow
|
| 5 |
+
colorTo: purple
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 5.42.0
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
hf_oauth: true
|
| 11 |
+
hf_oauth_scopes:
|
| 12 |
+
- inference-api
|
| 13 |
+
license: unlicense
|
| 14 |
+
short_description: 'Lawful vs. Legal : Dual Analysis "Adappt''plication"...!!!'
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
An example chatbot using [Gradio](https://gradio.app), [`huggingface_hub`](https://huggingface.co/docs/huggingface_hub/v0.22.2/en/index), and the [Hugging Face Inference API](https://huggingface.co/docs/api-inference/index).
|
README_DEPLOYMENT.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# π Enhanced Landing Page - Ready to Deploy!
|
| 2 |
+
|
| 3 |
+
## What's New
|
| 4 |
+
|
| 5 |
+
Your landing page has been **upgraded** with professional features!
|
| 6 |
+
|
| 7 |
+
### β¨ New Features
|
| 8 |
+
|
| 9 |
+
#### π Welcome Tab
|
| 10 |
+
- Beautiful gradient header
|
| 11 |
+
- Platform overview
|
| 12 |
+
- Mission statement
|
| 13 |
+
- Key features showcase
|
| 14 |
+
|
| 15 |
+
#### π€ Enhanced AI Assistant
|
| 16 |
+
- Better system prompts
|
| 17 |
+
- Example questions
|
| 18 |
+
- Improved styling
|
| 19 |
+
- Real-time streaming
|
| 20 |
+
|
| 21 |
+
#### β¨ Features Tab
|
| 22 |
+
- Comprehensive feature list
|
| 23 |
+
- Visual grid layout
|
| 24 |
+
- "Coming Soon" section
|
| 25 |
+
- Hover effects
|
| 26 |
+
|
| 27 |
+
#### βΉοΈ About Tab
|
| 28 |
+
- Platform story
|
| 29 |
+
- Target audience info
|
| 30 |
+
- Privacy & security details
|
| 31 |
+
- Resources and credits
|
| 32 |
+
|
| 33 |
+
---
|
| 34 |
+
|
| 35 |
+
## π― Quick Deploy (2 Ways)
|
| 36 |
+
|
| 37 |
+
### Method 1: One-Click (Windows)
|
| 38 |
+
```
|
| 39 |
+
Double-click: DEPLOY_NOW.bat
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
### Method 2: Command Line
|
| 43 |
+
```bash
|
| 44 |
+
python deploy_to_hf.py
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
---
|
| 48 |
+
|
| 49 |
+
## πΊ Live Preview
|
| 50 |
+
|
| 51 |
+
A live preview screen has been created for you:
|
| 52 |
+
- **File**: `../LIVE_PREVIEW.html`
|
| 53 |
+
- **Feature**: View your Space in real-time
|
| 54 |
+
- **Tabs**: Switch between different views
|
| 55 |
+
|
| 56 |
+
---
|
| 57 |
+
|
| 58 |
+
## π§ Files Created
|
| 59 |
+
|
| 60 |
+
| File | Purpose |
|
| 61 |
+
|------|---------|
|
| 62 |
+
| `enhanced_app.py` | New enhanced landing page |
|
| 63 |
+
| `deploy_to_hf.py` | Deployment script |
|
| 64 |
+
| `DEPLOY_NOW.bat` | Quick deploy (Windows) |
|
| 65 |
+
| `README_DEPLOYMENT.md` | This file |
|
| 66 |
+
|
| 67 |
+
---
|
| 68 |
+
|
| 69 |
+
## β
Pre-Deployment Checklist
|
| 70 |
+
|
| 71 |
+
- [ ] Hugging Face account ready
|
| 72 |
+
- [ ] Logged in: `huggingface-cli login`
|
| 73 |
+
- [ ] Reviewed enhanced_app.py
|
| 74 |
+
- [ ] Ready to deploy!
|
| 75 |
+
|
| 76 |
+
---
|
| 77 |
+
|
| 78 |
+
## π Deploy Now
|
| 79 |
+
|
| 80 |
+
```bash
|
| 81 |
+
# Make sure you're logged in
|
| 82 |
+
huggingface-cli whoami
|
| 83 |
+
|
| 84 |
+
# If not logged in
|
| 85 |
+
huggingface-cli login
|
| 86 |
+
|
| 87 |
+
# Deploy!
|
| 88 |
+
python deploy_to_hf.py
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
+
---
|
| 92 |
+
|
| 93 |
+
## π Your Space URL
|
| 94 |
+
|
| 95 |
+
After deployment (2-3 minutes):
|
| 96 |
+
```
|
| 97 |
+
https://huggingface.co/spaces/Solomon7890/ProVerbS_LaW_mAiN_PAgE
|
| 98 |
+
```
|
| 99 |
+
|
| 100 |
+
---
|
| 101 |
+
|
| 102 |
+
## π Need Help?
|
| 103 |
+
|
| 104 |
+
- **Full Guide**: `../DEPLOY_LANDING_PAGE_GUIDE.md`
|
| 105 |
+
- **Multi-Module Platform**: `../HF_SPACE_DEPLOYMENT/`
|
| 106 |
+
- **Live Preview**: `../LIVE_PREVIEW.html`
|
| 107 |
+
|
| 108 |
+
---
|
| 109 |
+
|
| 110 |
+
**Ready? Let's deploy!** π
|
app.py
ADDED
|
@@ -0,0 +1,866 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
ProVerBs Legal AI - Complete AI Integration
|
| 3 |
+
Features: 7 AI Modes + Rotating Logos + DeepSeek-OCR + ERNIE-4.5-VL + GDPVAL
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import gradio as gr
|
| 7 |
+
from huggingface_hub import InferenceClient
|
| 8 |
+
import json
|
| 9 |
+
import os
|
| 10 |
+
from datetime import datetime
|
| 11 |
+
from typing import Dict, List, Optional
|
| 12 |
+
import base64
|
| 13 |
+
from pathlib import Path
|
| 14 |
+
|
| 15 |
+
# AI Model Integration
|
| 16 |
+
try:
|
| 17 |
+
from transformers import pipeline, AutoModel
|
| 18 |
+
from datasets import load_dataset
|
| 19 |
+
AI_MODELS_AVAILABLE = True
|
| 20 |
+
except ImportError:
|
| 21 |
+
AI_MODELS_AVAILABLE = False
|
| 22 |
+
print("β οΈ AI models not available. Install transformers and datasets.")
|
| 23 |
+
|
| 24 |
+
class EnhancedAILegalChatbot:
|
| 25 |
+
"""
|
| 26 |
+
Enhanced AI Legal Chatbot with multiple AI models
|
| 27 |
+
- DeepSeek-OCR for document text extraction
|
| 28 |
+
- ERNIE-4.5-VL for vision-language understanding
|
| 29 |
+
- OpenAI GDPVAL dataset for legal knowledge
|
| 30 |
+
"""
|
| 31 |
+
|
| 32 |
+
def __init__(self):
|
| 33 |
+
self.specialized_modes = {
|
| 34 |
+
"navigation": "Application Navigation Guide",
|
| 35 |
+
"general": "General Legal Assistant",
|
| 36 |
+
"document_validation": "Document Validator with OCR & Vision AI",
|
| 37 |
+
"legal_research": "Legal Research Assistant with GDPVAL",
|
| 38 |
+
"etymology": "Legal Etymology Lookup",
|
| 39 |
+
"case_management": "Case Management Helper",
|
| 40 |
+
"regulatory_updates": "Regulatory Update Monitor"
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
# Initialize AI models
|
| 44 |
+
self.ocr_pipeline = None
|
| 45 |
+
self.vision_pipeline = None
|
| 46 |
+
self.gdpval_dataset = None
|
| 47 |
+
self.minimax_pipeline = None
|
| 48 |
+
|
| 49 |
+
if AI_MODELS_AVAILABLE:
|
| 50 |
+
self._initialize_models()
|
| 51 |
+
|
| 52 |
+
def _initialize_models(self):
|
| 53 |
+
"""Initialize all AI models"""
|
| 54 |
+
|
| 55 |
+
# DeepSeek-OCR for text extraction
|
| 56 |
+
try:
|
| 57 |
+
print("π¦ Loading DeepSeek-OCR...")
|
| 58 |
+
self.ocr_pipeline = pipeline(
|
| 59 |
+
"image-text-to-text",
|
| 60 |
+
model="deepseek-ai/DeepSeek-OCR",
|
| 61 |
+
trust_remote_code=True
|
| 62 |
+
)
|
| 63 |
+
print("β
DeepSeek-OCR loaded!")
|
| 64 |
+
except Exception as e:
|
| 65 |
+
print(f"β οΈ DeepSeek-OCR not loaded: {e}")
|
| 66 |
+
|
| 67 |
+
# ERNIE-4.5-VL for vision-language understanding
|
| 68 |
+
try:
|
| 69 |
+
print("π¦ Loading ERNIE-4.5-VL (this may take a while)...")
|
| 70 |
+
self.vision_pipeline = pipeline(
|
| 71 |
+
"image-text-to-text",
|
| 72 |
+
model="baidu/ERNIE-4.5-VL-28B-A3B-Thinking",
|
| 73 |
+
trust_remote_code=True
|
| 74 |
+
)
|
| 75 |
+
print("β
ERNIE-4.5-VL loaded!")
|
| 76 |
+
except Exception as e:
|
| 77 |
+
print(f"β οΈ ERNIE-4.5-VL not loaded: {e}")
|
| 78 |
+
|
| 79 |
+
# OpenAI GDPVAL dataset for legal knowledge
|
| 80 |
+
try:
|
| 81 |
+
print("π¦ Loading OpenAI GDPVAL dataset...")
|
| 82 |
+
self.gdpval_dataset = load_dataset("openai/gdpval", split="train")
|
| 83 |
+
print(f"β
GDPVAL loaded! {len(self.gdpval_dataset)} entries")
|
| 84 |
+
except Exception as e:
|
| 85 |
+
print(f"β οΈ GDPVAL not loaded: {e}")
|
| 86 |
+
|
| 87 |
+
# MiniMax-M2 for advanced text generation
|
| 88 |
+
try:
|
| 89 |
+
print("π¦ Loading MiniMax-M2...")
|
| 90 |
+
self.minimax_pipeline = pipeline(
|
| 91 |
+
"text-generation",
|
| 92 |
+
model="MiniMaxAI/MiniMax-M2",
|
| 93 |
+
trust_remote_code=True
|
| 94 |
+
)
|
| 95 |
+
print("β
MiniMax-M2 loaded!")
|
| 96 |
+
except Exception as e:
|
| 97 |
+
print(f"β οΈ MiniMax-M2 not loaded: {e}")
|
| 98 |
+
|
| 99 |
+
def process_with_ocr(self, image_path: str) -> str:
|
| 100 |
+
"""Extract text using DeepSeek-OCR"""
|
| 101 |
+
if not self.ocr_pipeline:
|
| 102 |
+
return "β OCR not available"
|
| 103 |
+
|
| 104 |
+
try:
|
| 105 |
+
result = self.ocr_pipeline(image_path)
|
| 106 |
+
return result[0]['generated_text'] if result else ""
|
| 107 |
+
except Exception as e:
|
| 108 |
+
return f"β OCR error: {str(e)}"
|
| 109 |
+
|
| 110 |
+
def process_with_vision(self, image_url: str, question: str) -> str:
|
| 111 |
+
"""Analyze image using ERNIE-4.5-VL"""
|
| 112 |
+
if not self.vision_pipeline:
|
| 113 |
+
return "β Vision AI not available"
|
| 114 |
+
|
| 115 |
+
try:
|
| 116 |
+
messages = [
|
| 117 |
+
{
|
| 118 |
+
"role": "user",
|
| 119 |
+
"content": [
|
| 120 |
+
{"type": "image", "url": image_url},
|
| 121 |
+
{"type": "text", "text": question}
|
| 122 |
+
]
|
| 123 |
+
}
|
| 124 |
+
]
|
| 125 |
+
result = self.vision_pipeline(text=messages)
|
| 126 |
+
return result
|
| 127 |
+
except Exception as e:
|
| 128 |
+
return f"β Vision AI error: {str(e)}"
|
| 129 |
+
|
| 130 |
+
def search_gdpval(self, query: str, limit: int = 5) -> str:
|
| 131 |
+
"""Search OpenAI GDPVAL dataset for legal knowledge"""
|
| 132 |
+
if not self.gdpval_dataset:
|
| 133 |
+
return "β GDPVAL dataset not available"
|
| 134 |
+
|
| 135 |
+
try:
|
| 136 |
+
# Simple keyword search (can be enhanced with embeddings)
|
| 137 |
+
results = []
|
| 138 |
+
query_lower = query.lower()
|
| 139 |
+
|
| 140 |
+
for i, entry in enumerate(self.gdpval_dataset):
|
| 141 |
+
if i >= 100: # Limit search for performance
|
| 142 |
+
break
|
| 143 |
+
|
| 144 |
+
# Check if query keywords appear in entry
|
| 145 |
+
entry_text = str(entry).lower()
|
| 146 |
+
if any(word in entry_text for word in query_lower.split()):
|
| 147 |
+
results.append(entry)
|
| 148 |
+
if len(results) >= limit:
|
| 149 |
+
break
|
| 150 |
+
|
| 151 |
+
if results:
|
| 152 |
+
formatted = "### π GDPVAL Knowledge Base Results:\n\n"
|
| 153 |
+
for i, result in enumerate(results, 1):
|
| 154 |
+
formatted += f"**Result {i}:**\n{result}\n\n"
|
| 155 |
+
return formatted
|
| 156 |
+
else:
|
| 157 |
+
return "No relevant results found in GDPVAL dataset."
|
| 158 |
+
except Exception as e:
|
| 159 |
+
return f"β GDPVAL search error: {str(e)}"
|
| 160 |
+
|
| 161 |
+
def analyze_legal_document(self, image_path: str) -> str:
|
| 162 |
+
"""
|
| 163 |
+
Complete document analysis using multiple AI models:
|
| 164 |
+
1. DeepSeek-OCR for text extraction
|
| 165 |
+
2. ERNIE-4.5-VL for visual understanding
|
| 166 |
+
3. Legal analysis with AI
|
| 167 |
+
"""
|
| 168 |
+
analysis = "## π Complete Legal Document Analysis\n\n"
|
| 169 |
+
|
| 170 |
+
# Step 1: OCR Text Extraction
|
| 171 |
+
analysis += "### Step 1: Text Extraction (DeepSeek-OCR)\n"
|
| 172 |
+
extracted_text = self.process_with_ocr(image_path)
|
| 173 |
+
analysis += f"```\n{extracted_text[:500]}...\n```\n\n"
|
| 174 |
+
|
| 175 |
+
# Step 2: Vision Analysis
|
| 176 |
+
analysis += "### Step 2: Visual Document Understanding (ERNIE-4.5-VL)\n"
|
| 177 |
+
vision_result = self.process_with_vision(
|
| 178 |
+
image_path,
|
| 179 |
+
"Analyze this legal document. Identify document type, key sections, and any notable elements."
|
| 180 |
+
)
|
| 181 |
+
analysis += f"{vision_result}\n\n"
|
| 182 |
+
|
| 183 |
+
# Step 3: Legal Term Detection
|
| 184 |
+
analysis += "### Step 3: Legal Analysis\n"
|
| 185 |
+
legal_terms = self._detect_legal_terms(extracted_text)
|
| 186 |
+
analysis += f"**Legal Terms Found:** {legal_terms}\n\n"
|
| 187 |
+
|
| 188 |
+
# Step 4: Document Quality Check
|
| 189 |
+
analysis += "### Step 4: Document Quality\n"
|
| 190 |
+
quality = self._assess_document_quality(extracted_text)
|
| 191 |
+
analysis += f"{quality}\n\n"
|
| 192 |
+
|
| 193 |
+
return analysis
|
| 194 |
+
|
| 195 |
+
def _detect_legal_terms(self, text: str) -> str:
|
| 196 |
+
"""Detect legal terminology in text"""
|
| 197 |
+
legal_terms = [
|
| 198 |
+
'contract', 'agreement', 'party', 'clause', 'provision',
|
| 199 |
+
'whereas', 'hereby', 'herein', 'pursuant', 'consideration',
|
| 200 |
+
'liability', 'indemnify', 'warranty', 'breach', 'terminate',
|
| 201 |
+
'arbitration', 'jurisdiction', 'statute', 'regulation'
|
| 202 |
+
]
|
| 203 |
+
|
| 204 |
+
found = [term for term in legal_terms if term.lower() in text.lower()]
|
| 205 |
+
return ', '.join(found) if found else "None detected"
|
| 206 |
+
|
| 207 |
+
def _assess_document_quality(self, text: str) -> str:
|
| 208 |
+
"""Assess document completeness and quality"""
|
| 209 |
+
issues = []
|
| 210 |
+
|
| 211 |
+
if len(text) < 100:
|
| 212 |
+
issues.append("β οΈ Document seems very short")
|
| 213 |
+
|
| 214 |
+
if not any(term in text.lower() for term in ['party', 'parties', 'agreement']):
|
| 215 |
+
issues.append("β οΈ Missing party identification")
|
| 216 |
+
|
| 217 |
+
if not any(term in text.lower() for term in ['date', 'dated', 'effective']):
|
| 218 |
+
issues.append("β οΈ No effective date found")
|
| 219 |
+
|
| 220 |
+
if issues:
|
| 221 |
+
return "**Issues Found:**\n" + "\n".join(issues)
|
| 222 |
+
else:
|
| 223 |
+
return "β
Document appears complete"
|
| 224 |
+
|
| 225 |
+
def generate_with_minimax(self, messages: list) -> str:
|
| 226 |
+
"""Generate response using MiniMax-M2"""
|
| 227 |
+
if not self.minimax_pipeline:
|
| 228 |
+
return "β MiniMax-M2 not available"
|
| 229 |
+
|
| 230 |
+
try:
|
| 231 |
+
result = self.minimax_pipeline(messages)
|
| 232 |
+
return result[0]['generated_text'] if result else "No response"
|
| 233 |
+
except Exception as e:
|
| 234 |
+
return f"β MiniMax error: {str(e)}"
|
| 235 |
+
|
| 236 |
+
def get_mode_system_prompt(self, mode: str) -> str:
|
| 237 |
+
"""Get specialized system prompt based on mode"""
|
| 238 |
+
prompts = {
|
| 239 |
+
"navigation": """You are a ProVerBs Application Navigation Guide.
|
| 240 |
+
|
| 241 |
+
**Enhanced Features:**
|
| 242 |
+
- Document Analysis with OCR (DeepSeek-OCR)
|
| 243 |
+
- Vision AI Analysis (ERNIE-4.5-VL)
|
| 244 |
+
- Legal Knowledge Base (OpenAI GDPVAL)
|
| 245 |
+
- 7 Specialized AI Modes
|
| 246 |
+
|
| 247 |
+
Guide users to the right features.""",
|
| 248 |
+
|
| 249 |
+
"general": """You are a General Legal Assistant for ProVerBs Legal AI Platform.
|
| 250 |
+
|
| 251 |
+
**Available Tools:**
|
| 252 |
+
- GDPVAL legal knowledge dataset
|
| 253 |
+
- Vision AI for document understanding
|
| 254 |
+
- OCR for text extraction
|
| 255 |
+
|
| 256 |
+
Provide accurate legal information while noting you cannot provide legal advice.""",
|
| 257 |
+
|
| 258 |
+
"document_validation": """You are an Advanced Document Validator.
|
| 259 |
+
|
| 260 |
+
**AI-Powered Capabilities:**
|
| 261 |
+
- **DeepSeek-OCR**: Extract text from scanned documents
|
| 262 |
+
- **ERNIE-4.5-VL**: Understand document structure and layout visually
|
| 263 |
+
- **Legal Analysis**: Validate completeness and legal terms
|
| 264 |
+
|
| 265 |
+
**Process:**
|
| 266 |
+
1. Extract text with OCR
|
| 267 |
+
2. Analyze visually with ERNIE
|
| 268 |
+
3. Check legal validity
|
| 269 |
+
4. Provide detailed feedback""",
|
| 270 |
+
|
| 271 |
+
"legal_research": """You are a Legal Research Assistant with GDPVAL access.
|
| 272 |
+
|
| 273 |
+
**Enhanced Research Tools:**
|
| 274 |
+
- OpenAI GDPVAL dataset for legal knowledge
|
| 275 |
+
- Case law and precedent search
|
| 276 |
+
- Statute and regulation analysis
|
| 277 |
+
|
| 278 |
+
Provide comprehensive research with citations.""",
|
| 279 |
+
|
| 280 |
+
"etymology": """You are a Legal Etymology Expert. Explain origins of legal terms.""",
|
| 281 |
+
|
| 282 |
+
"case_management": """You are a Case Management Helper with AI document processing.""",
|
| 283 |
+
|
| 284 |
+
"regulatory_updates": """You are a Regulatory Update Monitor."""
|
| 285 |
+
}
|
| 286 |
+
return prompts.get(mode, prompts["general"])
|
| 287 |
+
|
| 288 |
+
def respond_with_mode(
|
| 289 |
+
message,
|
| 290 |
+
history: list,
|
| 291 |
+
mode: str,
|
| 292 |
+
model_choice: str,
|
| 293 |
+
max_tokens: int,
|
| 294 |
+
temperature: float,
|
| 295 |
+
top_p: float,
|
| 296 |
+
):
|
| 297 |
+
"""Generate AI response based on selected mode"""
|
| 298 |
+
chatbot = EnhancedAILegalChatbot()
|
| 299 |
+
|
| 300 |
+
system_message = chatbot.get_mode_system_prompt(mode)
|
| 301 |
+
|
| 302 |
+
# Enhanced responses for specific modes
|
| 303 |
+
if mode == "document_validation" and "analyze" in message.lower():
|
| 304 |
+
yield """
|
| 305 |
+
## π Advanced Document Validator
|
| 306 |
+
|
| 307 |
+
**Multi-AI Analysis Available:**
|
| 308 |
+
|
| 309 |
+
1. **DeepSeek-OCR**: Extract text from scanned documents
|
| 310 |
+
2. **ERNIE-4.5-VL**: Understand document structure visually
|
| 311 |
+
3. **Legal AI**: Validate and analyze content
|
| 312 |
+
|
| 313 |
+
**Upload a document to get:**
|
| 314 |
+
- β
Text extraction
|
| 315 |
+
- β
Visual structure analysis
|
| 316 |
+
- β
Legal term detection
|
| 317 |
+
- β
Completeness check
|
| 318 |
+
- β
Quality assessment
|
| 319 |
+
"""
|
| 320 |
+
return
|
| 321 |
+
|
| 322 |
+
if mode == "legal_research" and "search" in message.lower():
|
| 323 |
+
# Search GDPVAL dataset
|
| 324 |
+
gdpval_results = chatbot.search_gdpval(message)
|
| 325 |
+
yield gdpval_results
|
| 326 |
+
return
|
| 327 |
+
|
| 328 |
+
# Choose AI model based on selection
|
| 329 |
+
if model_choice == "MiniMax-M2" and chatbot.minimax_pipeline:
|
| 330 |
+
# Use MiniMax-M2
|
| 331 |
+
try:
|
| 332 |
+
messages_minimax = [
|
| 333 |
+
{"role": "system", "content": system_message},
|
| 334 |
+
{"role": "user", "content": message}
|
| 335 |
+
]
|
| 336 |
+
response = chatbot.generate_with_minimax(messages_minimax)
|
| 337 |
+
yield response
|
| 338 |
+
except Exception as e:
|
| 339 |
+
yield f"MiniMax Error: {str(e)}"
|
| 340 |
+
else:
|
| 341 |
+
# Use HF Inference API (Llama) as default
|
| 342 |
+
try:
|
| 343 |
+
client = InferenceClient(model="meta-llama/Llama-3.3-70B-Instruct")
|
| 344 |
+
|
| 345 |
+
messages = [{"role": "system", "content": system_message}]
|
| 346 |
+
|
| 347 |
+
for user_msg, assistant_msg in history:
|
| 348 |
+
if user_msg:
|
| 349 |
+
messages.append({"role": "user", "content": user_msg})
|
| 350 |
+
if assistant_msg:
|
| 351 |
+
messages.append({"role": "assistant", "content": assistant_msg})
|
| 352 |
+
|
| 353 |
+
messages.append({"role": "user", "content": message})
|
| 354 |
+
|
| 355 |
+
response = ""
|
| 356 |
+
for message_chunk in client.chat_completion(
|
| 357 |
+
messages,
|
| 358 |
+
max_tokens=max_tokens,
|
| 359 |
+
stream=True,
|
| 360 |
+
temperature=temperature,
|
| 361 |
+
top_p=top_p,
|
| 362 |
+
):
|
| 363 |
+
if message_chunk.choices and message_chunk.choices[0].delta.content:
|
| 364 |
+
token = message_chunk.choices[0].delta.content
|
| 365 |
+
response += token
|
| 366 |
+
yield response
|
| 367 |
+
except Exception as e:
|
| 368 |
+
# Provide demo response for local preview
|
| 369 |
+
demo_response = f"""
|
| 370 |
+
## π― Preview Mode Response
|
| 371 |
+
|
| 372 |
+
**Your Question:** {message}
|
| 373 |
+
|
| 374 |
+
**Mode:** {mode}
|
| 375 |
+
|
| 376 |
+
**Note:** This is a demo response for local preview. The AI chat will work fully once deployed to Hugging Face Spaces with authentication.
|
| 377 |
+
|
| 378 |
+
### What This Mode Does:
|
| 379 |
+
|
| 380 |
+
{system_message[:200]}...
|
| 381 |
+
|
| 382 |
+
### Features Available:
|
| 383 |
+
- β
UI and navigation fully functional
|
| 384 |
+
- β
All tabs working
|
| 385 |
+
- β
Watermark backgrounds active
|
| 386 |
+
- β
Logo rotation active
|
| 387 |
+
- β οΈ AI responses require HF deployment
|
| 388 |
+
|
| 389 |
+
**To test AI chat:** Deploy to Hugging Face Spaces where authentication is automatic.
|
| 390 |
+
|
| 391 |
+
---
|
| 392 |
+
|
| 393 |
+
**For now:** Test the visual design, tab navigation, dropdowns, and timing features!
|
| 394 |
+
"""
|
| 395 |
+
yield demo_response
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
# Custom CSS with watermark background logos
|
| 399 |
+
custom_css = """
|
| 400 |
+
.gradio-container {
|
| 401 |
+
max-width: 1200px !important;
|
| 402 |
+
position: relative;
|
| 403 |
+
}
|
| 404 |
+
|
| 405 |
+
/* Watermark background container */
|
| 406 |
+
.watermark-container {
|
| 407 |
+
position: fixed;
|
| 408 |
+
top: 0;
|
| 409 |
+
left: 0;
|
| 410 |
+
width: 100%;
|
| 411 |
+
height: 100%;
|
| 412 |
+
z-index: 0;
|
| 413 |
+
pointer-events: none;
|
| 414 |
+
overflow: hidden;
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
/* Watermark logo styling */
|
| 418 |
+
.watermark-logo {
|
| 419 |
+
position: absolute;
|
| 420 |
+
width: 300px;
|
| 421 |
+
height: 300px;
|
| 422 |
+
opacity: 0.08;
|
| 423 |
+
object-fit: contain;
|
| 424 |
+
transition: opacity 2s ease-in-out;
|
| 425 |
+
}
|
| 426 |
+
|
| 427 |
+
.watermark-logo.active {
|
| 428 |
+
opacity: 0.08;
|
| 429 |
+
}
|
| 430 |
+
|
| 431 |
+
.watermark-logo.hidden {
|
| 432 |
+
opacity: 0;
|
| 433 |
+
}
|
| 434 |
+
|
| 435 |
+
/* Position watermarks at different locations */
|
| 436 |
+
.watermark-1 {
|
| 437 |
+
top: 10%;
|
| 438 |
+
left: 10%;
|
| 439 |
+
transform: rotate(-15deg);
|
| 440 |
+
}
|
| 441 |
+
|
| 442 |
+
.watermark-2 {
|
| 443 |
+
top: 15%;
|
| 444 |
+
right: 15%;
|
| 445 |
+
transform: rotate(20deg);
|
| 446 |
+
}
|
| 447 |
+
|
| 448 |
+
.watermark-3 {
|
| 449 |
+
bottom: 20%;
|
| 450 |
+
left: 15%;
|
| 451 |
+
transform: rotate(10deg);
|
| 452 |
+
}
|
| 453 |
+
|
| 454 |
+
.watermark-4 {
|
| 455 |
+
bottom: 15%;
|
| 456 |
+
right: 10%;
|
| 457 |
+
transform: rotate(-20deg);
|
| 458 |
+
}
|
| 459 |
+
|
| 460 |
+
.watermark-5 {
|
| 461 |
+
top: 50%;
|
| 462 |
+
left: 50%;
|
| 463 |
+
transform: translate(-50%, -50%) rotate(-5deg);
|
| 464 |
+
}
|
| 465 |
+
|
| 466 |
+
/* Ensure content is above watermarks */
|
| 467 |
+
.gradio-container > * {
|
| 468 |
+
position: relative;
|
| 469 |
+
z-index: 1;
|
| 470 |
+
}
|
| 471 |
+
|
| 472 |
+
.header-section {
|
| 473 |
+
text-align: center;
|
| 474 |
+
padding: 40px 20px;
|
| 475 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 476 |
+
color: white;
|
| 477 |
+
border-radius: 12px;
|
| 478 |
+
margin-bottom: 30px;
|
| 479 |
+
position: relative;
|
| 480 |
+
z-index: 2;
|
| 481 |
+
}
|
| 482 |
+
|
| 483 |
+
.logo-container {
|
| 484 |
+
margin-bottom: 20px;
|
| 485 |
+
display: flex;
|
| 486 |
+
justify-content: center;
|
| 487 |
+
align-items: center;
|
| 488 |
+
}
|
| 489 |
+
|
| 490 |
+
.rotating-logo {
|
| 491 |
+
width: 150px;
|
| 492 |
+
height: 150px;
|
| 493 |
+
border-radius: 50%;
|
| 494 |
+
object-fit: cover;
|
| 495 |
+
border: 4px solid rgba(255, 255, 255, 0.8);
|
| 496 |
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
|
| 497 |
+
}
|
| 498 |
+
|
| 499 |
+
.header-section h1 {
|
| 500 |
+
font-size: 3rem;
|
| 501 |
+
margin-bottom: 10px;
|
| 502 |
+
font-weight: 700;
|
| 503 |
+
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
|
| 504 |
+
}
|
| 505 |
+
|
| 506 |
+
/* Make sure tabs and content are above watermarks */
|
| 507 |
+
.tabs, .tabitem {
|
| 508 |
+
position: relative;
|
| 509 |
+
z-index: 1;
|
| 510 |
+
}
|
| 511 |
+
"""
|
| 512 |
+
|
| 513 |
+
# JavaScript for rotating logos in header and random watermarks
|
| 514 |
+
rotating_logo_js = """
|
| 515 |
+
<script>
|
| 516 |
+
// Header logo rotation
|
| 517 |
+
function rotateHeaderLogo() {
|
| 518 |
+
const logos = document.querySelectorAll('.rotating-logo');
|
| 519 |
+
let currentIndex = 0;
|
| 520 |
+
|
| 521 |
+
function showNextLogo() {
|
| 522 |
+
logos.forEach((logo, index) => {
|
| 523 |
+
logo.style.display = 'none';
|
| 524 |
+
});
|
| 525 |
+
if (logos.length > 0) {
|
| 526 |
+
logos[currentIndex].style.display = 'block';
|
| 527 |
+
currentIndex = (currentIndex + 1) % logos.length;
|
| 528 |
+
}
|
| 529 |
+
}
|
| 530 |
+
|
| 531 |
+
showNextLogo();
|
| 532 |
+
setInterval(showNextLogo, 60000);
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
// Random watermark rotation
|
| 536 |
+
function rotateWatermarks() {
|
| 537 |
+
const watermarks = document.querySelectorAll('.watermark-logo');
|
| 538 |
+
const logoImages = [
|
| 539 |
+
'file/assets/logo_1.jpg',
|
| 540 |
+
'file/assets/logo_2.jpg',
|
| 541 |
+
'file/assets/logo_3.jpg'
|
| 542 |
+
];
|
| 543 |
+
|
| 544 |
+
function randomizeWatermarks() {
|
| 545 |
+
watermarks.forEach((watermark) => {
|
| 546 |
+
// Fade out
|
| 547 |
+
watermark.classList.remove('active');
|
| 548 |
+
watermark.classList.add('hidden');
|
| 549 |
+
|
| 550 |
+
setTimeout(() => {
|
| 551 |
+
// Pick random logo
|
| 552 |
+
const randomLogo = logoImages[Math.floor(Math.random() * logoImages.length)];
|
| 553 |
+
watermark.src = randomLogo;
|
| 554 |
+
|
| 555 |
+
// Fade in
|
| 556 |
+
watermark.classList.remove('hidden');
|
| 557 |
+
watermark.classList.add('active');
|
| 558 |
+
}, 2000);
|
| 559 |
+
});
|
| 560 |
+
}
|
| 561 |
+
|
| 562 |
+
// Initial randomization
|
| 563 |
+
randomizeWatermarks();
|
| 564 |
+
|
| 565 |
+
// Change watermarks every 30 seconds with random logos
|
| 566 |
+
setInterval(randomizeWatermarks, 30000);
|
| 567 |
+
}
|
| 568 |
+
|
| 569 |
+
// Initialize both rotations
|
| 570 |
+
if (document.readyState === 'loading') {
|
| 571 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 572 |
+
rotateHeaderLogo();
|
| 573 |
+
rotateWatermarks();
|
| 574 |
+
});
|
| 575 |
+
} else {
|
| 576 |
+
rotateHeaderLogo();
|
| 577 |
+
rotateWatermarks();
|
| 578 |
+
}
|
| 579 |
+
</script>
|
| 580 |
+
"""
|
| 581 |
+
|
| 582 |
+
# Create the main application
|
| 583 |
+
demo = gr.Blocks(title="ProVerBs Legal AI Platform")
|
| 584 |
+
|
| 585 |
+
with demo:
|
| 586 |
+
|
| 587 |
+
# Watermark background logos
|
| 588 |
+
gr.HTML(f"""
|
| 589 |
+
<div class="watermark-container">
|
| 590 |
+
<img src="file/assets/logo_1.jpg" class="watermark-logo watermark-1 active" alt="Watermark 1">
|
| 591 |
+
<img src="file/assets/logo_2.jpg" class="watermark-logo watermark-2 active" alt="Watermark 2">
|
| 592 |
+
<img src="file/assets/logo_3.jpg" class="watermark-logo watermark-3 active" alt="Watermark 3">
|
| 593 |
+
<img src="file/assets/logo_1.jpg" class="watermark-logo watermark-4 active" alt="Watermark 4">
|
| 594 |
+
<img src="file/assets/logo_2.jpg" class="watermark-logo watermark-5 active" alt="Watermark 5">
|
| 595 |
+
</div>
|
| 596 |
+
|
| 597 |
+
<style>{custom_css}</style>
|
| 598 |
+
{rotating_logo_js}
|
| 599 |
+
|
| 600 |
+
<!-- Header with Rotating Logos -->
|
| 601 |
+
<div class="header-section">
|
| 602 |
+
<div class="logo-container">
|
| 603 |
+
<img src="file/assets/logo_1.jpg" class="rotating-logo" alt="Logo 1" style="display: block;">
|
| 604 |
+
<img src="file/assets/logo_2.jpg" class="rotating-logo" alt="Logo 2" style="display: none;">
|
| 605 |
+
<img src="file/assets/logo_3.jpg" class="rotating-logo" alt="Logo 3" style="display: none;">
|
| 606 |
+
</div>
|
| 607 |
+
<h1>βοΈ ProVerBs Legal AI Platform</h1>
|
| 608 |
+
<p>Lawful vs. Legal: Dual Analysis "Adappt'plication"</p>
|
| 609 |
+
<p style="font-size: 1rem; margin-top: 10px;">
|
| 610 |
+
Multi-AI Legal System | 5 AI Models Working Together π
|
| 611 |
+
</p>
|
| 612 |
+
</div>
|
| 613 |
+
""")
|
| 614 |
+
|
| 615 |
+
gr.Markdown("---")
|
| 616 |
+
|
| 617 |
+
# Main Tabs
|
| 618 |
+
with gr.Tabs():
|
| 619 |
+
|
| 620 |
+
# Tab 1: Welcome
|
| 621 |
+
with gr.Tab("π Welcome"):
|
| 622 |
+
gr.Markdown("""
|
| 623 |
+
## Welcome to ProVerBs Legal AI Platform
|
| 624 |
+
|
| 625 |
+
### π€ 5 AI Models Integrated:
|
| 626 |
+
|
| 627 |
+
1. **DeepSeek-OCR** - Extract text from scanned documents
|
| 628 |
+
2. **ERNIE-4.5-VL** - Advanced vision-language understanding
|
| 629 |
+
3. **OpenAI GDPVAL** - Legal knowledge dataset
|
| 630 |
+
4. **Meta Llama 3.3** - General AI assistance
|
| 631 |
+
5. **MiniMax-M2** - Advanced text generation
|
| 632 |
+
|
| 633 |
+
### βοΈ 7 Specialized Modes:
|
| 634 |
+
|
| 635 |
+
- π Navigation Guide
|
| 636 |
+
- π¬ General Legal Assistant (with GDPVAL)
|
| 637 |
+
- π Document Validator (OCR + Vision AI)
|
| 638 |
+
- π Legal Research (GDPVAL-powered)
|
| 639 |
+
- π Etymology Expert
|
| 640 |
+
- πΌ Case Management
|
| 641 |
+
- π Regulatory Updates
|
| 642 |
+
|
| 643 |
+
### β¨ Unique Features:
|
| 644 |
+
|
| 645 |
+
- **Multi-AI Document Analysis**: Combines OCR + Vision AI
|
| 646 |
+
- **Legal Knowledge Base**: Access to GDPVAL dataset
|
| 647 |
+
- **Rotating Custom Logos**: Your professional branding
|
| 648 |
+
- **Complete Legal Solution**: All-in-one platform
|
| 649 |
+
""")
|
| 650 |
+
|
| 651 |
+
# Tab 2: AI Legal Chatbot
|
| 652 |
+
with gr.Tab("π€ AI Legal Chatbot"):
|
| 653 |
+
gr.Markdown("""
|
| 654 |
+
## Multi-AI Legal Chatbot
|
| 655 |
+
|
| 656 |
+
**Powered by 5 AI Models** for comprehensive legal assistance!
|
| 657 |
+
|
| 658 |
+
**Choose Your AI Model:**
|
| 659 |
+
- **Meta Llama 3.3** - Fast, efficient, streaming responses
|
| 660 |
+
- **MiniMax-M2** - Advanced text generation capabilities
|
| 661 |
+
""")
|
| 662 |
+
|
| 663 |
+
mode_selector = gr.Dropdown(
|
| 664 |
+
choices=[
|
| 665 |
+
"navigation",
|
| 666 |
+
"general",
|
| 667 |
+
"document_validation",
|
| 668 |
+
"legal_research",
|
| 669 |
+
"etymology",
|
| 670 |
+
"case_management",
|
| 671 |
+
"regulatory_updates"
|
| 672 |
+
],
|
| 673 |
+
value="navigation",
|
| 674 |
+
label="Select AI Assistant Mode"
|
| 675 |
+
)
|
| 676 |
+
|
| 677 |
+
model_selector = gr.Dropdown(
|
| 678 |
+
choices=[
|
| 679 |
+
"Meta Llama 3.3",
|
| 680 |
+
"MiniMax-M2"
|
| 681 |
+
],
|
| 682 |
+
value="Meta Llama 3.3",
|
| 683 |
+
label="Select AI Model"
|
| 684 |
+
)
|
| 685 |
+
|
| 686 |
+
gr.Markdown("---")
|
| 687 |
+
|
| 688 |
+
chatbot = gr.ChatInterface(
|
| 689 |
+
respond_with_mode,
|
| 690 |
+
chatbot=gr.Chatbot(height=500),
|
| 691 |
+
additional_inputs=[
|
| 692 |
+
mode_selector,
|
| 693 |
+
model_selector,
|
| 694 |
+
gr.Slider(128, 4096, value=2048, label="Max Tokens"),
|
| 695 |
+
gr.Slider(0.1, 2.0, value=0.7, label="Temperature"),
|
| 696 |
+
gr.Slider(0.1, 1.0, value=0.95, label="Top-p"),
|
| 697 |
+
],
|
| 698 |
+
examples=[
|
| 699 |
+
["How do I use the multi-AI document analysis?"],
|
| 700 |
+
["Search GDPVAL for contract law information"],
|
| 701 |
+
["Analyze a document with vision AI"],
|
| 702 |
+
],
|
| 703 |
+
)
|
| 704 |
+
|
| 705 |
+
# Tab 3: Document Analysis (NEW!)
|
| 706 |
+
with gr.Tab("π Document Analysis"):
|
| 707 |
+
gr.Markdown("""
|
| 708 |
+
## π Document Upload & AI Analysis
|
| 709 |
+
|
| 710 |
+
Upload legal documents for comprehensive AI analysis!
|
| 711 |
+
""")
|
| 712 |
+
|
| 713 |
+
with gr.Row():
|
| 714 |
+
with gr.Column(scale=1):
|
| 715 |
+
doc_upload = gr.File(
|
| 716 |
+
label="π Upload Document",
|
| 717 |
+
file_types=[".pdf", ".jpg", ".jpeg", ".png", ".txt"]
|
| 718 |
+
)
|
| 719 |
+
|
| 720 |
+
analysis_type = gr.Radio(
|
| 721 |
+
choices=[
|
| 722 |
+
"Complete Analysis",
|
| 723 |
+
"OCR Only",
|
| 724 |
+
"Visual Only",
|
| 725 |
+
"Legal Validation"
|
| 726 |
+
],
|
| 727 |
+
value="Complete Analysis",
|
| 728 |
+
label="Analysis Type"
|
| 729 |
+
)
|
| 730 |
+
|
| 731 |
+
analyze_btn = gr.Button("π Analyze", variant="primary", size="lg")
|
| 732 |
+
|
| 733 |
+
with gr.Column(scale=2):
|
| 734 |
+
analysis_output = gr.Markdown("Upload a document to begin analysis.")
|
| 735 |
+
|
| 736 |
+
def analyze_doc(file_path, analysis_type):
|
| 737 |
+
if not file_path:
|
| 738 |
+
return "β οΈ Please upload a document first."
|
| 739 |
+
|
| 740 |
+
filename = file_path.split('/')[-1] if '/' in file_path else file_path.split('\\')[-1]
|
| 741 |
+
|
| 742 |
+
return f"""
|
| 743 |
+
## π Document Analysis Results
|
| 744 |
+
|
| 745 |
+
**File:** {filename}
|
| 746 |
+
**Analysis Type:** {analysis_type}
|
| 747 |
+
|
| 748 |
+
### β οΈ Preview Mode
|
| 749 |
+
|
| 750 |
+
**What happens in production:**
|
| 751 |
+
- **DeepSeek-OCR** extracts text from images
|
| 752 |
+
- **ERNIE-4.5-VL** analyzes document structure
|
| 753 |
+
- **Legal AI** validates completeness
|
| 754 |
+
|
| 755 |
+
**Demo Output:**
|
| 756 |
+
- Document uploaded successfully β
|
| 757 |
+
- File format supported β
|
| 758 |
+
- Ready for AI analysis β
|
| 759 |
+
|
| 760 |
+
**Note:** Full analysis available after HF deployment.
|
| 761 |
+
|
| 762 |
+
**Try it:** Upload any legal document (PDF, image, text) to see the interface!
|
| 763 |
+
"""
|
| 764 |
+
|
| 765 |
+
analyze_btn.click(
|
| 766 |
+
fn=analyze_doc,
|
| 767 |
+
inputs=[doc_upload, analysis_type],
|
| 768 |
+
outputs=analysis_output
|
| 769 |
+
)
|
| 770 |
+
|
| 771 |
+
# Tab 4: Features
|
| 772 |
+
with gr.Tab("β¨ Features"):
|
| 773 |
+
gr.Markdown("""
|
| 774 |
+
## Advanced AI Features
|
| 775 |
+
|
| 776 |
+
### π€ Integrated AI Models:
|
| 777 |
+
|
| 778 |
+
1. **DeepSeek-OCR**
|
| 779 |
+
- Text extraction from images
|
| 780 |
+
- Document scanning
|
| 781 |
+
- High accuracy OCR
|
| 782 |
+
|
| 783 |
+
2. **ERNIE-4.5-VL** (Baidu)
|
| 784 |
+
- Vision-language understanding
|
| 785 |
+
- Document layout analysis
|
| 786 |
+
- Visual question answering
|
| 787 |
+
|
| 788 |
+
3. **OpenAI GDPVAL**
|
| 789 |
+
- Legal knowledge dataset
|
| 790 |
+
- Case law and precedents
|
| 791 |
+
- Regulatory information
|
| 792 |
+
|
| 793 |
+
4. **Meta Llama 3.3**
|
| 794 |
+
- General AI assistance
|
| 795 |
+
- Legal reasoning
|
| 796 |
+
- Natural conversation
|
| 797 |
+
|
| 798 |
+
5. **MiniMax-M2** β NEW!
|
| 799 |
+
- Advanced text generation
|
| 800 |
+
- High-quality responses
|
| 801 |
+
- Alternative AI model option
|
| 802 |
+
|
| 803 |
+
### π― What This Means:
|
| 804 |
+
|
| 805 |
+
- **Most Advanced**: 5 AI models working together
|
| 806 |
+
- **Best Analysis**: Multiple AI perspectives
|
| 807 |
+
- **Model Choice**: Select the best AI for your task
|
| 808 |
+
- **Comprehensive**: Text + Vision + Knowledge
|
| 809 |
+
- **Professional**: Your custom branding with logos
|
| 810 |
+
""")
|
| 811 |
+
|
| 812 |
+
# Tab 4: About
|
| 813 |
+
with gr.Tab("βΉοΈ About"):
|
| 814 |
+
gr.Markdown("""
|
| 815 |
+
## About ProVerBs Legal AI - Complete Edition
|
| 816 |
+
|
| 817 |
+
### π Version 2.1.0 - Complete Multi-AI Integration
|
| 818 |
+
|
| 819 |
+
**This is the most advanced version** with all AI capabilities:
|
| 820 |
+
|
| 821 |
+
- β
7 Specialized AI Modes
|
| 822 |
+
- β
3 Rotating Custom Logos
|
| 823 |
+
- β
DeepSeek-OCR Integration
|
| 824 |
+
- β
ERNIE-4.5-VL Vision AI
|
| 825 |
+
- β
OpenAI GDPVAL Dataset
|
| 826 |
+
- β
Meta Llama 3.3 AI
|
| 827 |
+
- β
MiniMax-M2 AI β NEW!
|
| 828 |
+
|
| 829 |
+
### π Technical Stack:
|
| 830 |
+
|
| 831 |
+
- **Frontend**: Gradio 4.x
|
| 832 |
+
- **OCR**: DeepSeek-OCR
|
| 833 |
+
- **Vision**: ERNIE-4.5-VL-28B
|
| 834 |
+
- **Dataset**: OpenAI GDPVAL
|
| 835 |
+
- **LLM 1**: Meta Llama 3.3-70B
|
| 836 |
+
- **LLM 2**: MiniMax-M2
|
| 837 |
+
- **Platform**: Hugging Face Spaces
|
| 838 |
+
|
| 839 |
+
### β οΈ Disclaimer:
|
| 840 |
+
|
| 841 |
+
This platform provides general legal information only.
|
| 842 |
+
Always consult with a qualified attorney for specific legal matters.
|
| 843 |
+
|
| 844 |
+
---
|
| 845 |
+
|
| 846 |
+
**Version 2.1.0** | Built by Solomon7890 | 5-Model AI Legal Platform
|
| 847 |
+
""")
|
| 848 |
+
|
| 849 |
+
# Footer
|
| 850 |
+
gr.Markdown("""
|
| 851 |
+
---
|
| 852 |
+
<div style="text-align: center; padding: 20px;">
|
| 853 |
+
<p><strong>βοΈ ProVerBs Legal AI Platform</strong> | Version 2.1.0 - 5-Model AI Edition</p>
|
| 854 |
+
<p>Powered by: DeepSeek-OCR β’ ERNIE-4.5-VL β’ GDPVAL β’ Llama 3.3 β’ MiniMax-M2</p>
|
| 855 |
+
<p>Β© 2024 ProVerBs Legal AI</p>
|
| 856 |
+
</div>
|
| 857 |
+
""")
|
| 858 |
+
|
| 859 |
+
if __name__ == "__main__":
|
| 860 |
+
demo.queue(max_size=20)
|
| 861 |
+
demo.launch(
|
| 862 |
+
server_name="0.0.0.0",
|
| 863 |
+
server_port=7860,
|
| 864 |
+
share=False,
|
| 865 |
+
show_error=True
|
| 866 |
+
)
|
deploy_to_hf.py
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Deployment Script for ProVerBs Landing Page
|
| 3 |
+
Deploys to Solomon7890/ProVerbS_LaW_mAiN_PAgE
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import subprocess
|
| 7 |
+
import sys
|
| 8 |
+
import os
|
| 9 |
+
|
| 10 |
+
def print_banner():
|
| 11 |
+
print("="*60)
|
| 12 |
+
print("π ProVerBs Legal AI - Landing Page Deployment")
|
| 13 |
+
print("="*60)
|
| 14 |
+
print()
|
| 15 |
+
|
| 16 |
+
def check_login():
|
| 17 |
+
"""Check if user is logged in to Hugging Face"""
|
| 18 |
+
print("π Checking Hugging Face authentication...")
|
| 19 |
+
try:
|
| 20 |
+
result = subprocess.run(['huggingface-cli', 'whoami'],
|
| 21 |
+
capture_output=True, text=True)
|
| 22 |
+
if result.returncode == 0:
|
| 23 |
+
username = result.stdout.strip().split('\n')[0].replace('username: ', '')
|
| 24 |
+
print(f" β
Logged in as: {username}")
|
| 25 |
+
return username
|
| 26 |
+
else:
|
| 27 |
+
print(" β Not logged in")
|
| 28 |
+
return None
|
| 29 |
+
except Exception as e:
|
| 30 |
+
print(f" β Error: {e}")
|
| 31 |
+
return None
|
| 32 |
+
|
| 33 |
+
def login_hf():
|
| 34 |
+
"""Login to Hugging Face"""
|
| 35 |
+
print("\nπ Please login to Hugging Face...")
|
| 36 |
+
print("Token: https://huggingface.co/settings/tokens\n")
|
| 37 |
+
try:
|
| 38 |
+
subprocess.run(['huggingface-cli', 'login'])
|
| 39 |
+
return check_login()
|
| 40 |
+
except Exception as e:
|
| 41 |
+
print(f"β Login failed: {e}")
|
| 42 |
+
return None
|
| 43 |
+
|
| 44 |
+
def deploy_space():
|
| 45 |
+
"""Deploy to the Space"""
|
| 46 |
+
space_name = "Solomon7890/ProVerbS_LaW_mAiN_PAgE"
|
| 47 |
+
print(f"\nπ€ Deploying to: {space_name}")
|
| 48 |
+
print("="*60)
|
| 49 |
+
|
| 50 |
+
try:
|
| 51 |
+
# Check if git is initialized
|
| 52 |
+
if not os.path.exists('.git'):
|
| 53 |
+
print("π¦ Initializing git repository...")
|
| 54 |
+
subprocess.run(['git', 'init'], check=True)
|
| 55 |
+
|
| 56 |
+
# Add remote if not exists
|
| 57 |
+
print("π Setting up remote...")
|
| 58 |
+
subprocess.run(
|
| 59 |
+
['git', 'remote', 'add', 'space', f'https://huggingface.co/spaces/{space_name}'],
|
| 60 |
+
capture_output=True
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
# Set remote URL (in case it already exists)
|
| 64 |
+
subprocess.run(
|
| 65 |
+
['git', 'remote', 'set-url', 'space', f'https://huggingface.co/spaces/{space_name}'],
|
| 66 |
+
capture_output=True
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
# Replace app.py with enhanced version
|
| 70 |
+
print("π Updating app.py with enhanced version...")
|
| 71 |
+
if os.path.exists('enhanced_app.py'):
|
| 72 |
+
import shutil
|
| 73 |
+
shutil.copy('enhanced_app.py', 'app.py')
|
| 74 |
+
print(" β
Enhanced app.py deployed")
|
| 75 |
+
|
| 76 |
+
# Add files
|
| 77 |
+
print("π Adding files...")
|
| 78 |
+
subprocess.run(['git', 'add', 'app.py', 'README.md', '.gitattributes'], check=True)
|
| 79 |
+
|
| 80 |
+
# Commit
|
| 81 |
+
print("πΎ Creating commit...")
|
| 82 |
+
subprocess.run(
|
| 83 |
+
['git', 'commit', '-m', 'Deploy enhanced ProVerBs Legal AI landing page'],
|
| 84 |
+
capture_output=True
|
| 85 |
+
)
|
| 86 |
+
|
| 87 |
+
# Push
|
| 88 |
+
print("π Pushing to Hugging Face...")
|
| 89 |
+
result = subprocess.run(
|
| 90 |
+
['git', 'push', 'space', 'main', '-f'],
|
| 91 |
+
capture_output=True,
|
| 92 |
+
text=True
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
+
if result.returncode != 0:
|
| 96 |
+
# Try master branch
|
| 97 |
+
result = subprocess.run(
|
| 98 |
+
['git', 'push', 'space', 'master', '-f'],
|
| 99 |
+
capture_output=True,
|
| 100 |
+
text=True
|
| 101 |
+
)
|
| 102 |
+
|
| 103 |
+
if "Everything up-to-date" in result.stderr or result.returncode == 0:
|
| 104 |
+
print(" β
Deployment successful!")
|
| 105 |
+
return True
|
| 106 |
+
else:
|
| 107 |
+
print(" β οΈ Push completed with warnings")
|
| 108 |
+
return True
|
| 109 |
+
|
| 110 |
+
except Exception as e:
|
| 111 |
+
print(f" β Error: {e}")
|
| 112 |
+
return False
|
| 113 |
+
|
| 114 |
+
def main():
|
| 115 |
+
print_banner()
|
| 116 |
+
|
| 117 |
+
# Check login
|
| 118 |
+
username = check_login()
|
| 119 |
+
if not username:
|
| 120 |
+
username = login_hf()
|
| 121 |
+
if not username:
|
| 122 |
+
print("\nβ Deployment cancelled - login required")
|
| 123 |
+
return
|
| 124 |
+
|
| 125 |
+
# Confirm deployment
|
| 126 |
+
space_url = "https://huggingface.co/spaces/Solomon7890/ProVerbS_LaW_mAiN_PAgE"
|
| 127 |
+
print(f"\nπ Deployment Target:")
|
| 128 |
+
print(f" Space: Solomon7890/ProVerbS_LaW_mAiN_PAgE")
|
| 129 |
+
print(f" URL: {space_url}")
|
| 130 |
+
print()
|
| 131 |
+
|
| 132 |
+
confirm = input("Deploy enhanced landing page now? (y/n): ").strip().lower()
|
| 133 |
+
if confirm != 'y':
|
| 134 |
+
print("\nβ Deployment cancelled")
|
| 135 |
+
return
|
| 136 |
+
|
| 137 |
+
# Deploy
|
| 138 |
+
if deploy_space():
|
| 139 |
+
print("\n" + "="*60)
|
| 140 |
+
print("β
DEPLOYMENT SUCCESSFUL!")
|
| 141 |
+
print("="*60)
|
| 142 |
+
print()
|
| 143 |
+
print(f"π Your Space is available at:")
|
| 144 |
+
print(f" {space_url}")
|
| 145 |
+
print()
|
| 146 |
+
print("β³ The Space is now building. This may take 2-3 minutes.")
|
| 147 |
+
print()
|
| 148 |
+
print("π Next steps:")
|
| 149 |
+
print(" 1. Visit your Space URL")
|
| 150 |
+
print(" 2. Wait for the build to complete")
|
| 151 |
+
print(" 3. Test all features")
|
| 152 |
+
print(" 4. Share with your audience!")
|
| 153 |
+
print()
|
| 154 |
+
print("="*60)
|
| 155 |
+
else:
|
| 156 |
+
print("\nβ Deployment failed. Please check the errors above.")
|
| 157 |
+
|
| 158 |
+
if __name__ == "__main__":
|
| 159 |
+
try:
|
| 160 |
+
main()
|
| 161 |
+
except KeyboardInterrupt:
|
| 162 |
+
print("\n\nβ Deployment cancelled by user")
|
| 163 |
+
except Exception as e:
|
| 164 |
+
print(f"\n\nβ Unexpected error: {e}")
|
enhanced_app.py
ADDED
|
@@ -0,0 +1,352 @@
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
ProVerBs Legal AI - Enhanced Landing Page
|
| 3 |
+
Multi-Module Legal AI Platform with Professional UI
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import gradio as gr
|
| 7 |
+
from huggingface_hub import InferenceClient
|
| 8 |
+
|
| 9 |
+
def respond(
|
| 10 |
+
message,
|
| 11 |
+
history: list[dict[str, str]],
|
| 12 |
+
system_message,
|
| 13 |
+
max_tokens,
|
| 14 |
+
temperature,
|
| 15 |
+
top_p,
|
| 16 |
+
hf_token: gr.OAuthToken,
|
| 17 |
+
):
|
| 18 |
+
"""
|
| 19 |
+
Main chat response function with AI integration
|
| 20 |
+
"""
|
| 21 |
+
client = InferenceClient(token=hf_token.token, model="meta-llama/Llama-3.3-70B-Instruct")
|
| 22 |
+
|
| 23 |
+
messages = [{"role": "system", "content": system_message}]
|
| 24 |
+
messages.extend(history)
|
| 25 |
+
messages.append({"role": "user", "content": message})
|
| 26 |
+
|
| 27 |
+
response = ""
|
| 28 |
+
for message in client.chat_completion(
|
| 29 |
+
messages,
|
| 30 |
+
max_tokens=max_tokens,
|
| 31 |
+
stream=True,
|
| 32 |
+
temperature=temperature,
|
| 33 |
+
top_p=top_p,
|
| 34 |
+
):
|
| 35 |
+
choices = message.choices
|
| 36 |
+
token = ""
|
| 37 |
+
if len(choices) and choices[0].delta.content:
|
| 38 |
+
token = choices[0].delta.content
|
| 39 |
+
response += token
|
| 40 |
+
yield response
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
# Custom CSS for professional styling
|
| 44 |
+
custom_css = """
|
| 45 |
+
.gradio-container {
|
| 46 |
+
max-width: 1200px !important;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
.header-section {
|
| 50 |
+
text-align: center;
|
| 51 |
+
padding: 40px 20px;
|
| 52 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 53 |
+
color: white;
|
| 54 |
+
border-radius: 12px;
|
| 55 |
+
margin-bottom: 30px;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
.header-section h1 {
|
| 59 |
+
font-size: 3rem;
|
| 60 |
+
margin-bottom: 10px;
|
| 61 |
+
font-weight: 700;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
.header-section p {
|
| 65 |
+
font-size: 1.2rem;
|
| 66 |
+
opacity: 0.95;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
.feature-card {
|
| 70 |
+
border: 2px solid #e0e0e0;
|
| 71 |
+
border-radius: 12px;
|
| 72 |
+
padding: 20px;
|
| 73 |
+
margin: 10px;
|
| 74 |
+
transition: all 0.3s;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
.feature-card:hover {
|
| 78 |
+
border-color: #667eea;
|
| 79 |
+
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
.tab-nav button {
|
| 83 |
+
font-size: 16px;
|
| 84 |
+
font-weight: 600;
|
| 85 |
+
}
|
| 86 |
+
"""
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
# Create the main application
|
| 90 |
+
with gr.Blocks(
|
| 91 |
+
theme=gr.themes.Soft(
|
| 92 |
+
primary_hue="purple",
|
| 93 |
+
secondary_hue="blue",
|
| 94 |
+
),
|
| 95 |
+
css=custom_css,
|
| 96 |
+
title="ProVerBs Legal AI Platform"
|
| 97 |
+
) as demo:
|
| 98 |
+
|
| 99 |
+
# Header Section
|
| 100 |
+
gr.HTML("""
|
| 101 |
+
<div class="header-section">
|
| 102 |
+
<h1>βοΈ ProVerBs Legal AI Platform</h1>
|
| 103 |
+
<p>Lawful vs. Legal: Dual Analysis "Adappt'plication"</p>
|
| 104 |
+
<p style="font-size: 1rem; margin-top: 10px;">
|
| 105 |
+
Professional Legal AI System | Multi-Module Platform | Powered by Advanced AI
|
| 106 |
+
</p>
|
| 107 |
+
</div>
|
| 108 |
+
""")
|
| 109 |
+
|
| 110 |
+
# Login Section
|
| 111 |
+
with gr.Row():
|
| 112 |
+
with gr.Column(scale=1):
|
| 113 |
+
gr.LoginButton(size="lg")
|
| 114 |
+
with gr.Column(scale=5):
|
| 115 |
+
gr.Markdown("π **Login with your Hugging Face account** for full access to premium features")
|
| 116 |
+
|
| 117 |
+
gr.Markdown("---")
|
| 118 |
+
|
| 119 |
+
# Main Content Tabs
|
| 120 |
+
with gr.Tabs() as tabs:
|
| 121 |
+
|
| 122 |
+
# Tab 1: Welcome & Overview
|
| 123 |
+
with gr.Tab("π Welcome", id="welcome"):
|
| 124 |
+
gr.Markdown("""
|
| 125 |
+
## Welcome to ProVerBs Legal AI Platform
|
| 126 |
+
|
| 127 |
+
A comprehensive legal AI system designed for legal professionals, researchers, and individuals
|
| 128 |
+
seeking legal information. Our platform combines multiple AI models and specialized tools to
|
| 129 |
+
provide accurate, helpful legal assistance.
|
| 130 |
+
|
| 131 |
+
### π Key Features
|
| 132 |
+
|
| 133 |
+
- **π€ AI Legal Assistant**: Chat with advanced AI models trained on legal knowledge
|
| 134 |
+
- **π Document Analysis**: Process and analyze legal documents
|
| 135 |
+
- **πΌ Case Management**: Track and manage legal cases efficiently
|
| 136 |
+
- **π Legal Research**: Access vast databases of legal information
|
| 137 |
+
- **π‘οΈ Compliance Tools**: Ensure regulatory compliance
|
| 138 |
+
- **π Analytics Dashboard**: Visualize legal data and insights
|
| 139 |
+
|
| 140 |
+
### π― Our Mission
|
| 141 |
+
|
| 142 |
+
To democratize access to legal information and tools, making professional-grade legal AI
|
| 143 |
+
accessible to everyone while maintaining the highest standards of accuracy and reliability.
|
| 144 |
+
|
| 145 |
+
### β οΈ Important Disclaimer
|
| 146 |
+
|
| 147 |
+
This platform provides general legal information and AI-powered assistance. It does not
|
| 148 |
+
constitute legal advice. Always consult with a qualified attorney for specific legal matters.
|
| 149 |
+
|
| 150 |
+
---
|
| 151 |
+
|
| 152 |
+
**Ready to get started?** Click on the "Legal AI Assistant" tab to begin chatting!
|
| 153 |
+
""")
|
| 154 |
+
|
| 155 |
+
# Tab 2: Legal AI Assistant (Main Chat)
|
| 156 |
+
with gr.Tab("π€ Legal AI Assistant", id="assistant"):
|
| 157 |
+
gr.Markdown("""
|
| 158 |
+
## Legal AI Assistant
|
| 159 |
+
|
| 160 |
+
Ask questions about law, legal procedures, case analysis, or any legal topic.
|
| 161 |
+
Our AI assistant is here to help with accurate, contextual information.
|
| 162 |
+
""")
|
| 163 |
+
|
| 164 |
+
chatbot = gr.ChatInterface(
|
| 165 |
+
respond,
|
| 166 |
+
type="messages",
|
| 167 |
+
chatbot=gr.Chatbot(
|
| 168 |
+
height=500,
|
| 169 |
+
placeholder="π¬ Ask me anything about law, legal procedures, or case analysis...",
|
| 170 |
+
show_label=False,
|
| 171 |
+
),
|
| 172 |
+
textbox=gr.Textbox(
|
| 173 |
+
placeholder="Type your legal question here...",
|
| 174 |
+
container=False,
|
| 175 |
+
scale=7
|
| 176 |
+
),
|
| 177 |
+
additional_inputs=[
|
| 178 |
+
gr.Textbox(
|
| 179 |
+
value="You are ProVerBs Legal AI, a knowledgeable legal assistant specializing in law, legal procedures, and case analysis. Provide accurate, helpful information while noting that you cannot provide legal advice. Always recommend consulting with a licensed attorney for specific legal matters. Be professional, thorough, and cite relevant legal principles when possible.",
|
| 180 |
+
label="System Message",
|
| 181 |
+
lines=4
|
| 182 |
+
),
|
| 183 |
+
gr.Slider(
|
| 184 |
+
minimum=128,
|
| 185 |
+
maximum=4096,
|
| 186 |
+
value=2048,
|
| 187 |
+
step=128,
|
| 188 |
+
label="Max Tokens"
|
| 189 |
+
),
|
| 190 |
+
gr.Slider(
|
| 191 |
+
minimum=0.1,
|
| 192 |
+
maximum=2.0,
|
| 193 |
+
value=0.7,
|
| 194 |
+
step=0.1,
|
| 195 |
+
label="Temperature"
|
| 196 |
+
),
|
| 197 |
+
gr.Slider(
|
| 198 |
+
minimum=0.1,
|
| 199 |
+
maximum=1.0,
|
| 200 |
+
value=0.95,
|
| 201 |
+
step=0.05,
|
| 202 |
+
label="Top-p (nucleus sampling)"
|
| 203 |
+
),
|
| 204 |
+
],
|
| 205 |
+
examples=[
|
| 206 |
+
["What is the difference between civil law and criminal law?"],
|
| 207 |
+
["Explain the concept of 'burden of proof' in legal proceedings"],
|
| 208 |
+
["What are the essential elements of a valid contract?"],
|
| 209 |
+
["What is the statute of limitations and why is it important?"],
|
| 210 |
+
["Explain the difference between 'lawful' and 'legal'"],
|
| 211 |
+
],
|
| 212 |
+
cache_examples=False,
|
| 213 |
+
)
|
| 214 |
+
|
| 215 |
+
# Tab 3: Features Overview
|
| 216 |
+
with gr.Tab("β¨ Features", id="features"):
|
| 217 |
+
gr.Markdown("""
|
| 218 |
+
## Platform Features
|
| 219 |
+
|
| 220 |
+
### π― Core Capabilities
|
| 221 |
+
""")
|
| 222 |
+
|
| 223 |
+
with gr.Row():
|
| 224 |
+
with gr.Column():
|
| 225 |
+
gr.Markdown("""
|
| 226 |
+
#### π€ AI-Powered Assistance
|
| 227 |
+
- Multiple AI models (Llama, GPT, Qwen)
|
| 228 |
+
- Real-time streaming responses
|
| 229 |
+
- Context-aware conversations
|
| 230 |
+
- Legal knowledge base integration
|
| 231 |
+
""")
|
| 232 |
+
|
| 233 |
+
with gr.Column():
|
| 234 |
+
gr.Markdown("""
|
| 235 |
+
#### π Document Processing
|
| 236 |
+
- PDF, DOCX, TXT support
|
| 237 |
+
- Automatic text extraction
|
| 238 |
+
- Key terms identification
|
| 239 |
+
- Legal issue detection
|
| 240 |
+
""")
|
| 241 |
+
|
| 242 |
+
with gr.Row():
|
| 243 |
+
with gr.Column():
|
| 244 |
+
gr.Markdown("""
|
| 245 |
+
#### πΌ Case Management
|
| 246 |
+
- Track multiple cases
|
| 247 |
+
- Client information management
|
| 248 |
+
- Deadline tracking
|
| 249 |
+
- Status monitoring
|
| 250 |
+
""")
|
| 251 |
+
|
| 252 |
+
with gr.Column():
|
| 253 |
+
gr.Markdown("""
|
| 254 |
+
#### π Research Tools
|
| 255 |
+
- Case law search
|
| 256 |
+
- Statute lookup
|
| 257 |
+
- Legal precedent finder
|
| 258 |
+
- Citation generator
|
| 259 |
+
""")
|
| 260 |
+
|
| 261 |
+
gr.Markdown("""
|
| 262 |
+
---
|
| 263 |
+
|
| 264 |
+
### π Coming Soon
|
| 265 |
+
|
| 266 |
+
- **Advanced Analytics**: Visualize case trends and patterns
|
| 267 |
+
- **Multi-language Support**: Legal assistance in multiple languages
|
| 268 |
+
- **API Access**: Integrate with your existing tools
|
| 269 |
+
- **Team Collaboration**: Share workspaces with colleagues
|
| 270 |
+
- **Mobile App**: Access on the go
|
| 271 |
+
""")
|
| 272 |
+
|
| 273 |
+
# Tab 4: About & Resources
|
| 274 |
+
with gr.Tab("βΉοΈ About", id="about"):
|
| 275 |
+
gr.Markdown("""
|
| 276 |
+
## About ProVerBs Legal AI
|
| 277 |
+
|
| 278 |
+
### π Our Story
|
| 279 |
+
|
| 280 |
+
ProVerBs Legal AI is a cutting-edge platform that combines artificial intelligence with
|
| 281 |
+
legal expertise to provide accessible, accurate legal information and tools. We believe
|
| 282 |
+
that everyone deserves access to quality legal resources.
|
| 283 |
+
|
| 284 |
+
### π₯ For Everyone
|
| 285 |
+
|
| 286 |
+
- **Legal Professionals**: Enhance your practice with AI-powered tools
|
| 287 |
+
- **Law Students**: Study and research with advanced AI assistance
|
| 288 |
+
- **Businesses**: Understand legal implications of business decisions
|
| 289 |
+
- **Individuals**: Get information about your legal rights and options
|
| 290 |
+
|
| 291 |
+
### π Privacy & Security
|
| 292 |
+
|
| 293 |
+
We take your privacy seriously:
|
| 294 |
+
- End-to-end encryption for sensitive data
|
| 295 |
+
- No storage of personal information without consent
|
| 296 |
+
- GDPR and CCPA compliant
|
| 297 |
+
- Secure OAuth authentication via Hugging Face
|
| 298 |
+
|
| 299 |
+
### π Resources
|
| 300 |
+
|
| 301 |
+
- **Documentation**: [Read the Docs](https://huggingface.co/Solomon7890)
|
| 302 |
+
- **GitHub**: [Source Code](https://github.com/Solomon7890)
|
| 303 |
+
- **Community**: [Join our Discord](#)
|
| 304 |
+
- **Support**: [Contact Us](#)
|
| 305 |
+
|
| 306 |
+
### π€ Credits
|
| 307 |
+
|
| 308 |
+
Built with:
|
| 309 |
+
- [Gradio](https://gradio.app) - UI Framework
|
| 310 |
+
- [Hugging Face](https://huggingface.co) - AI Infrastructure
|
| 311 |
+
- [Meta Llama](https://llama.meta.com) - Language Models
|
| 312 |
+
|
| 313 |
+
### π License
|
| 314 |
+
|
| 315 |
+
This project is released under the Unlicense - free for any use.
|
| 316 |
+
|
| 317 |
+
---
|
| 318 |
+
|
| 319 |
+
**Version 1.0.0** | Last Updated: 2024 | Built by Solomon7890
|
| 320 |
+
""")
|
| 321 |
+
|
| 322 |
+
# Footer
|
| 323 |
+
gr.Markdown("""
|
| 324 |
+
---
|
| 325 |
+
|
| 326 |
+
<div style="text-align: center; padding: 20px; color: #666;">
|
| 327 |
+
<p><strong>βοΈ ProVerBs Legal AI Platform</strong> | Version 1.0.0</p>
|
| 328 |
+
<p>
|
| 329 |
+
<a href="https://huggingface.co/Solomon7890" target="_blank">Hugging Face</a> |
|
| 330 |
+
<a href="https://github.com/Solomon7890" target="_blank">GitHub</a> |
|
| 331 |
+
<a href="#" target="_blank">Documentation</a> |
|
| 332 |
+
<a href="#" target="_blank">Support</a>
|
| 333 |
+
</p>
|
| 334 |
+
<p style="font-size: 0.9rem; margin-top: 10px;">
|
| 335 |
+
β οΈ <strong>Disclaimer</strong>: This AI provides general legal information only.
|
| 336 |
+
It does not constitute legal advice. Consult with a licensed attorney for specific legal matters.
|
| 337 |
+
</p>
|
| 338 |
+
<p style="font-size: 0.85rem; color: #999; margin-top: 10px;">
|
| 339 |
+
Β© 2024 ProVerBs Legal AI. Built with β€οΈ for legal professionals worldwide.
|
| 340 |
+
</p>
|
| 341 |
+
</div>
|
| 342 |
+
""")
|
| 343 |
+
|
| 344 |
+
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
ProVerBs Legal AI - Integrated Landing Page with AI Legal Chatbot
|
| 3 |
+
Incorporates your specialized AI Legal Chatbot with multiple modes
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import gradio as gr
|
| 7 |
+
from huggingface_hub import InferenceClient
|
| 8 |
+
import json
|
| 9 |
+
import os
|
| 10 |
+
from datetime import datetime
|
| 11 |
+
from typing import Dict, List, Optional
|
| 12 |
+
|
| 13 |
+
class AILegalChatbotIntegration:
|
| 14 |
+
"""
|
| 15 |
+
Integration of your AI Legal Chatbot into Gradio
|
| 16 |
+
Supports all specialized modes from your original chatbot
|
| 17 |
+
"""
|
| 18 |
+
|
| 19 |
+
def __init__(self):
|
| 20 |
+
self.specialized_modes = {
|
| 21 |
+
"navigation": "Application Navigation Guide",
|
| 22 |
+
"general": "General Legal Assistant",
|
| 23 |
+
"document_validation": "Document Validator",
|
| 24 |
+
"legal_research": "Legal Research Assistant",
|
| 25 |
+
"etymology": "Legal Etymology Lookup",
|
| 26 |
+
"case_management": "Case Management Helper",
|
| 27 |
+
"regulatory_updates": "Regulatory Update Monitor"
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
# Application features from your original chatbot
|
| 31 |
+
self.app_features = {
|
| 32 |
+
"Legal Action Advisor": {
|
| 33 |
+
"description": "Get personalized recommendations for seeking justice and remedy",
|
| 34 |
+
"features": ["AI-powered action recommendations", "Case type analysis", "Timeline planning"]
|
| 35 |
+
},
|
| 36 |
+
"Document Analysis": {
|
| 37 |
+
"description": "Upload and analyze legal documents with AI-powered insights",
|
| 38 |
+
"features": ["OCR text extraction", "Multi-format support", "AI analysis"]
|
| 39 |
+
},
|
| 40 |
+
"Legal Research": {
|
| 41 |
+
"description": "Comprehensive legal research tools and databases",
|
| 42 |
+
"features": ["Multiple legal databases", "Case law research", "Statutory analysis"]
|
| 43 |
+
},
|
| 44 |
+
"Communications": {
|
| 45 |
+
"description": "Integrated communication system with SMS, email, and phone",
|
| 46 |
+
"features": ["Twilio integration", "Legal alerts", "Case reminders"]
|
| 47 |
+
},
|
| 48 |
+
"Document Generation": {
|
| 49 |
+
"description": "AI-powered legal document creation and templates",
|
| 50 |
+
"features": ["Smart templates", "Custom document builder", "Legal form generation"]
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
def get_mode_system_prompt(self, mode: str) -> str:
|
| 55 |
+
"""Get specialized system prompt based on mode"""
|
| 56 |
+
prompts = {
|
| 57 |
+
"navigation": """You are a ProVerBs Application Navigation Guide. Help users navigate the application's features:
|
| 58 |
+
|
| 59 |
+
**Available Features:**
|
| 60 |
+
- Legal Action Advisor: Get recommendations for seeking justice
|
| 61 |
+
- Document Analysis: Upload and analyze legal documents
|
| 62 |
+
- Legal Research: Access comprehensive legal databases
|
| 63 |
+
- Communications: SMS, email, and phone integration
|
| 64 |
+
- Document Generation: Create legal documents with AI
|
| 65 |
+
|
| 66 |
+
Guide users to the right features and explain how to use them effectively.""",
|
| 67 |
+
|
| 68 |
+
"general": """You are a General Legal Assistant for ProVerBs Legal AI Platform. Provide accurate legal information while noting that you cannot provide legal advice. Always recommend consulting with a licensed attorney for specific legal matters. Be professional, thorough, and cite relevant legal principles when possible.""",
|
| 69 |
+
|
| 70 |
+
"document_validation": """You are a Document Validator. Analyze legal documents for:
|
| 71 |
+
- Completeness and required elements
|
| 72 |
+
- Legal terminology accuracy
|
| 73 |
+
- Structural integrity
|
| 74 |
+
- Common issues and red flags
|
| 75 |
+
Provide specific feedback on document quality and validity.""",
|
| 76 |
+
|
| 77 |
+
"legal_research": """You are a Legal Research Assistant. Help users:
|
| 78 |
+
- Find relevant case law and precedents
|
| 79 |
+
- Understand statutes and regulations
|
| 80 |
+
- Research legal principles and concepts
|
| 81 |
+
- Cite authoritative legal sources
|
| 82 |
+
Provide comprehensive research guidance.""",
|
| 83 |
+
|
| 84 |
+
"etymology": """You are a Legal Etymology Expert. Explain the origins and meanings of legal terms:
|
| 85 |
+
- Latin and historical roots
|
| 86 |
+
- Evolution of legal terminology
|
| 87 |
+
- Modern usage and interpretation
|
| 88 |
+
- Related legal concepts
|
| 89 |
+
Make legal language accessible and understandable.""",
|
| 90 |
+
|
| 91 |
+
"case_management": """You are a Case Management Helper. Assist with:
|
| 92 |
+
- Organizing case information
|
| 93 |
+
- Tracking deadlines and milestones
|
| 94 |
+
- Managing documents and evidence
|
| 95 |
+
- Coordinating case activities
|
| 96 |
+
Provide practical case management advice.""",
|
| 97 |
+
|
| 98 |
+
"regulatory_updates": """You are a Regulatory Update Monitor. Keep users informed about:
|
| 99 |
+
- Recent legal and regulatory changes
|
| 100 |
+
- Industry-specific compliance updates
|
| 101 |
+
- Important legislative developments
|
| 102 |
+
- Impact analysis of new regulations
|
| 103 |
+
Provide timely and relevant regulatory information."""
|
| 104 |
+
}
|
| 105 |
+
return prompts.get(mode, prompts["general"])
|
| 106 |
+
|
| 107 |
+
def format_navigation_response(self, query: str) -> str:
|
| 108 |
+
"""Format response for navigation queries"""
|
| 109 |
+
query_lower = query.lower()
|
| 110 |
+
|
| 111 |
+
# Feature recommendations based on query
|
| 112 |
+
recommendations = []
|
| 113 |
+
|
| 114 |
+
if any(word in query_lower for word in ["document", "contract", "agreement", "analyze"]):
|
| 115 |
+
recommendations.append("π **Document Analysis** - Upload and analyze your documents")
|
| 116 |
+
|
| 117 |
+
if any(word in query_lower for word in ["research", "case", "law", "statute"]):
|
| 118 |
+
recommendations.append("π **Legal Research** - Access comprehensive legal databases")
|
| 119 |
+
|
| 120 |
+
if any(word in query_lower for word in ["action", "remedy", "justice", "sue"]):
|
| 121 |
+
recommendations.append("βοΈ **Legal Action Advisor** - Get recommendations for your situation")
|
| 122 |
+
|
| 123 |
+
if any(word in query_lower for word in ["create", "generate", "template", "form"]):
|
| 124 |
+
recommendations.append("π **Document Generation** - Create legal documents with AI")
|
| 125 |
+
|
| 126 |
+
if any(word in query_lower for word in ["communicate", "message", "sms", "email"]):
|
| 127 |
+
recommendations.append("π§ **Communications** - Integrated messaging system")
|
| 128 |
+
|
| 129 |
+
if recommendations:
|
| 130 |
+
return "### I can help you with these features:\n\n" + "\n".join(recommendations) + "\n\n**What would you like to explore?**"
|
| 131 |
+
|
| 132 |
+
return None
|
| 133 |
+
|
| 134 |
+
def respond_with_mode(
|
| 135 |
+
message,
|
| 136 |
+
history: list,
|
| 137 |
+
mode: str,
|
| 138 |
+
max_tokens: int,
|
| 139 |
+
temperature: float,
|
| 140 |
+
top_p: float,
|
| 141 |
+
hf_token: gr.OAuthToken | None = None
|
| 142 |
+
):
|
| 143 |
+
"""
|
| 144 |
+
Generate AI response based on selected mode
|
| 145 |
+
"""
|
| 146 |
+
chatbot_integration = AILegalChatbotIntegration()
|
| 147 |
+
|
| 148 |
+
# Get mode-specific system prompt
|
| 149 |
+
system_message = chatbot_integration.get_mode_system_prompt(mode)
|
| 150 |
+
|
| 151 |
+
# Check for navigation-specific responses
|
| 152 |
+
if mode == "navigation":
|
| 153 |
+
nav_response = chatbot_integration.format_navigation_response(message)
|
| 154 |
+
if nav_response:
|
| 155 |
+
yield nav_response
|
| 156 |
+
return
|
| 157 |
+
|
| 158 |
+
# Use HF Inference API
|
| 159 |
+
token = hf_token.token if hf_token else None
|
| 160 |
+
client = InferenceClient(token=token, model="meta-llama/Llama-3.3-70B-Instruct")
|
| 161 |
+
|
| 162 |
+
# Prepare messages
|
| 163 |
+
messages = [{"role": "system", "content": system_message}]
|
| 164 |
+
|
| 165 |
+
for user_msg, assistant_msg in history:
|
| 166 |
+
if user_msg:
|
| 167 |
+
messages.append({"role": "user", "content": user_msg})
|
| 168 |
+
if assistant_msg:
|
| 169 |
+
messages.append({"role": "assistant", "content": assistant_msg})
|
| 170 |
+
|
| 171 |
+
messages.append({"role": "user", "content": message})
|
| 172 |
+
|
| 173 |
+
# Stream response
|
| 174 |
+
response = ""
|
| 175 |
+
try:
|
| 176 |
+
for message_chunk in client.chat_completion(
|
| 177 |
+
messages,
|
| 178 |
+
max_tokens=max_tokens,
|
| 179 |
+
stream=True,
|
| 180 |
+
temperature=temperature,
|
| 181 |
+
top_p=top_p,
|
| 182 |
+
):
|
| 183 |
+
if message_chunk.choices and message_chunk.choices[0].delta.content:
|
| 184 |
+
token = message_chunk.choices[0].delta.content
|
| 185 |
+
response += token
|
| 186 |
+
yield response
|
| 187 |
+
except Exception as e:
|
| 188 |
+
yield f"Error: {str(e)}"
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
# Custom CSS
|
| 192 |
+
custom_css = """
|
| 193 |
+
.gradio-container {
|
| 194 |
+
max-width: 1200px !important;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
.header-section {
|
| 198 |
+
text-align: center;
|
| 199 |
+
padding: 40px 20px;
|
| 200 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 201 |
+
color: white;
|
| 202 |
+
border-radius: 12px;
|
| 203 |
+
margin-bottom: 30px;
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
.header-section h1 {
|
| 207 |
+
font-size: 3rem;
|
| 208 |
+
margin-bottom: 10px;
|
| 209 |
+
font-weight: 700;
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
.mode-selector {
|
| 213 |
+
font-size: 1.1rem !important;
|
| 214 |
+
font-weight: 600 !important;
|
| 215 |
+
padding: 12px !important;
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
.tab-nav button {
|
| 219 |
+
font-size: 16px;
|
| 220 |
+
font-weight: 600;
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
.feature-card {
|
| 224 |
+
border: 2px solid #e0e0e0;
|
| 225 |
+
border-radius: 12px;
|
| 226 |
+
padding: 20px;
|
| 227 |
+
margin: 10px;
|
| 228 |
+
background: #f8f9fa;
|
| 229 |
+
}
|
| 230 |
+
"""
|
| 231 |
+
|
| 232 |
+
# Create the main application
|
| 233 |
+
with gr.Blocks(
|
| 234 |
+
theme=gr.themes.Soft(
|
| 235 |
+
primary_hue="purple",
|
| 236 |
+
secondary_hue="blue",
|
| 237 |
+
),
|
| 238 |
+
css=custom_css,
|
| 239 |
+
title="ProVerBs Legal AI Platform"
|
| 240 |
+
) as demo:
|
| 241 |
+
|
| 242 |
+
# Header
|
| 243 |
+
gr.HTML("""
|
| 244 |
+
<div class="header-section">
|
| 245 |
+
<h1>βοΈ ProVerBs Legal AI Platform</h1>
|
| 246 |
+
<p>Lawful vs. Legal: Dual Analysis "Adappt'plication"</p>
|
| 247 |
+
<p style="font-size: 1rem; margin-top: 10px;">
|
| 248 |
+
Professional Legal AI System | Multi-Module Platform | Powered by Advanced AI
|
| 249 |
+
</p>
|
| 250 |
+
</div>
|
| 251 |
+
""")
|
| 252 |
+
|
| 253 |
+
# Login Section
|
| 254 |
+
with gr.Row():
|
| 255 |
+
with gr.Column(scale=1):
|
| 256 |
+
gr.LoginButton(size="lg")
|
| 257 |
+
with gr.Column(scale=5):
|
| 258 |
+
gr.Markdown("π **Login with your Hugging Face account** for full access")
|
| 259 |
+
|
| 260 |
+
gr.Markdown("---")
|
| 261 |
+
|
| 262 |
+
# Main Tabs
|
| 263 |
+
with gr.Tabs() as tabs:
|
| 264 |
+
|
| 265 |
+
# Tab 1: Welcome
|
| 266 |
+
with gr.Tab("π Welcome", id="welcome"):
|
| 267 |
+
gr.Markdown("""
|
| 268 |
+
## Welcome to ProVerBs Legal AI Platform
|
| 269 |
+
|
| 270 |
+
A comprehensive legal AI system with **multiple specialized assistants** to help you navigate legal matters.
|
| 271 |
+
|
| 272 |
+
### π― Choose Your AI Assistant Mode
|
| 273 |
+
|
| 274 |
+
Our platform features **7 specialized AI modes** to serve your specific needs:
|
| 275 |
+
|
| 276 |
+
- **π Navigation Guide** - Help finding features in the platform
|
| 277 |
+
- **π¬ General Legal Assistant** - Broad legal questions and guidance
|
| 278 |
+
- **π Document Validator** - Analyze and validate legal documents
|
| 279 |
+
- **π Legal Research** - Case law and statutory research
|
| 280 |
+
- **π Etymology Expert** - Understanding legal terminology origins
|
| 281 |
+
- **πΌ Case Management** - Organizing and tracking legal cases
|
| 282 |
+
- **π Regulatory Updates** - Stay informed about legal changes
|
| 283 |
+
|
| 284 |
+
### βοΈ Platform Features
|
| 285 |
+
|
| 286 |
+
- **Legal Action Advisor** - Get personalized recommendations
|
| 287 |
+
- **Document Analysis** - AI-powered document processing
|
| 288 |
+
- **Legal Research Tools** - Comprehensive databases
|
| 289 |
+
- **Communications** - Integrated SMS, email, phone
|
| 290 |
+
- **Document Generation** - Create legal documents with AI
|
| 291 |
+
|
| 292 |
+
**Ready to start?** Click the "AI Legal Chatbot" tab to begin!
|
| 293 |
+
""")
|
| 294 |
+
|
| 295 |
+
# Tab 2: AI Legal Chatbot (Your specialized chatbot)
|
| 296 |
+
with gr.Tab("π€ AI Legal Chatbot", id="chatbot"):
|
| 297 |
+
gr.Markdown("""
|
| 298 |
+
## AI Legal Chatbot - Multiple Specialized Modes
|
| 299 |
+
|
| 300 |
+
Select your assistant mode below and start chatting!
|
| 301 |
+
""")
|
| 302 |
+
|
| 303 |
+
# Mode selector
|
| 304 |
+
mode_selector = gr.Dropdown(
|
| 305 |
+
choices=list({
|
| 306 |
+
"navigation": "π Navigation Guide - Find features in the app",
|
| 307 |
+
"general": "π¬ General Legal Assistant - Broad legal questions",
|
| 308 |
+
"document_validation": "π Document Validator - Analyze documents",
|
| 309 |
+
"legal_research": "π Legal Research - Case law & statutes",
|
| 310 |
+
"etymology": "π Etymology Expert - Legal term origins",
|
| 311 |
+
"case_management": "πΌ Case Management - Organize cases",
|
| 312 |
+
"regulatory_updates": "π Regulatory Updates - Legal changes"
|
| 313 |
+
}.items()),
|
| 314 |
+
value="navigation",
|
| 315 |
+
label="Select AI Assistant Mode",
|
| 316 |
+
elem_classes=["mode-selector"]
|
| 317 |
+
)
|
| 318 |
+
|
| 319 |
+
gr.Markdown("---")
|
| 320 |
+
|
| 321 |
+
# Chat interface
|
| 322 |
+
chatbot = gr.ChatInterface(
|
| 323 |
+
lambda message, history, mode, max_tokens, temperature, top_p, hf_token:
|
| 324 |
+
respond_with_mode(message, history, mode.split(":")[0], max_tokens, temperature, top_p, hf_token),
|
| 325 |
+
type="messages",
|
| 326 |
+
chatbot=gr.Chatbot(
|
| 327 |
+
height=500,
|
| 328 |
+
placeholder="π¬ Select a mode above and ask your question...",
|
| 329 |
+
show_label=False,
|
| 330 |
+
),
|
| 331 |
+
textbox=gr.Textbox(
|
| 332 |
+
placeholder="Type your question here...",
|
| 333 |
+
container=False,
|
| 334 |
+
scale=7
|
| 335 |
+
),
|
| 336 |
+
additional_inputs=[
|
| 337 |
+
mode_selector,
|
| 338 |
+
gr.Slider(128, 4096, value=2048, step=128, label="Max Tokens"),
|
| 339 |
+
gr.Slider(0.1, 2.0, value=0.7, step=0.1, label="Temperature"),
|
| 340 |
+
gr.Slider(0.1, 1.0, value=0.95, step=0.05, label="Top-p"),
|
| 341 |
+
],
|
| 342 |
+
examples=[
|
| 343 |
+
["How do I navigate to the document analysis feature?"],
|
| 344 |
+
["What is the difference between lawful and legal?"],
|
| 345 |
+
["Can you help me validate a contract?"],
|
| 346 |
+
["I need to research case law about contracts"],
|
| 347 |
+
["What does 'habeas corpus' mean?"],
|
| 348 |
+
["How do I organize my legal case documents?"],
|
| 349 |
+
["What are the latest regulatory changes in business law?"],
|
| 350 |
+
],
|
| 351 |
+
cache_examples=False,
|
| 352 |
+
)
|
| 353 |
+
|
| 354 |
+
gr.Markdown("""
|
| 355 |
+
### π‘ Tips for Best Results
|
| 356 |
+
|
| 357 |
+
- **Choose the right mode** for your question type
|
| 358 |
+
- **Be specific** with your questions
|
| 359 |
+
- **Navigation Mode** helps you find features in the app
|
| 360 |
+
- **General Mode** answers broad legal questions
|
| 361 |
+
- Each mode is specialized for different tasks!
|
| 362 |
+
""")
|
| 363 |
+
|
| 364 |
+
# Tab 3: Features Overview
|
| 365 |
+
with gr.Tab("β¨ Features", id="features"):
|
| 366 |
+
gr.Markdown("""
|
| 367 |
+
## Platform Features
|
| 368 |
+
|
| 369 |
+
### π― Core Capabilities
|
| 370 |
+
""")
|
| 371 |
+
|
| 372 |
+
with gr.Row():
|
| 373 |
+
with gr.Column():
|
| 374 |
+
gr.Markdown("""
|
| 375 |
+
<div class="feature-card">
|
| 376 |
+
|
| 377 |
+
#### βοΈ Legal Action Advisor
|
| 378 |
+
Get personalized recommendations for seeking justice and remedy
|
| 379 |
+
|
| 380 |
+
- AI-powered action recommendations
|
| 381 |
+
- Case type analysis
|
| 382 |
+
- Timeline planning
|
| 383 |
+
- Free resource finder
|
| 384 |
+
- Evidence collection guidance
|
| 385 |
+
</div>
|
| 386 |
+
""", elem_classes=["feature-card"])
|
| 387 |
+
|
| 388 |
+
with gr.Column():
|
| 389 |
+
gr.Markdown("""
|
| 390 |
+
<div class="feature-card">
|
| 391 |
+
|
| 392 |
+
#### π Document Analysis
|
| 393 |
+
Upload and analyze legal documents with AI insights
|
| 394 |
+
|
| 395 |
+
- OCR text extraction
|
| 396 |
+
- Multi-format support (PDF, DOCX, TXT)
|
| 397 |
+
- AI-powered analysis
|
| 398 |
+
- Legal database cross-reference
|
| 399 |
+
- Document validation
|
| 400 |
+
</div>
|
| 401 |
+
""", elem_classes=["feature-card"])
|
| 402 |
+
|
| 403 |
+
with gr.Row():
|
| 404 |
+
with gr.Column():
|
| 405 |
+
gr.Markdown("""
|
| 406 |
+
<div class="feature-card">
|
| 407 |
+
|
| 408 |
+
#### π Legal Research
|
| 409 |
+
Comprehensive legal research tools and databases
|
| 410 |
+
|
| 411 |
+
- Multiple legal databases
|
| 412 |
+
- Case law research
|
| 413 |
+
- Statutory analysis
|
| 414 |
+
- Historical documents
|
| 415 |
+
- Citation tools
|
| 416 |
+
</div>
|
| 417 |
+
""", elem_classes=["feature-card"])
|
| 418 |
+
|
| 419 |
+
with gr.Column():
|
| 420 |
+
gr.Markdown("""
|
| 421 |
+
<div class="feature-card">
|
| 422 |
+
|
| 423 |
+
#### π§ Communications
|
| 424 |
+
Integrated communication system
|
| 425 |
+
|
| 426 |
+
- Twilio integration
|
| 427 |
+
- SMS messaging
|
| 428 |
+
- Email notifications
|
| 429 |
+
- Phone capabilities
|
| 430 |
+
- Legal alerts & reminders
|
| 431 |
+
</div>
|
| 432 |
+
""", elem_classes=["feature-card"])
|
| 433 |
+
|
| 434 |
+
gr.Markdown("""
|
| 435 |
+
---
|
| 436 |
+
|
| 437 |
+
### π€ AI Assistant Modes
|
| 438 |
+
|
| 439 |
+
Our chatbot includes **7 specialized modes**:
|
| 440 |
+
|
| 441 |
+
1. **Navigation Guide** - Find features in the platform
|
| 442 |
+
2. **General Assistant** - Broad legal questions
|
| 443 |
+
3. **Document Validator** - Analyze document quality
|
| 444 |
+
4. **Research Assistant** - Find legal precedents
|
| 445 |
+
5. **Etymology Expert** - Learn term origins
|
| 446 |
+
6. **Case Manager** - Organize your cases
|
| 447 |
+
7. **Regulatory Monitor** - Stay updated on changes
|
| 448 |
+
""")
|
| 449 |
+
|
| 450 |
+
# Tab 4: About
|
| 451 |
+
with gr.Tab("βΉοΈ About", id="about"):
|
| 452 |
+
gr.Markdown("""
|
| 453 |
+
## About ProVerBs Legal AI
|
| 454 |
+
|
| 455 |
+
### π Our Platform
|
| 456 |
+
|
| 457 |
+
ProVerBs Legal AI combines advanced artificial intelligence with comprehensive legal knowledge
|
| 458 |
+
to provide accessible, accurate legal information and tools.
|
| 459 |
+
|
| 460 |
+
### π€ Specialized AI Chatbot
|
| 461 |
+
|
| 462 |
+
Our AI chatbot features **7 specialized modes**, each trained for specific legal tasks:
|
| 463 |
+
|
| 464 |
+
- **Navigation Guide** - Helps you find and use platform features
|
| 465 |
+
- **General Legal Assistant** - Answers broad legal questions
|
| 466 |
+
- **Document Validator** - Analyzes legal documents for completeness
|
| 467 |
+
- **Legal Research Assistant** - Finds relevant case law and statutes
|
| 468 |
+
- **Etymology Expert** - Explains origins of legal terms
|
| 469 |
+
- **Case Management Helper** - Assists with organizing cases
|
| 470 |
+
- **Regulatory Update Monitor** - Keeps you informed of changes
|
| 471 |
+
|
| 472 |
+
### π₯ Who We Serve
|
| 473 |
+
|
| 474 |
+
- **Legal Professionals** - Enhance your practice with AI
|
| 475 |
+
- **Law Students** - Research and study assistance
|
| 476 |
+
- **Businesses** - Understand legal implications
|
| 477 |
+
- **Individuals** - Learn about your legal rights
|
| 478 |
+
|
| 479 |
+
### π Privacy & Security
|
| 480 |
+
|
| 481 |
+
- End-to-end encryption
|
| 482 |
+
- No storage without consent
|
| 483 |
+
- GDPR and CCPA compliant
|
| 484 |
+
- Secure OAuth authentication
|
| 485 |
+
|
| 486 |
+
### π Resources
|
| 487 |
+
|
| 488 |
+
- [Documentation](https://huggingface.co/Solomon7890)
|
| 489 |
+
- [GitHub](https://github.com/Solomon7890)
|
| 490 |
+
- [Community](#)
|
| 491 |
+
- [Support](#)
|
| 492 |
+
|
| 493 |
+
### β οΈ Important Disclaimer
|
| 494 |
+
|
| 495 |
+
This platform provides general legal information only. It does not constitute legal advice.
|
| 496 |
+
Always consult with a qualified attorney for specific legal matters.
|
| 497 |
+
|
| 498 |
+
---
|
| 499 |
+
|
| 500 |
+
**Version 1.0.0** | Built by Solomon7890 | Powered by Hugging Face
|
| 501 |
+
""")
|
| 502 |
+
|
| 503 |
+
# Footer
|
| 504 |
+
gr.Markdown("""
|
| 505 |
+
---
|
| 506 |
+
|
| 507 |
+
<div style="text-align: center; padding: 20px; color: #666;">
|
| 508 |
+
<p><strong>βοΈ ProVerBs Legal AI Platform</strong> | Version 1.0.0</p>
|
| 509 |
+
<p>
|
| 510 |
+
<a href="https://huggingface.co/Solomon7890" target="_blank">Hugging Face</a> |
|
| 511 |
+
<a href="https://github.com/Solomon7890" target="_blank">GitHub</a> |
|
| 512 |
+
<a href="#" target="_blank">Documentation</a>
|
| 513 |
+
</p>
|
| 514 |
+
<p style="font-size: 0.9rem; margin-top: 10px;">
|
| 515 |
+
β οΈ <strong>Disclaimer</strong>: This AI provides general legal information only.
|
| 516 |
+
Consult with a licensed attorney for specific legal matters.
|
| 517 |
+
</p>
|
| 518 |
+
<p style="font-size: 0.85rem; color: #999;">
|
| 519 |
+
Β© 2024 ProVerBs Legal AI. Built with β€οΈ for legal professionals worldwide.
|
| 520 |
+
</p>
|
| 521 |
+
</div>
|
| 522 |
+
""")
|
| 523 |
+
|
| 524 |
+
if __name__ == "__main__":
|
| 525 |
+
demo.queue(max_size=20)
|
| 526 |
+
demo.launch(
|
| 527 |
+
server_name="0.0.0.0",
|
| 528 |
+
server_port=7860,
|
| 529 |
+
share=False,
|
| 530 |
+
show_error=True
|
| 531 |
+
)
|
integrated_chatbot_full_ai.py
ADDED
|
@@ -0,0 +1,866 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
ProVerBs Legal AI - Complete AI Integration
|
| 3 |
+
Features: 7 AI Modes + Rotating Logos + DeepSeek-OCR + ERNIE-4.5-VL + GDPVAL
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import gradio as gr
|
| 7 |
+
from huggingface_hub import InferenceClient
|
| 8 |
+
import json
|
| 9 |
+
import os
|
| 10 |
+
from datetime import datetime
|
| 11 |
+
from typing import Dict, List, Optional
|
| 12 |
+
import base64
|
| 13 |
+
from pathlib import Path
|
| 14 |
+
|
| 15 |
+
# AI Model Integration
|
| 16 |
+
try:
|
| 17 |
+
from transformers import pipeline, AutoModel
|
| 18 |
+
from datasets import load_dataset
|
| 19 |
+
AI_MODELS_AVAILABLE = True
|
| 20 |
+
except ImportError:
|
| 21 |
+
AI_MODELS_AVAILABLE = False
|
| 22 |
+
print("β οΈ AI models not available. Install transformers and datasets.")
|
| 23 |
+
|
| 24 |
+
class EnhancedAILegalChatbot:
|
| 25 |
+
"""
|
| 26 |
+
Enhanced AI Legal Chatbot with multiple AI models
|
| 27 |
+
- DeepSeek-OCR for document text extraction
|
| 28 |
+
- ERNIE-4.5-VL for vision-language understanding
|
| 29 |
+
- OpenAI GDPVAL dataset for legal knowledge
|
| 30 |
+
"""
|
| 31 |
+
|
| 32 |
+
def __init__(self):
|
| 33 |
+
self.specialized_modes = {
|
| 34 |
+
"navigation": "Application Navigation Guide",
|
| 35 |
+
"general": "General Legal Assistant",
|
| 36 |
+
"document_validation": "Document Validator with OCR & Vision AI",
|
| 37 |
+
"legal_research": "Legal Research Assistant with GDPVAL",
|
| 38 |
+
"etymology": "Legal Etymology Lookup",
|
| 39 |
+
"case_management": "Case Management Helper",
|
| 40 |
+
"regulatory_updates": "Regulatory Update Monitor"
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
# Initialize AI models
|
| 44 |
+
self.ocr_pipeline = None
|
| 45 |
+
self.vision_pipeline = None
|
| 46 |
+
self.gdpval_dataset = None
|
| 47 |
+
self.minimax_pipeline = None
|
| 48 |
+
|
| 49 |
+
if AI_MODELS_AVAILABLE:
|
| 50 |
+
self._initialize_models()
|
| 51 |
+
|
| 52 |
+
def _initialize_models(self):
|
| 53 |
+
"""Initialize all AI models"""
|
| 54 |
+
|
| 55 |
+
# DeepSeek-OCR for text extraction
|
| 56 |
+
try:
|
| 57 |
+
print("π¦ Loading DeepSeek-OCR...")
|
| 58 |
+
self.ocr_pipeline = pipeline(
|
| 59 |
+
"image-text-to-text",
|
| 60 |
+
model="deepseek-ai/DeepSeek-OCR",
|
| 61 |
+
trust_remote_code=True
|
| 62 |
+
)
|
| 63 |
+
print("β
DeepSeek-OCR loaded!")
|
| 64 |
+
except Exception as e:
|
| 65 |
+
print(f"β οΈ DeepSeek-OCR not loaded: {e}")
|
| 66 |
+
|
| 67 |
+
# ERNIE-4.5-VL for vision-language understanding
|
| 68 |
+
try:
|
| 69 |
+
print("π¦ Loading ERNIE-4.5-VL (this may take a while)...")
|
| 70 |
+
self.vision_pipeline = pipeline(
|
| 71 |
+
"image-text-to-text",
|
| 72 |
+
model="baidu/ERNIE-4.5-VL-28B-A3B-Thinking",
|
| 73 |
+
trust_remote_code=True
|
| 74 |
+
)
|
| 75 |
+
print("β
ERNIE-4.5-VL loaded!")
|
| 76 |
+
except Exception as e:
|
| 77 |
+
print(f"β οΈ ERNIE-4.5-VL not loaded: {e}")
|
| 78 |
+
|
| 79 |
+
# OpenAI GDPVAL dataset for legal knowledge
|
| 80 |
+
try:
|
| 81 |
+
print("π¦ Loading OpenAI GDPVAL dataset...")
|
| 82 |
+
self.gdpval_dataset = load_dataset("openai/gdpval", split="train")
|
| 83 |
+
print(f"β
GDPVAL loaded! {len(self.gdpval_dataset)} entries")
|
| 84 |
+
except Exception as e:
|
| 85 |
+
print(f"β οΈ GDPVAL not loaded: {e}")
|
| 86 |
+
|
| 87 |
+
# MiniMax-M2 for advanced text generation
|
| 88 |
+
try:
|
| 89 |
+
print("π¦ Loading MiniMax-M2...")
|
| 90 |
+
self.minimax_pipeline = pipeline(
|
| 91 |
+
"text-generation",
|
| 92 |
+
model="MiniMaxAI/MiniMax-M2",
|
| 93 |
+
trust_remote_code=True
|
| 94 |
+
)
|
| 95 |
+
print("β
MiniMax-M2 loaded!")
|
| 96 |
+
except Exception as e:
|
| 97 |
+
print(f"β οΈ MiniMax-M2 not loaded: {e}")
|
| 98 |
+
|
| 99 |
+
def process_with_ocr(self, image_path: str) -> str:
|
| 100 |
+
"""Extract text using DeepSeek-OCR"""
|
| 101 |
+
if not self.ocr_pipeline:
|
| 102 |
+
return "β OCR not available"
|
| 103 |
+
|
| 104 |
+
try:
|
| 105 |
+
result = self.ocr_pipeline(image_path)
|
| 106 |
+
return result[0]['generated_text'] if result else ""
|
| 107 |
+
except Exception as e:
|
| 108 |
+
return f"β OCR error: {str(e)}"
|
| 109 |
+
|
| 110 |
+
def process_with_vision(self, image_url: str, question: str) -> str:
|
| 111 |
+
"""Analyze image using ERNIE-4.5-VL"""
|
| 112 |
+
if not self.vision_pipeline:
|
| 113 |
+
return "β Vision AI not available"
|
| 114 |
+
|
| 115 |
+
try:
|
| 116 |
+
messages = [
|
| 117 |
+
{
|
| 118 |
+
"role": "user",
|
| 119 |
+
"content": [
|
| 120 |
+
{"type": "image", "url": image_url},
|
| 121 |
+
{"type": "text", "text": question}
|
| 122 |
+
]
|
| 123 |
+
}
|
| 124 |
+
]
|
| 125 |
+
result = self.vision_pipeline(text=messages)
|
| 126 |
+
return result
|
| 127 |
+
except Exception as e:
|
| 128 |
+
return f"β Vision AI error: {str(e)}"
|
| 129 |
+
|
| 130 |
+
def search_gdpval(self, query: str, limit: int = 5) -> str:
|
| 131 |
+
"""Search OpenAI GDPVAL dataset for legal knowledge"""
|
| 132 |
+
if not self.gdpval_dataset:
|
| 133 |
+
return "β GDPVAL dataset not available"
|
| 134 |
+
|
| 135 |
+
try:
|
| 136 |
+
# Simple keyword search (can be enhanced with embeddings)
|
| 137 |
+
results = []
|
| 138 |
+
query_lower = query.lower()
|
| 139 |
+
|
| 140 |
+
for i, entry in enumerate(self.gdpval_dataset):
|
| 141 |
+
if i >= 100: # Limit search for performance
|
| 142 |
+
break
|
| 143 |
+
|
| 144 |
+
# Check if query keywords appear in entry
|
| 145 |
+
entry_text = str(entry).lower()
|
| 146 |
+
if any(word in entry_text for word in query_lower.split()):
|
| 147 |
+
results.append(entry)
|
| 148 |
+
if len(results) >= limit:
|
| 149 |
+
break
|
| 150 |
+
|
| 151 |
+
if results:
|
| 152 |
+
formatted = "### π GDPVAL Knowledge Base Results:\n\n"
|
| 153 |
+
for i, result in enumerate(results, 1):
|
| 154 |
+
formatted += f"**Result {i}:**\n{result}\n\n"
|
| 155 |
+
return formatted
|
| 156 |
+
else:
|
| 157 |
+
return "No relevant results found in GDPVAL dataset."
|
| 158 |
+
except Exception as e:
|
| 159 |
+
return f"β GDPVAL search error: {str(e)}"
|
| 160 |
+
|
| 161 |
+
def analyze_legal_document(self, image_path: str) -> str:
|
| 162 |
+
"""
|
| 163 |
+
Complete document analysis using multiple AI models:
|
| 164 |
+
1. DeepSeek-OCR for text extraction
|
| 165 |
+
2. ERNIE-4.5-VL for visual understanding
|
| 166 |
+
3. Legal analysis with AI
|
| 167 |
+
"""
|
| 168 |
+
analysis = "## π Complete Legal Document Analysis\n\n"
|
| 169 |
+
|
| 170 |
+
# Step 1: OCR Text Extraction
|
| 171 |
+
analysis += "### Step 1: Text Extraction (DeepSeek-OCR)\n"
|
| 172 |
+
extracted_text = self.process_with_ocr(image_path)
|
| 173 |
+
analysis += f"```\n{extracted_text[:500]}...\n```\n\n"
|
| 174 |
+
|
| 175 |
+
# Step 2: Vision Analysis
|
| 176 |
+
analysis += "### Step 2: Visual Document Understanding (ERNIE-4.5-VL)\n"
|
| 177 |
+
vision_result = self.process_with_vision(
|
| 178 |
+
image_path,
|
| 179 |
+
"Analyze this legal document. Identify document type, key sections, and any notable elements."
|
| 180 |
+
)
|
| 181 |
+
analysis += f"{vision_result}\n\n"
|
| 182 |
+
|
| 183 |
+
# Step 3: Legal Term Detection
|
| 184 |
+
analysis += "### Step 3: Legal Analysis\n"
|
| 185 |
+
legal_terms = self._detect_legal_terms(extracted_text)
|
| 186 |
+
analysis += f"**Legal Terms Found:** {legal_terms}\n\n"
|
| 187 |
+
|
| 188 |
+
# Step 4: Document Quality Check
|
| 189 |
+
analysis += "### Step 4: Document Quality\n"
|
| 190 |
+
quality = self._assess_document_quality(extracted_text)
|
| 191 |
+
analysis += f"{quality}\n\n"
|
| 192 |
+
|
| 193 |
+
return analysis
|
| 194 |
+
|
| 195 |
+
def _detect_legal_terms(self, text: str) -> str:
|
| 196 |
+
"""Detect legal terminology in text"""
|
| 197 |
+
legal_terms = [
|
| 198 |
+
'contract', 'agreement', 'party', 'clause', 'provision',
|
| 199 |
+
'whereas', 'hereby', 'herein', 'pursuant', 'consideration',
|
| 200 |
+
'liability', 'indemnify', 'warranty', 'breach', 'terminate',
|
| 201 |
+
'arbitration', 'jurisdiction', 'statute', 'regulation'
|
| 202 |
+
]
|
| 203 |
+
|
| 204 |
+
found = [term for term in legal_terms if term.lower() in text.lower()]
|
| 205 |
+
return ', '.join(found) if found else "None detected"
|
| 206 |
+
|
| 207 |
+
def _assess_document_quality(self, text: str) -> str:
|
| 208 |
+
"""Assess document completeness and quality"""
|
| 209 |
+
issues = []
|
| 210 |
+
|
| 211 |
+
if len(text) < 100:
|
| 212 |
+
issues.append("β οΈ Document seems very short")
|
| 213 |
+
|
| 214 |
+
if not any(term in text.lower() for term in ['party', 'parties', 'agreement']):
|
| 215 |
+
issues.append("β οΈ Missing party identification")
|
| 216 |
+
|
| 217 |
+
if not any(term in text.lower() for term in ['date', 'dated', 'effective']):
|
| 218 |
+
issues.append("β οΈ No effective date found")
|
| 219 |
+
|
| 220 |
+
if issues:
|
| 221 |
+
return "**Issues Found:**\n" + "\n".join(issues)
|
| 222 |
+
else:
|
| 223 |
+
return "β
Document appears complete"
|
| 224 |
+
|
| 225 |
+
def generate_with_minimax(self, messages: list) -> str:
|
| 226 |
+
"""Generate response using MiniMax-M2"""
|
| 227 |
+
if not self.minimax_pipeline:
|
| 228 |
+
return "β MiniMax-M2 not available"
|
| 229 |
+
|
| 230 |
+
try:
|
| 231 |
+
result = self.minimax_pipeline(messages)
|
| 232 |
+
return result[0]['generated_text'] if result else "No response"
|
| 233 |
+
except Exception as e:
|
| 234 |
+
return f"β MiniMax error: {str(e)}"
|
| 235 |
+
|
| 236 |
+
def get_mode_system_prompt(self, mode: str) -> str:
|
| 237 |
+
"""Get specialized system prompt based on mode"""
|
| 238 |
+
prompts = {
|
| 239 |
+
"navigation": """You are a ProVerBs Application Navigation Guide.
|
| 240 |
+
|
| 241 |
+
**Enhanced Features:**
|
| 242 |
+
- Document Analysis with OCR (DeepSeek-OCR)
|
| 243 |
+
- Vision AI Analysis (ERNIE-4.5-VL)
|
| 244 |
+
- Legal Knowledge Base (OpenAI GDPVAL)
|
| 245 |
+
- 7 Specialized AI Modes
|
| 246 |
+
|
| 247 |
+
Guide users to the right features.""",
|
| 248 |
+
|
| 249 |
+
"general": """You are a General Legal Assistant for ProVerBs Legal AI Platform.
|
| 250 |
+
|
| 251 |
+
**Available Tools:**
|
| 252 |
+
- GDPVAL legal knowledge dataset
|
| 253 |
+
- Vision AI for document understanding
|
| 254 |
+
- OCR for text extraction
|
| 255 |
+
|
| 256 |
+
Provide accurate legal information while noting you cannot provide legal advice.""",
|
| 257 |
+
|
| 258 |
+
"document_validation": """You are an Advanced Document Validator.
|
| 259 |
+
|
| 260 |
+
**AI-Powered Capabilities:**
|
| 261 |
+
- **DeepSeek-OCR**: Extract text from scanned documents
|
| 262 |
+
- **ERNIE-4.5-VL**: Understand document structure and layout visually
|
| 263 |
+
- **Legal Analysis**: Validate completeness and legal terms
|
| 264 |
+
|
| 265 |
+
**Process:**
|
| 266 |
+
1. Extract text with OCR
|
| 267 |
+
2. Analyze visually with ERNIE
|
| 268 |
+
3. Check legal validity
|
| 269 |
+
4. Provide detailed feedback""",
|
| 270 |
+
|
| 271 |
+
"legal_research": """You are a Legal Research Assistant with GDPVAL access.
|
| 272 |
+
|
| 273 |
+
**Enhanced Research Tools:**
|
| 274 |
+
- OpenAI GDPVAL dataset for legal knowledge
|
| 275 |
+
- Case law and precedent search
|
| 276 |
+
- Statute and regulation analysis
|
| 277 |
+
|
| 278 |
+
Provide comprehensive research with citations.""",
|
| 279 |
+
|
| 280 |
+
"etymology": """You are a Legal Etymology Expert. Explain origins of legal terms.""",
|
| 281 |
+
|
| 282 |
+
"case_management": """You are a Case Management Helper with AI document processing.""",
|
| 283 |
+
|
| 284 |
+
"regulatory_updates": """You are a Regulatory Update Monitor."""
|
| 285 |
+
}
|
| 286 |
+
return prompts.get(mode, prompts["general"])
|
| 287 |
+
|
| 288 |
+
def respond_with_mode(
|
| 289 |
+
message,
|
| 290 |
+
history: list,
|
| 291 |
+
mode: str,
|
| 292 |
+
model_choice: str,
|
| 293 |
+
max_tokens: int,
|
| 294 |
+
temperature: float,
|
| 295 |
+
top_p: float,
|
| 296 |
+
):
|
| 297 |
+
"""Generate AI response based on selected mode"""
|
| 298 |
+
chatbot = EnhancedAILegalChatbot()
|
| 299 |
+
|
| 300 |
+
system_message = chatbot.get_mode_system_prompt(mode)
|
| 301 |
+
|
| 302 |
+
# Enhanced responses for specific modes
|
| 303 |
+
if mode == "document_validation" and "analyze" in message.lower():
|
| 304 |
+
yield """
|
| 305 |
+
## π Advanced Document Validator
|
| 306 |
+
|
| 307 |
+
**Multi-AI Analysis Available:**
|
| 308 |
+
|
| 309 |
+
1. **DeepSeek-OCR**: Extract text from scanned documents
|
| 310 |
+
2. **ERNIE-4.5-VL**: Understand document structure visually
|
| 311 |
+
3. **Legal AI**: Validate and analyze content
|
| 312 |
+
|
| 313 |
+
**Upload a document to get:**
|
| 314 |
+
- β
Text extraction
|
| 315 |
+
- β
Visual structure analysis
|
| 316 |
+
- β
Legal term detection
|
| 317 |
+
- β
Completeness check
|
| 318 |
+
- β
Quality assessment
|
| 319 |
+
"""
|
| 320 |
+
return
|
| 321 |
+
|
| 322 |
+
if mode == "legal_research" and "search" in message.lower():
|
| 323 |
+
# Search GDPVAL dataset
|
| 324 |
+
gdpval_results = chatbot.search_gdpval(message)
|
| 325 |
+
yield gdpval_results
|
| 326 |
+
return
|
| 327 |
+
|
| 328 |
+
# Choose AI model based on selection
|
| 329 |
+
if model_choice == "MiniMax-M2" and chatbot.minimax_pipeline:
|
| 330 |
+
# Use MiniMax-M2
|
| 331 |
+
try:
|
| 332 |
+
messages_minimax = [
|
| 333 |
+
{"role": "system", "content": system_message},
|
| 334 |
+
{"role": "user", "content": message}
|
| 335 |
+
]
|
| 336 |
+
response = chatbot.generate_with_minimax(messages_minimax)
|
| 337 |
+
yield response
|
| 338 |
+
except Exception as e:
|
| 339 |
+
yield f"MiniMax Error: {str(e)}"
|
| 340 |
+
else:
|
| 341 |
+
# Use HF Inference API (Llama) as default
|
| 342 |
+
try:
|
| 343 |
+
client = InferenceClient(model="meta-llama/Llama-3.3-70B-Instruct")
|
| 344 |
+
|
| 345 |
+
messages = [{"role": "system", "content": system_message}]
|
| 346 |
+
|
| 347 |
+
for user_msg, assistant_msg in history:
|
| 348 |
+
if user_msg:
|
| 349 |
+
messages.append({"role": "user", "content": user_msg})
|
| 350 |
+
if assistant_msg:
|
| 351 |
+
messages.append({"role": "assistant", "content": assistant_msg})
|
| 352 |
+
|
| 353 |
+
messages.append({"role": "user", "content": message})
|
| 354 |
+
|
| 355 |
+
response = ""
|
| 356 |
+
for message_chunk in client.chat_completion(
|
| 357 |
+
messages,
|
| 358 |
+
max_tokens=max_tokens,
|
| 359 |
+
stream=True,
|
| 360 |
+
temperature=temperature,
|
| 361 |
+
top_p=top_p,
|
| 362 |
+
):
|
| 363 |
+
if message_chunk.choices and message_chunk.choices[0].delta.content:
|
| 364 |
+
token = message_chunk.choices[0].delta.content
|
| 365 |
+
response += token
|
| 366 |
+
yield response
|
| 367 |
+
except Exception as e:
|
| 368 |
+
# Provide demo response for local preview
|
| 369 |
+
demo_response = f"""
|
| 370 |
+
## π― Preview Mode Response
|
| 371 |
+
|
| 372 |
+
**Your Question:** {message}
|
| 373 |
+
|
| 374 |
+
**Mode:** {mode}
|
| 375 |
+
|
| 376 |
+
**Note:** This is a demo response for local preview. The AI chat will work fully once deployed to Hugging Face Spaces with authentication.
|
| 377 |
+
|
| 378 |
+
### What This Mode Does:
|
| 379 |
+
|
| 380 |
+
{system_message[:200]}...
|
| 381 |
+
|
| 382 |
+
### Features Available:
|
| 383 |
+
- β
UI and navigation fully functional
|
| 384 |
+
- β
All tabs working
|
| 385 |
+
- β
Watermark backgrounds active
|
| 386 |
+
- β
Logo rotation active
|
| 387 |
+
- β οΈ AI responses require HF deployment
|
| 388 |
+
|
| 389 |
+
**To test AI chat:** Deploy to Hugging Face Spaces where authentication is automatic.
|
| 390 |
+
|
| 391 |
+
---
|
| 392 |
+
|
| 393 |
+
**For now:** Test the visual design, tab navigation, dropdowns, and timing features!
|
| 394 |
+
"""
|
| 395 |
+
yield demo_response
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
# Custom CSS with watermark background logos
|
| 399 |
+
custom_css = """
|
| 400 |
+
.gradio-container {
|
| 401 |
+
max-width: 1200px !important;
|
| 402 |
+
position: relative;
|
| 403 |
+
}
|
| 404 |
+
|
| 405 |
+
/* Watermark background container */
|
| 406 |
+
.watermark-container {
|
| 407 |
+
position: fixed;
|
| 408 |
+
top: 0;
|
| 409 |
+
left: 0;
|
| 410 |
+
width: 100%;
|
| 411 |
+
height: 100%;
|
| 412 |
+
z-index: 0;
|
| 413 |
+
pointer-events: none;
|
| 414 |
+
overflow: hidden;
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
/* Watermark logo styling */
|
| 418 |
+
.watermark-logo {
|
| 419 |
+
position: absolute;
|
| 420 |
+
width: 300px;
|
| 421 |
+
height: 300px;
|
| 422 |
+
opacity: 0.08;
|
| 423 |
+
object-fit: contain;
|
| 424 |
+
transition: opacity 2s ease-in-out;
|
| 425 |
+
}
|
| 426 |
+
|
| 427 |
+
.watermark-logo.active {
|
| 428 |
+
opacity: 0.08;
|
| 429 |
+
}
|
| 430 |
+
|
| 431 |
+
.watermark-logo.hidden {
|
| 432 |
+
opacity: 0;
|
| 433 |
+
}
|
| 434 |
+
|
| 435 |
+
/* Position watermarks at different locations */
|
| 436 |
+
.watermark-1 {
|
| 437 |
+
top: 10%;
|
| 438 |
+
left: 10%;
|
| 439 |
+
transform: rotate(-15deg);
|
| 440 |
+
}
|
| 441 |
+
|
| 442 |
+
.watermark-2 {
|
| 443 |
+
top: 15%;
|
| 444 |
+
right: 15%;
|
| 445 |
+
transform: rotate(20deg);
|
| 446 |
+
}
|
| 447 |
+
|
| 448 |
+
.watermark-3 {
|
| 449 |
+
bottom: 20%;
|
| 450 |
+
left: 15%;
|
| 451 |
+
transform: rotate(10deg);
|
| 452 |
+
}
|
| 453 |
+
|
| 454 |
+
.watermark-4 {
|
| 455 |
+
bottom: 15%;
|
| 456 |
+
right: 10%;
|
| 457 |
+
transform: rotate(-20deg);
|
| 458 |
+
}
|
| 459 |
+
|
| 460 |
+
.watermark-5 {
|
| 461 |
+
top: 50%;
|
| 462 |
+
left: 50%;
|
| 463 |
+
transform: translate(-50%, -50%) rotate(-5deg);
|
| 464 |
+
}
|
| 465 |
+
|
| 466 |
+
/* Ensure content is above watermarks */
|
| 467 |
+
.gradio-container > * {
|
| 468 |
+
position: relative;
|
| 469 |
+
z-index: 1;
|
| 470 |
+
}
|
| 471 |
+
|
| 472 |
+
.header-section {
|
| 473 |
+
text-align: center;
|
| 474 |
+
padding: 40px 20px;
|
| 475 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 476 |
+
color: white;
|
| 477 |
+
border-radius: 12px;
|
| 478 |
+
margin-bottom: 30px;
|
| 479 |
+
position: relative;
|
| 480 |
+
z-index: 2;
|
| 481 |
+
}
|
| 482 |
+
|
| 483 |
+
.logo-container {
|
| 484 |
+
margin-bottom: 20px;
|
| 485 |
+
display: flex;
|
| 486 |
+
justify-content: center;
|
| 487 |
+
align-items: center;
|
| 488 |
+
}
|
| 489 |
+
|
| 490 |
+
.rotating-logo {
|
| 491 |
+
width: 150px;
|
| 492 |
+
height: 150px;
|
| 493 |
+
border-radius: 50%;
|
| 494 |
+
object-fit: cover;
|
| 495 |
+
border: 4px solid rgba(255, 255, 255, 0.8);
|
| 496 |
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
|
| 497 |
+
}
|
| 498 |
+
|
| 499 |
+
.header-section h1 {
|
| 500 |
+
font-size: 3rem;
|
| 501 |
+
margin-bottom: 10px;
|
| 502 |
+
font-weight: 700;
|
| 503 |
+
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
|
| 504 |
+
}
|
| 505 |
+
|
| 506 |
+
/* Make sure tabs and content are above watermarks */
|
| 507 |
+
.tabs, .tabitem {
|
| 508 |
+
position: relative;
|
| 509 |
+
z-index: 1;
|
| 510 |
+
}
|
| 511 |
+
"""
|
| 512 |
+
|
| 513 |
+
# JavaScript for rotating logos in header and random watermarks
|
| 514 |
+
rotating_logo_js = """
|
| 515 |
+
<script>
|
| 516 |
+
// Header logo rotation
|
| 517 |
+
function rotateHeaderLogo() {
|
| 518 |
+
const logos = document.querySelectorAll('.rotating-logo');
|
| 519 |
+
let currentIndex = 0;
|
| 520 |
+
|
| 521 |
+
function showNextLogo() {
|
| 522 |
+
logos.forEach((logo, index) => {
|
| 523 |
+
logo.style.display = 'none';
|
| 524 |
+
});
|
| 525 |
+
if (logos.length > 0) {
|
| 526 |
+
logos[currentIndex].style.display = 'block';
|
| 527 |
+
currentIndex = (currentIndex + 1) % logos.length;
|
| 528 |
+
}
|
| 529 |
+
}
|
| 530 |
+
|
| 531 |
+
showNextLogo();
|
| 532 |
+
setInterval(showNextLogo, 60000);
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
// Random watermark rotation
|
| 536 |
+
function rotateWatermarks() {
|
| 537 |
+
const watermarks = document.querySelectorAll('.watermark-logo');
|
| 538 |
+
const logoImages = [
|
| 539 |
+
'file/assets/logo_1.jpg',
|
| 540 |
+
'file/assets/logo_2.jpg',
|
| 541 |
+
'file/assets/logo_3.jpg'
|
| 542 |
+
];
|
| 543 |
+
|
| 544 |
+
function randomizeWatermarks() {
|
| 545 |
+
watermarks.forEach((watermark) => {
|
| 546 |
+
// Fade out
|
| 547 |
+
watermark.classList.remove('active');
|
| 548 |
+
watermark.classList.add('hidden');
|
| 549 |
+
|
| 550 |
+
setTimeout(() => {
|
| 551 |
+
// Pick random logo
|
| 552 |
+
const randomLogo = logoImages[Math.floor(Math.random() * logoImages.length)];
|
| 553 |
+
watermark.src = randomLogo;
|
| 554 |
+
|
| 555 |
+
// Fade in
|
| 556 |
+
watermark.classList.remove('hidden');
|
| 557 |
+
watermark.classList.add('active');
|
| 558 |
+
}, 2000);
|
| 559 |
+
});
|
| 560 |
+
}
|
| 561 |
+
|
| 562 |
+
// Initial randomization
|
| 563 |
+
randomizeWatermarks();
|
| 564 |
+
|
| 565 |
+
// Change watermarks every 30 seconds with random logos
|
| 566 |
+
setInterval(randomizeWatermarks, 30000);
|
| 567 |
+
}
|
| 568 |
+
|
| 569 |
+
// Initialize both rotations
|
| 570 |
+
if (document.readyState === 'loading') {
|
| 571 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 572 |
+
rotateHeaderLogo();
|
| 573 |
+
rotateWatermarks();
|
| 574 |
+
});
|
| 575 |
+
} else {
|
| 576 |
+
rotateHeaderLogo();
|
| 577 |
+
rotateWatermarks();
|
| 578 |
+
}
|
| 579 |
+
</script>
|
| 580 |
+
"""
|
| 581 |
+
|
| 582 |
+
# Create the main application
|
| 583 |
+
demo = gr.Blocks(title="ProVerBs Legal AI Platform")
|
| 584 |
+
|
| 585 |
+
with demo:
|
| 586 |
+
|
| 587 |
+
# Watermark background logos
|
| 588 |
+
gr.HTML(f"""
|
| 589 |
+
<div class="watermark-container">
|
| 590 |
+
<img src="file/assets/logo_1.jpg" class="watermark-logo watermark-1 active" alt="Watermark 1">
|
| 591 |
+
<img src="file/assets/logo_2.jpg" class="watermark-logo watermark-2 active" alt="Watermark 2">
|
| 592 |
+
<img src="file/assets/logo_3.jpg" class="watermark-logo watermark-3 active" alt="Watermark 3">
|
| 593 |
+
<img src="file/assets/logo_1.jpg" class="watermark-logo watermark-4 active" alt="Watermark 4">
|
| 594 |
+
<img src="file/assets/logo_2.jpg" class="watermark-logo watermark-5 active" alt="Watermark 5">
|
| 595 |
+
</div>
|
| 596 |
+
|
| 597 |
+
<style>{custom_css}</style>
|
| 598 |
+
{rotating_logo_js}
|
| 599 |
+
|
| 600 |
+
<!-- Header with Rotating Logos -->
|
| 601 |
+
<div class="header-section">
|
| 602 |
+
<div class="logo-container">
|
| 603 |
+
<img src="file/assets/logo_1.jpg" class="rotating-logo" alt="Logo 1" style="display: block;">
|
| 604 |
+
<img src="file/assets/logo_2.jpg" class="rotating-logo" alt="Logo 2" style="display: none;">
|
| 605 |
+
<img src="file/assets/logo_3.jpg" class="rotating-logo" alt="Logo 3" style="display: none;">
|
| 606 |
+
</div>
|
| 607 |
+
<h1>βοΈ ProVerBs Legal AI Platform</h1>
|
| 608 |
+
<p>Lawful vs. Legal: Dual Analysis "Adappt'plication"</p>
|
| 609 |
+
<p style="font-size: 1rem; margin-top: 10px;">
|
| 610 |
+
Multi-AI Legal System | 5 AI Models Working Together π
|
| 611 |
+
</p>
|
| 612 |
+
</div>
|
| 613 |
+
""")
|
| 614 |
+
|
| 615 |
+
gr.Markdown("---")
|
| 616 |
+
|
| 617 |
+
# Main Tabs
|
| 618 |
+
with gr.Tabs():
|
| 619 |
+
|
| 620 |
+
# Tab 1: Welcome
|
| 621 |
+
with gr.Tab("π Welcome"):
|
| 622 |
+
gr.Markdown("""
|
| 623 |
+
## Welcome to ProVerBs Legal AI Platform
|
| 624 |
+
|
| 625 |
+
### π€ 5 AI Models Integrated:
|
| 626 |
+
|
| 627 |
+
1. **DeepSeek-OCR** - Extract text from scanned documents
|
| 628 |
+
2. **ERNIE-4.5-VL** - Advanced vision-language understanding
|
| 629 |
+
3. **OpenAI GDPVAL** - Legal knowledge dataset
|
| 630 |
+
4. **Meta Llama 3.3** - General AI assistance
|
| 631 |
+
5. **MiniMax-M2** - Advanced text generation
|
| 632 |
+
|
| 633 |
+
### βοΈ 7 Specialized Modes:
|
| 634 |
+
|
| 635 |
+
- π Navigation Guide
|
| 636 |
+
- π¬ General Legal Assistant (with GDPVAL)
|
| 637 |
+
- π Document Validator (OCR + Vision AI)
|
| 638 |
+
- π Legal Research (GDPVAL-powered)
|
| 639 |
+
- π Etymology Expert
|
| 640 |
+
- πΌ Case Management
|
| 641 |
+
- π Regulatory Updates
|
| 642 |
+
|
| 643 |
+
### β¨ Unique Features:
|
| 644 |
+
|
| 645 |
+
- **Multi-AI Document Analysis**: Combines OCR + Vision AI
|
| 646 |
+
- **Legal Knowledge Base**: Access to GDPVAL dataset
|
| 647 |
+
- **Rotating Custom Logos**: Your professional branding
|
| 648 |
+
- **Complete Legal Solution**: All-in-one platform
|
| 649 |
+
""")
|
| 650 |
+
|
| 651 |
+
# Tab 2: AI Legal Chatbot
|
| 652 |
+
with gr.Tab("π€ AI Legal Chatbot"):
|
| 653 |
+
gr.Markdown("""
|
| 654 |
+
## Multi-AI Legal Chatbot
|
| 655 |
+
|
| 656 |
+
**Powered by 5 AI Models** for comprehensive legal assistance!
|
| 657 |
+
|
| 658 |
+
**Choose Your AI Model:**
|
| 659 |
+
- **Meta Llama 3.3** - Fast, efficient, streaming responses
|
| 660 |
+
- **MiniMax-M2** - Advanced text generation capabilities
|
| 661 |
+
""")
|
| 662 |
+
|
| 663 |
+
mode_selector = gr.Dropdown(
|
| 664 |
+
choices=[
|
| 665 |
+
"navigation",
|
| 666 |
+
"general",
|
| 667 |
+
"document_validation",
|
| 668 |
+
"legal_research",
|
| 669 |
+
"etymology",
|
| 670 |
+
"case_management",
|
| 671 |
+
"regulatory_updates"
|
| 672 |
+
],
|
| 673 |
+
value="navigation",
|
| 674 |
+
label="Select AI Assistant Mode"
|
| 675 |
+
)
|
| 676 |
+
|
| 677 |
+
model_selector = gr.Dropdown(
|
| 678 |
+
choices=[
|
| 679 |
+
"Meta Llama 3.3",
|
| 680 |
+
"MiniMax-M2"
|
| 681 |
+
],
|
| 682 |
+
value="Meta Llama 3.3",
|
| 683 |
+
label="Select AI Model"
|
| 684 |
+
)
|
| 685 |
+
|
| 686 |
+
gr.Markdown("---")
|
| 687 |
+
|
| 688 |
+
chatbot = gr.ChatInterface(
|
| 689 |
+
respond_with_mode,
|
| 690 |
+
chatbot=gr.Chatbot(height=500),
|
| 691 |
+
additional_inputs=[
|
| 692 |
+
mode_selector,
|
| 693 |
+
model_selector,
|
| 694 |
+
gr.Slider(128, 4096, value=2048, label="Max Tokens"),
|
| 695 |
+
gr.Slider(0.1, 2.0, value=0.7, label="Temperature"),
|
| 696 |
+
gr.Slider(0.1, 1.0, value=0.95, label="Top-p"),
|
| 697 |
+
],
|
| 698 |
+
examples=[
|
| 699 |
+
["How do I use the multi-AI document analysis?"],
|
| 700 |
+
["Search GDPVAL for contract law information"],
|
| 701 |
+
["Analyze a document with vision AI"],
|
| 702 |
+
],
|
| 703 |
+
)
|
| 704 |
+
|
| 705 |
+
# Tab 3: Document Analysis (NEW!)
|
| 706 |
+
with gr.Tab("π Document Analysis"):
|
| 707 |
+
gr.Markdown("""
|
| 708 |
+
## π Document Upload & AI Analysis
|
| 709 |
+
|
| 710 |
+
Upload legal documents for comprehensive AI analysis!
|
| 711 |
+
""")
|
| 712 |
+
|
| 713 |
+
with gr.Row():
|
| 714 |
+
with gr.Column(scale=1):
|
| 715 |
+
doc_upload = gr.File(
|
| 716 |
+
label="π Upload Document",
|
| 717 |
+
file_types=[".pdf", ".jpg", ".jpeg", ".png", ".txt"]
|
| 718 |
+
)
|
| 719 |
+
|
| 720 |
+
analysis_type = gr.Radio(
|
| 721 |
+
choices=[
|
| 722 |
+
"Complete Analysis",
|
| 723 |
+
"OCR Only",
|
| 724 |
+
"Visual Only",
|
| 725 |
+
"Legal Validation"
|
| 726 |
+
],
|
| 727 |
+
value="Complete Analysis",
|
| 728 |
+
label="Analysis Type"
|
| 729 |
+
)
|
| 730 |
+
|
| 731 |
+
analyze_btn = gr.Button("π Analyze", variant="primary", size="lg")
|
| 732 |
+
|
| 733 |
+
with gr.Column(scale=2):
|
| 734 |
+
analysis_output = gr.Markdown("Upload a document to begin analysis.")
|
| 735 |
+
|
| 736 |
+
def analyze_doc(file_path, analysis_type):
|
| 737 |
+
if not file_path:
|
| 738 |
+
return "β οΈ Please upload a document first."
|
| 739 |
+
|
| 740 |
+
filename = file_path.split('/')[-1] if '/' in file_path else file_path.split('\\')[-1]
|
| 741 |
+
|
| 742 |
+
return f"""
|
| 743 |
+
## π Document Analysis Results
|
| 744 |
+
|
| 745 |
+
**File:** {filename}
|
| 746 |
+
**Analysis Type:** {analysis_type}
|
| 747 |
+
|
| 748 |
+
### β οΈ Preview Mode
|
| 749 |
+
|
| 750 |
+
**What happens in production:**
|
| 751 |
+
- **DeepSeek-OCR** extracts text from images
|
| 752 |
+
- **ERNIE-4.5-VL** analyzes document structure
|
| 753 |
+
- **Legal AI** validates completeness
|
| 754 |
+
|
| 755 |
+
**Demo Output:**
|
| 756 |
+
- Document uploaded successfully β
|
| 757 |
+
- File format supported β
|
| 758 |
+
- Ready for AI analysis β
|
| 759 |
+
|
| 760 |
+
**Note:** Full analysis available after HF deployment.
|
| 761 |
+
|
| 762 |
+
**Try it:** Upload any legal document (PDF, image, text) to see the interface!
|
| 763 |
+
"""
|
| 764 |
+
|
| 765 |
+
analyze_btn.click(
|
| 766 |
+
fn=analyze_doc,
|
| 767 |
+
inputs=[doc_upload, analysis_type],
|
| 768 |
+
outputs=analysis_output
|
| 769 |
+
)
|
| 770 |
+
|
| 771 |
+
# Tab 4: Features
|
| 772 |
+
with gr.Tab("β¨ Features"):
|
| 773 |
+
gr.Markdown("""
|
| 774 |
+
## Advanced AI Features
|
| 775 |
+
|
| 776 |
+
### π€ Integrated AI Models:
|
| 777 |
+
|
| 778 |
+
1. **DeepSeek-OCR**
|
| 779 |
+
- Text extraction from images
|
| 780 |
+
- Document scanning
|
| 781 |
+
- High accuracy OCR
|
| 782 |
+
|
| 783 |
+
2. **ERNIE-4.5-VL** (Baidu)
|
| 784 |
+
- Vision-language understanding
|
| 785 |
+
- Document layout analysis
|
| 786 |
+
- Visual question answering
|
| 787 |
+
|
| 788 |
+
3. **OpenAI GDPVAL**
|
| 789 |
+
- Legal knowledge dataset
|
| 790 |
+
- Case law and precedents
|
| 791 |
+
- Regulatory information
|
| 792 |
+
|
| 793 |
+
4. **Meta Llama 3.3**
|
| 794 |
+
- General AI assistance
|
| 795 |
+
- Legal reasoning
|
| 796 |
+
- Natural conversation
|
| 797 |
+
|
| 798 |
+
5. **MiniMax-M2** β NEW!
|
| 799 |
+
- Advanced text generation
|
| 800 |
+
- High-quality responses
|
| 801 |
+
- Alternative AI model option
|
| 802 |
+
|
| 803 |
+
### π― What This Means:
|
| 804 |
+
|
| 805 |
+
- **Most Advanced**: 5 AI models working together
|
| 806 |
+
- **Best Analysis**: Multiple AI perspectives
|
| 807 |
+
- **Model Choice**: Select the best AI for your task
|
| 808 |
+
- **Comprehensive**: Text + Vision + Knowledge
|
| 809 |
+
- **Professional**: Your custom branding with logos
|
| 810 |
+
""")
|
| 811 |
+
|
| 812 |
+
# Tab 4: About
|
| 813 |
+
with gr.Tab("βΉοΈ About"):
|
| 814 |
+
gr.Markdown("""
|
| 815 |
+
## About ProVerBs Legal AI - Complete Edition
|
| 816 |
+
|
| 817 |
+
### π Version 2.1.0 - Complete Multi-AI Integration
|
| 818 |
+
|
| 819 |
+
**This is the most advanced version** with all AI capabilities:
|
| 820 |
+
|
| 821 |
+
- β
7 Specialized AI Modes
|
| 822 |
+
- β
3 Rotating Custom Logos
|
| 823 |
+
- β
DeepSeek-OCR Integration
|
| 824 |
+
- β
ERNIE-4.5-VL Vision AI
|
| 825 |
+
- β
OpenAI GDPVAL Dataset
|
| 826 |
+
- β
Meta Llama 3.3 AI
|
| 827 |
+
- β
MiniMax-M2 AI β NEW!
|
| 828 |
+
|
| 829 |
+
### π Technical Stack:
|
| 830 |
+
|
| 831 |
+
- **Frontend**: Gradio 4.x
|
| 832 |
+
- **OCR**: DeepSeek-OCR
|
| 833 |
+
- **Vision**: ERNIE-4.5-VL-28B
|
| 834 |
+
- **Dataset**: OpenAI GDPVAL
|
| 835 |
+
- **LLM 1**: Meta Llama 3.3-70B
|
| 836 |
+
- **LLM 2**: MiniMax-M2
|
| 837 |
+
- **Platform**: Hugging Face Spaces
|
| 838 |
+
|
| 839 |
+
### β οΈ Disclaimer:
|
| 840 |
+
|
| 841 |
+
This platform provides general legal information only.
|
| 842 |
+
Always consult with a qualified attorney for specific legal matters.
|
| 843 |
+
|
| 844 |
+
---
|
| 845 |
+
|
| 846 |
+
**Version 2.1.0** | Built by Solomon7890 | 5-Model AI Legal Platform
|
| 847 |
+
""")
|
| 848 |
+
|
| 849 |
+
# Footer
|
| 850 |
+
gr.Markdown("""
|
| 851 |
+
---
|
| 852 |
+
<div style="text-align: center; padding: 20px;">
|
| 853 |
+
<p><strong>βοΈ ProVerBs Legal AI Platform</strong> | Version 2.1.0 - 5-Model AI Edition</p>
|
| 854 |
+
<p>Powered by: DeepSeek-OCR β’ ERNIE-4.5-VL β’ GDPVAL β’ Llama 3.3 β’ MiniMax-M2</p>
|
| 855 |
+
<p>Β© 2024 ProVerBs Legal AI</p>
|
| 856 |
+
</div>
|
| 857 |
+
""")
|
| 858 |
+
|
| 859 |
+
if __name__ == "__main__":
|
| 860 |
+
demo.queue(max_size=20)
|
| 861 |
+
demo.launch(
|
| 862 |
+
server_name="0.0.0.0",
|
| 863 |
+
server_port=7860,
|
| 864 |
+
share=False,
|
| 865 |
+
show_error=True
|
| 866 |
+
)
|
integrated_chatbot_with_logos.py
ADDED
|
@@ -0,0 +1,538 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
ProVerBs Legal AI - Integrated Landing Page with Rotating Logos
|
| 3 |
+
Features your custom logos with 60-second rotation
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import gradio as gr
|
| 7 |
+
from huggingface_hub import InferenceClient
|
| 8 |
+
import json
|
| 9 |
+
import os
|
| 10 |
+
from datetime import datetime
|
| 11 |
+
from typing import Dict, List, Optional
|
| 12 |
+
import base64
|
| 13 |
+
from pathlib import Path
|
| 14 |
+
|
| 15 |
+
class AILegalChatbotIntegration:
|
| 16 |
+
"""
|
| 17 |
+
Integration of your AI Legal Chatbot into Gradio
|
| 18 |
+
Supports all specialized modes from your original chatbot
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
def __init__(self):
|
| 22 |
+
self.specialized_modes = {
|
| 23 |
+
"navigation": "Application Navigation Guide",
|
| 24 |
+
"general": "General Legal Assistant",
|
| 25 |
+
"document_validation": "Document Validator",
|
| 26 |
+
"legal_research": "Legal Research Assistant",
|
| 27 |
+
"etymology": "Legal Etymology Lookup",
|
| 28 |
+
"case_management": "Case Management Helper",
|
| 29 |
+
"regulatory_updates": "Regulatory Update Monitor"
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
def get_mode_system_prompt(self, mode: str) -> str:
|
| 33 |
+
"""Get specialized system prompt based on mode"""
|
| 34 |
+
prompts = {
|
| 35 |
+
"navigation": """You are a ProVerBs Application Navigation Guide. Help users navigate the application's features:
|
| 36 |
+
|
| 37 |
+
**Available Features:**
|
| 38 |
+
- Legal Action Advisor: Get recommendations for seeking justice
|
| 39 |
+
- Document Analysis: Upload and analyze legal documents
|
| 40 |
+
- Legal Research: Access comprehensive legal databases
|
| 41 |
+
- Communications: SMS, email, and phone integration
|
| 42 |
+
- Document Generation: Create legal documents with AI
|
| 43 |
+
|
| 44 |
+
Guide users to the right features and explain how to use them effectively.""",
|
| 45 |
+
|
| 46 |
+
"general": """You are a General Legal Assistant for ProVerBs Legal AI Platform. Provide accurate legal information while noting that you cannot provide legal advice. Always recommend consulting with a licensed attorney for specific legal matters. Be professional, thorough, and cite relevant legal principles when possible.""",
|
| 47 |
+
|
| 48 |
+
"document_validation": """You are a Document Validator. Analyze legal documents for:
|
| 49 |
+
- Completeness and required elements
|
| 50 |
+
- Legal terminology accuracy
|
| 51 |
+
- Structural integrity
|
| 52 |
+
- Common issues and red flags
|
| 53 |
+
Provide specific feedback on document quality and validity.""",
|
| 54 |
+
|
| 55 |
+
"legal_research": """You are a Legal Research Assistant. Help users:
|
| 56 |
+
- Find relevant case law and precedents
|
| 57 |
+
- Understand statutes and regulations
|
| 58 |
+
- Research legal principles and concepts
|
| 59 |
+
- Cite authoritative legal sources
|
| 60 |
+
Provide comprehensive research guidance.""",
|
| 61 |
+
|
| 62 |
+
"etymology": """You are a Legal Etymology Expert. Explain the origins and meanings of legal terms:
|
| 63 |
+
- Latin and historical roots
|
| 64 |
+
- Evolution of legal terminology
|
| 65 |
+
- Modern usage and interpretation
|
| 66 |
+
- Related legal concepts
|
| 67 |
+
Make legal language accessible and understandable.""",
|
| 68 |
+
|
| 69 |
+
"case_management": """You are a Case Management Helper. Assist with:
|
| 70 |
+
- Organizing case information
|
| 71 |
+
- Tracking deadlines and milestones
|
| 72 |
+
- Managing documents and evidence
|
| 73 |
+
- Coordinating case activities
|
| 74 |
+
Provide practical case management advice.""",
|
| 75 |
+
|
| 76 |
+
"regulatory_updates": """You are a Regulatory Update Monitor. Keep users informed about:
|
| 77 |
+
- Recent legal and regulatory changes
|
| 78 |
+
- Industry-specific compliance updates
|
| 79 |
+
- Important legislative developments
|
| 80 |
+
- Impact analysis of new regulations
|
| 81 |
+
Provide timely and relevant regulatory information."""
|
| 82 |
+
}
|
| 83 |
+
return prompts.get(mode, prompts["general"])
|
| 84 |
+
|
| 85 |
+
def format_navigation_response(self, query: str) -> str:
|
| 86 |
+
"""Format response for navigation queries"""
|
| 87 |
+
query_lower = query.lower()
|
| 88 |
+
|
| 89 |
+
recommendations = []
|
| 90 |
+
|
| 91 |
+
if any(word in query_lower for word in ["document", "contract", "agreement", "analyze"]):
|
| 92 |
+
recommendations.append("π **Document Analysis** - Upload and analyze your documents")
|
| 93 |
+
|
| 94 |
+
if any(word in query_lower for word in ["research", "case", "law", "statute"]):
|
| 95 |
+
recommendations.append("π **Legal Research** - Access comprehensive legal databases")
|
| 96 |
+
|
| 97 |
+
if any(word in query_lower for word in ["action", "remedy", "justice", "sue"]):
|
| 98 |
+
recommendations.append("βοΈ **Legal Action Advisor** - Get recommendations for your situation")
|
| 99 |
+
|
| 100 |
+
if any(word in query_lower for word in ["create", "generate", "template", "form"]):
|
| 101 |
+
recommendations.append("π **Document Generation** - Create legal documents with AI")
|
| 102 |
+
|
| 103 |
+
if any(word in query_lower for word in ["communicate", "message", "sms", "email"]):
|
| 104 |
+
recommendations.append("π§ **Communications** - Integrated messaging system")
|
| 105 |
+
|
| 106 |
+
if recommendations:
|
| 107 |
+
return "### I can help you with these features:\n\n" + "\n".join(recommendations) + "\n\n**What would you like to explore?**"
|
| 108 |
+
|
| 109 |
+
return None
|
| 110 |
+
|
| 111 |
+
def respond_with_mode(
|
| 112 |
+
message,
|
| 113 |
+
history: list,
|
| 114 |
+
mode: str,
|
| 115 |
+
max_tokens: int,
|
| 116 |
+
temperature: float,
|
| 117 |
+
top_p: float,
|
| 118 |
+
hf_token: gr.OAuthToken | None = None
|
| 119 |
+
):
|
| 120 |
+
"""Generate AI response based on selected mode"""
|
| 121 |
+
chatbot_integration = AILegalChatbotIntegration()
|
| 122 |
+
|
| 123 |
+
system_message = chatbot_integration.get_mode_system_prompt(mode)
|
| 124 |
+
|
| 125 |
+
if mode == "navigation":
|
| 126 |
+
nav_response = chatbot_integration.format_navigation_response(message)
|
| 127 |
+
if nav_response:
|
| 128 |
+
yield nav_response
|
| 129 |
+
return
|
| 130 |
+
|
| 131 |
+
token = hf_token.token if hf_token else None
|
| 132 |
+
client = InferenceClient(token=token, model="meta-llama/Llama-3.3-70B-Instruct")
|
| 133 |
+
|
| 134 |
+
messages = [{"role": "system", "content": system_message}]
|
| 135 |
+
|
| 136 |
+
for user_msg, assistant_msg in history:
|
| 137 |
+
if user_msg:
|
| 138 |
+
messages.append({"role": "user", "content": user_msg})
|
| 139 |
+
if assistant_msg:
|
| 140 |
+
messages.append({"role": "assistant", "content": assistant_msg})
|
| 141 |
+
|
| 142 |
+
messages.append({"role": "user", "content": message})
|
| 143 |
+
|
| 144 |
+
response = ""
|
| 145 |
+
try:
|
| 146 |
+
for message_chunk in client.chat_completion(
|
| 147 |
+
messages,
|
| 148 |
+
max_tokens=max_tokens,
|
| 149 |
+
stream=True,
|
| 150 |
+
temperature=temperature,
|
| 151 |
+
top_p=top_p,
|
| 152 |
+
):
|
| 153 |
+
if message_chunk.choices and message_chunk.choices[0].delta.content:
|
| 154 |
+
token = message_chunk.choices[0].delta.content
|
| 155 |
+
response += token
|
| 156 |
+
yield response
|
| 157 |
+
except Exception as e:
|
| 158 |
+
yield f"Error: {str(e)}"
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
# Custom CSS with rotating logo animation
|
| 162 |
+
custom_css = """
|
| 163 |
+
.gradio-container {
|
| 164 |
+
max-width: 1200px !important;
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
.header-section {
|
| 168 |
+
text-align: center;
|
| 169 |
+
padding: 40px 20px;
|
| 170 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 171 |
+
color: white;
|
| 172 |
+
border-radius: 12px;
|
| 173 |
+
margin-bottom: 30px;
|
| 174 |
+
position: relative;
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
.logo-container {
|
| 178 |
+
margin-bottom: 20px;
|
| 179 |
+
display: flex;
|
| 180 |
+
justify-content: center;
|
| 181 |
+
align-items: center;
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
.rotating-logo {
|
| 185 |
+
width: 150px;
|
| 186 |
+
height: 150px;
|
| 187 |
+
border-radius: 50%;
|
| 188 |
+
object-fit: cover;
|
| 189 |
+
border: 4px solid rgba(255, 255, 255, 0.8);
|
| 190 |
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
|
| 191 |
+
animation: fadeInOut 60s infinite;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
@keyframes fadeInOut {
|
| 195 |
+
0%, 20% { opacity: 1; }
|
| 196 |
+
25%, 45% { opacity: 0; }
|
| 197 |
+
50%, 70% { opacity: 1; }
|
| 198 |
+
75%, 95% { opacity: 0; }
|
| 199 |
+
100% { opacity: 1; }
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
.logo-1 { animation-delay: 0s; }
|
| 203 |
+
.logo-2 { animation-delay: 20s; }
|
| 204 |
+
.logo-3 { animation-delay: 40s; }
|
| 205 |
+
|
| 206 |
+
.header-section h1 {
|
| 207 |
+
font-size: 3rem;
|
| 208 |
+
margin-bottom: 10px;
|
| 209 |
+
font-weight: 700;
|
| 210 |
+
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
.mode-selector {
|
| 214 |
+
font-size: 1.1rem !important;
|
| 215 |
+
font-weight: 600 !important;
|
| 216 |
+
padding: 12px !important;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
.tab-nav button {
|
| 220 |
+
font-size: 16px;
|
| 221 |
+
font-weight: 600;
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
.feature-card {
|
| 225 |
+
border: 2px solid #e0e0e0;
|
| 226 |
+
border-radius: 12px;
|
| 227 |
+
padding: 20px;
|
| 228 |
+
margin: 10px;
|
| 229 |
+
background: #f8f9fa;
|
| 230 |
+
transition: all 0.3s;
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
.feature-card:hover {
|
| 234 |
+
border-color: #667eea;
|
| 235 |
+
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
|
| 236 |
+
transform: translateY(-2px);
|
| 237 |
+
}
|
| 238 |
+
"""
|
| 239 |
+
|
| 240 |
+
# JavaScript for rotating logos
|
| 241 |
+
rotating_logo_js = """
|
| 242 |
+
<script>
|
| 243 |
+
function rotateLogo() {
|
| 244 |
+
const logos = document.querySelectorAll('.rotating-logo');
|
| 245 |
+
let currentIndex = 0;
|
| 246 |
+
|
| 247 |
+
function showNextLogo() {
|
| 248 |
+
logos.forEach((logo, index) => {
|
| 249 |
+
logo.style.display = 'none';
|
| 250 |
+
});
|
| 251 |
+
|
| 252 |
+
logos[currentIndex].style.display = 'block';
|
| 253 |
+
|
| 254 |
+
currentIndex = (currentIndex + 1) % logos.length;
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
// Show first logo initially
|
| 258 |
+
showNextLogo();
|
| 259 |
+
|
| 260 |
+
// Rotate every 60 seconds
|
| 261 |
+
setInterval(showNextLogo, 60000);
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
// Start rotation when page loads
|
| 265 |
+
if (document.readyState === 'loading') {
|
| 266 |
+
document.addEventListener('DOMContentLoaded', rotateLogo);
|
| 267 |
+
} else {
|
| 268 |
+
rotateLogo();
|
| 269 |
+
}
|
| 270 |
+
</script>
|
| 271 |
+
"""
|
| 272 |
+
|
| 273 |
+
# Create the main application
|
| 274 |
+
demo = gr.Blocks(title="ProVerBs Legal AI Platform")
|
| 275 |
+
demo.css = custom_css
|
| 276 |
+
|
| 277 |
+
with demo:
|
| 278 |
+
|
| 279 |
+
# Header with Rotating Logos
|
| 280 |
+
gr.HTML(f"""
|
| 281 |
+
<div class="header-section">
|
| 282 |
+
<div class="logo-container">
|
| 283 |
+
<img src="file/assets/logo_1.jpg" class="rotating-logo logo-1" alt="ProVerBs Logo 1" style="display: block;">
|
| 284 |
+
<img src="file/assets/logo_2.jpg" class="rotating-logo logo-2" alt="ProVerBs Logo 2" style="display: none;">
|
| 285 |
+
<img src="file/assets/logo_3.jpg" class="rotating-logo logo-3" alt="ProVerBs Logo 3" style="display: none;">
|
| 286 |
+
</div>
|
| 287 |
+
<h1>βοΈ ProVerBs Legal AI Platform</h1>
|
| 288 |
+
<p>Lawful vs. Legal: Dual Analysis "Adappt'plication"</p>
|
| 289 |
+
<p style="font-size: 1rem; margin-top: 10px;">
|
| 290 |
+
Professional Legal AI System | Multi-Module Platform | Powered by Advanced AI
|
| 291 |
+
</p>
|
| 292 |
+
</div>
|
| 293 |
+
{rotating_logo_js}
|
| 294 |
+
""")
|
| 295 |
+
|
| 296 |
+
# Login Section (commented out for local preview)
|
| 297 |
+
# with gr.Row():
|
| 298 |
+
# with gr.Column(scale=1):
|
| 299 |
+
# gr.LoginButton(size="lg")
|
| 300 |
+
# with gr.Column(scale=5):
|
| 301 |
+
# gr.Markdown("π **Login with your Hugging Face account** for full access")
|
| 302 |
+
|
| 303 |
+
gr.Markdown("---")
|
| 304 |
+
|
| 305 |
+
# Main Tabs
|
| 306 |
+
with gr.Tabs() as tabs:
|
| 307 |
+
|
| 308 |
+
# Tab 1: Welcome
|
| 309 |
+
with gr.Tab("π Welcome", id="welcome"):
|
| 310 |
+
gr.Markdown("""
|
| 311 |
+
## Welcome to ProVerBs Legal AI Platform
|
| 312 |
+
|
| 313 |
+
A comprehensive legal AI system with **multiple specialized assistants** to help you navigate legal matters.
|
| 314 |
+
|
| 315 |
+
### π― Choose Your AI Assistant Mode
|
| 316 |
+
|
| 317 |
+
Our platform features **7 specialized AI modes** to serve your specific needs:
|
| 318 |
+
|
| 319 |
+
- **π Navigation Guide** - Help finding features in the platform
|
| 320 |
+
- **π¬ General Legal Assistant** - Broad legal questions and guidance
|
| 321 |
+
- **π Document Validator** - Analyze and validate legal documents
|
| 322 |
+
- **π Legal Research** - Case law and statutory research
|
| 323 |
+
- **π Etymology Expert** - Understanding legal terminology origins
|
| 324 |
+
- **πΌ Case Management** - Organizing and tracking legal cases
|
| 325 |
+
- **π Regulatory Updates** - Stay informed about legal changes
|
| 326 |
+
|
| 327 |
+
### βοΈ Platform Features
|
| 328 |
+
|
| 329 |
+
- **Legal Action Advisor** - Get personalized recommendations
|
| 330 |
+
- **Document Analysis** - AI-powered document processing
|
| 331 |
+
- **Legal Research Tools** - Comprehensive databases
|
| 332 |
+
- **Communications** - Integrated SMS, email, phone
|
| 333 |
+
- **Document Generation** - Create legal documents with AI
|
| 334 |
+
|
| 335 |
+
**Ready to start?** Click the "AI Legal Chatbot" tab to begin!
|
| 336 |
+
""")
|
| 337 |
+
|
| 338 |
+
# Tab 2: AI Legal Chatbot
|
| 339 |
+
with gr.Tab("π€ AI Legal Chatbot", id="chatbot"):
|
| 340 |
+
gr.Markdown("""
|
| 341 |
+
## AI Legal Chatbot - Multiple Specialized Modes
|
| 342 |
+
|
| 343 |
+
Select your assistant mode below and start chatting!
|
| 344 |
+
""")
|
| 345 |
+
|
| 346 |
+
mode_selector = gr.Dropdown(
|
| 347 |
+
choices=list({
|
| 348 |
+
"navigation": "π Navigation Guide - Find features in the app",
|
| 349 |
+
"general": "π¬ General Legal Assistant - Broad legal questions",
|
| 350 |
+
"document_validation": "π Document Validator - Analyze documents",
|
| 351 |
+
"legal_research": "π Legal Research - Case law & statutes",
|
| 352 |
+
"etymology": "π Etymology Expert - Legal term origins",
|
| 353 |
+
"case_management": "πΌ Case Management - Organize cases",
|
| 354 |
+
"regulatory_updates": "π Regulatory Updates - Legal changes"
|
| 355 |
+
}.items()),
|
| 356 |
+
value="navigation",
|
| 357 |
+
label="Select AI Assistant Mode",
|
| 358 |
+
elem_classes=["mode-selector"]
|
| 359 |
+
)
|
| 360 |
+
|
| 361 |
+
gr.Markdown("---")
|
| 362 |
+
|
| 363 |
+
chatbot = gr.ChatInterface(
|
| 364 |
+
lambda message, history, mode, max_tokens, temperature, top_p, hf_token:
|
| 365 |
+
respond_with_mode(message, history, mode.split(":")[0], max_tokens, temperature, top_p, hf_token),
|
| 366 |
+
chatbot=gr.Chatbot(
|
| 367 |
+
height=500,
|
| 368 |
+
placeholder="π¬ Select a mode above and ask your question...",
|
| 369 |
+
show_label=False,
|
| 370 |
+
),
|
| 371 |
+
textbox=gr.Textbox(
|
| 372 |
+
placeholder="Type your question here...",
|
| 373 |
+
container=False,
|
| 374 |
+
scale=7
|
| 375 |
+
),
|
| 376 |
+
additional_inputs=[
|
| 377 |
+
mode_selector,
|
| 378 |
+
gr.Slider(128, 4096, value=2048, step=128, label="Max Tokens"),
|
| 379 |
+
gr.Slider(0.1, 2.0, value=0.7, step=0.1, label="Temperature"),
|
| 380 |
+
gr.Slider(0.1, 1.0, value=0.95, step=0.05, label="Top-p"),
|
| 381 |
+
],
|
| 382 |
+
examples=[
|
| 383 |
+
["How do I navigate to the document analysis feature?"],
|
| 384 |
+
["What is the difference between lawful and legal?"],
|
| 385 |
+
["Can you help me validate a contract?"],
|
| 386 |
+
["I need to research case law about contracts"],
|
| 387 |
+
["What does 'habeas corpus' mean?"],
|
| 388 |
+
["How do I organize my legal case documents?"],
|
| 389 |
+
["What are the latest regulatory changes in business law?"],
|
| 390 |
+
],
|
| 391 |
+
cache_examples=False,
|
| 392 |
+
)
|
| 393 |
+
|
| 394 |
+
gr.Markdown("""
|
| 395 |
+
### π‘ Tips for Best Results
|
| 396 |
+
|
| 397 |
+
- **Choose the right mode** for your question type
|
| 398 |
+
- **Be specific** with your questions
|
| 399 |
+
- **Navigation Mode** helps you find features in the app
|
| 400 |
+
- Each mode is specialized for different tasks!
|
| 401 |
+
""")
|
| 402 |
+
|
| 403 |
+
# Tab 3: Features Overview
|
| 404 |
+
with gr.Tab("β¨ Features", id="features"):
|
| 405 |
+
gr.Markdown("""
|
| 406 |
+
## Platform Features
|
| 407 |
+
|
| 408 |
+
### π― Core Capabilities
|
| 409 |
+
""")
|
| 410 |
+
|
| 411 |
+
with gr.Row():
|
| 412 |
+
with gr.Column():
|
| 413 |
+
gr.Markdown("""
|
| 414 |
+
<div class="feature-card">
|
| 415 |
+
|
| 416 |
+
#### βοΈ Legal Action Advisor
|
| 417 |
+
Get personalized recommendations for seeking justice and remedy
|
| 418 |
+
|
| 419 |
+
- AI-powered action recommendations
|
| 420 |
+
- Case type analysis
|
| 421 |
+
- Timeline planning
|
| 422 |
+
- Free resource finder
|
| 423 |
+
- Evidence collection guidance
|
| 424 |
+
</div>
|
| 425 |
+
""")
|
| 426 |
+
|
| 427 |
+
with gr.Column():
|
| 428 |
+
gr.Markdown("""
|
| 429 |
+
<div class="feature-card">
|
| 430 |
+
|
| 431 |
+
#### π Document Analysis
|
| 432 |
+
Upload and analyze legal documents with AI insights
|
| 433 |
+
|
| 434 |
+
- OCR text extraction
|
| 435 |
+
- Multi-format support (PDF, DOCX, TXT)
|
| 436 |
+
- AI-powered analysis
|
| 437 |
+
- Legal database cross-reference
|
| 438 |
+
- Document validation
|
| 439 |
+
</div>
|
| 440 |
+
""")
|
| 441 |
+
|
| 442 |
+
with gr.Row():
|
| 443 |
+
with gr.Column():
|
| 444 |
+
gr.Markdown("""
|
| 445 |
+
<div class="feature-card">
|
| 446 |
+
|
| 447 |
+
#### π Legal Research
|
| 448 |
+
Comprehensive legal research tools and databases
|
| 449 |
+
|
| 450 |
+
- Multiple legal databases
|
| 451 |
+
- Case law research
|
| 452 |
+
- Statutory analysis
|
| 453 |
+
- Historical documents
|
| 454 |
+
- Citation tools
|
| 455 |
+
</div>
|
| 456 |
+
""")
|
| 457 |
+
|
| 458 |
+
with gr.Column():
|
| 459 |
+
gr.Markdown("""
|
| 460 |
+
<div class="feature-card">
|
| 461 |
+
|
| 462 |
+
#### π§ Communications
|
| 463 |
+
Integrated communication system
|
| 464 |
+
|
| 465 |
+
- Twilio integration
|
| 466 |
+
- SMS messaging
|
| 467 |
+
- Email notifications
|
| 468 |
+
- Phone capabilities
|
| 469 |
+
- Legal alerts & reminders
|
| 470 |
+
</div>
|
| 471 |
+
""")
|
| 472 |
+
|
| 473 |
+
# Tab 4: About
|
| 474 |
+
with gr.Tab("βΉοΈ About", id="about"):
|
| 475 |
+
gr.Markdown("""
|
| 476 |
+
## About ProVerBs Legal AI
|
| 477 |
+
|
| 478 |
+
### π Our Platform
|
| 479 |
+
|
| 480 |
+
ProVerBs Legal AI combines advanced artificial intelligence with comprehensive legal knowledge
|
| 481 |
+
to provide accessible, accurate legal information and tools.
|
| 482 |
+
|
| 483 |
+
### π€ Specialized AI Chatbot
|
| 484 |
+
|
| 485 |
+
Our AI chatbot features **7 specialized modes**, each trained for specific legal tasks.
|
| 486 |
+
|
| 487 |
+
### π₯ Who We Serve
|
| 488 |
+
|
| 489 |
+
- **Legal Professionals** - Enhance your practice with AI
|
| 490 |
+
- **Law Students** - Research and study assistance
|
| 491 |
+
- **Businesses** - Understand legal implications
|
| 492 |
+
- **Individuals** - Learn about your legal rights
|
| 493 |
+
|
| 494 |
+
### π Privacy & Security
|
| 495 |
+
|
| 496 |
+
- End-to-end encryption
|
| 497 |
+
- No storage without consent
|
| 498 |
+
- GDPR and CCPA compliant
|
| 499 |
+
- Secure OAuth authentication
|
| 500 |
+
|
| 501 |
+
### β οΈ Important Disclaimer
|
| 502 |
+
|
| 503 |
+
This platform provides general legal information only. It does not constitute legal advice.
|
| 504 |
+
Always consult with a qualified attorney for specific legal matters.
|
| 505 |
+
|
| 506 |
+
---
|
| 507 |
+
|
| 508 |
+
**Version 1.0.0** | Built by Solomon7890 | Powered by Hugging Face
|
| 509 |
+
""")
|
| 510 |
+
|
| 511 |
+
# Footer
|
| 512 |
+
gr.Markdown("""
|
| 513 |
+
---
|
| 514 |
+
|
| 515 |
+
<div style="text-align: center; padding: 20px; color: #666;">
|
| 516 |
+
<p><strong>βοΈ ProVerBs Legal AI Platform</strong> | Version 1.0.0</p>
|
| 517 |
+
<p>
|
| 518 |
+
<a href="https://huggingface.co/Solomon7890" target="_blank">Hugging Face</a> |
|
| 519 |
+
<a href="https://github.com/Solomon7890" target="_blank">GitHub</a>
|
| 520 |
+
</p>
|
| 521 |
+
<p style="font-size: 0.9rem; margin-top: 10px;">
|
| 522 |
+
β οΈ <strong>Disclaimer</strong>: This AI provides general legal information only.
|
| 523 |
+
Consult with a licensed attorney for specific legal matters.
|
| 524 |
+
</p>
|
| 525 |
+
<p style="font-size: 0.85rem; color: #999;">
|
| 526 |
+
Β© 2024 ProVerBs Legal AI. Built with β€οΈ for legal professionals worldwide.
|
| 527 |
+
</p>
|
| 528 |
+
</div>
|
| 529 |
+
""")
|
| 530 |
+
|
| 531 |
+
if __name__ == "__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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
ProVerBs Legal AI - Enhanced with DeepSeek-OCR Integration
|
| 3 |
+
Features: 7 AI Modes + Rotating Logos + OCR Document Processing
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import gradio as gr
|
| 7 |
+
from huggingface_hub import InferenceClient
|
| 8 |
+
import json
|
| 9 |
+
import os
|
| 10 |
+
from datetime import datetime
|
| 11 |
+
from typing import Dict, List, Optional
|
| 12 |
+
import base64
|
| 13 |
+
from pathlib import Path
|
| 14 |
+
|
| 15 |
+
# OCR Integration
|
| 16 |
+
try:
|
| 17 |
+
from transformers import pipeline, AutoModel
|
| 18 |
+
OCR_AVAILABLE = True
|
| 19 |
+
except ImportError:
|
| 20 |
+
OCR_AVAILABLE = False
|
| 21 |
+
print("β οΈ Transformers not installed. OCR features will be limited.")
|
| 22 |
+
|
| 23 |
+
class AILegalChatbotIntegration:
|
| 24 |
+
"""
|
| 25 |
+
Integration of AI Legal Chatbot with OCR capabilities
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
def __init__(self):
|
| 29 |
+
self.specialized_modes = {
|
| 30 |
+
"navigation": "Application Navigation Guide",
|
| 31 |
+
"general": "General Legal Assistant",
|
| 32 |
+
"document_validation": "Document Validator with OCR",
|
| 33 |
+
"legal_research": "Legal Research Assistant",
|
| 34 |
+
"etymology": "Legal Etymology Lookup",
|
| 35 |
+
"case_management": "Case Management Helper",
|
| 36 |
+
"regulatory_updates": "Regulatory Update Monitor"
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
# Initialize OCR if available
|
| 40 |
+
self.ocr_pipeline = None
|
| 41 |
+
if OCR_AVAILABLE:
|
| 42 |
+
try:
|
| 43 |
+
print("π¦ Loading DeepSeek-OCR model...")
|
| 44 |
+
self.ocr_pipeline = pipeline(
|
| 45 |
+
"image-text-to-text",
|
| 46 |
+
model="deepseek-ai/DeepSeek-OCR",
|
| 47 |
+
trust_remote_code=True
|
| 48 |
+
)
|
| 49 |
+
print("β
OCR model loaded successfully!")
|
| 50 |
+
except Exception as e:
|
| 51 |
+
print(f"β οΈ Could not load OCR model: {e}")
|
| 52 |
+
self.ocr_pipeline = None
|
| 53 |
+
|
| 54 |
+
def process_document_with_ocr(self, image_path: str) -> str:
|
| 55 |
+
"""
|
| 56 |
+
Extract text from document image using DeepSeek-OCR
|
| 57 |
+
"""
|
| 58 |
+
if not self.ocr_pipeline:
|
| 59 |
+
return "β OCR model not available. Please install transformers and torch."
|
| 60 |
+
|
| 61 |
+
try:
|
| 62 |
+
# Process image with OCR
|
| 63 |
+
result = self.ocr_pipeline(image_path)
|
| 64 |
+
extracted_text = result[0]['generated_text'] if result else ""
|
| 65 |
+
|
| 66 |
+
return f"""
|
| 67 |
+
## π OCR Extraction Results
|
| 68 |
+
|
| 69 |
+
**Status**: β
Text extracted successfully
|
| 70 |
+
|
| 71 |
+
**Extracted Text:**
|
| 72 |
+
```
|
| 73 |
+
{extracted_text}
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
**Document Analysis:**
|
| 77 |
+
- **Length**: {len(extracted_text)} characters
|
| 78 |
+
- **Word Count**: {len(extracted_text.split())} words
|
| 79 |
+
- **Contains Legal Terms**: {self._check_legal_terms(extracted_text)}
|
| 80 |
+
|
| 81 |
+
**Next Steps:**
|
| 82 |
+
- Review the extracted text for accuracy
|
| 83 |
+
- Use Document Validator mode to analyze the content
|
| 84 |
+
- Ask questions about specific clauses or terms
|
| 85 |
+
"""
|
| 86 |
+
except Exception as e:
|
| 87 |
+
return f"β OCR processing error: {str(e)}"
|
| 88 |
+
|
| 89 |
+
def _check_legal_terms(self, text: str) -> str:
|
| 90 |
+
"""Check for common legal terms in text"""
|
| 91 |
+
legal_terms = [
|
| 92 |
+
'contract', 'agreement', 'party', 'clause', 'provision',
|
| 93 |
+
'whereas', 'hereby', 'herein', 'pursuant', 'consideration',
|
| 94 |
+
'liability', 'indemnify', 'warranty', 'breach', 'terminate'
|
| 95 |
+
]
|
| 96 |
+
|
| 97 |
+
found_terms = [term for term in legal_terms if term.lower() in text.lower()]
|
| 98 |
+
|
| 99 |
+
if found_terms:
|
| 100 |
+
return f"Yes ({len(found_terms)} terms: {', '.join(found_terms[:5])}...)"
|
| 101 |
+
return "No"
|
| 102 |
+
|
| 103 |
+
def get_mode_system_prompt(self, mode: str) -> str:
|
| 104 |
+
"""Get specialized system prompt based on mode"""
|
| 105 |
+
prompts = {
|
| 106 |
+
"navigation": """You are a ProVerBs Application Navigation Guide. Help users navigate the application's features:
|
| 107 |
+
|
| 108 |
+
**Available Features:**
|
| 109 |
+
- Legal Action Advisor: Get recommendations for seeking justice
|
| 110 |
+
- Document Analysis with OCR: Upload and analyze legal documents (now with OCR support!)
|
| 111 |
+
- Legal Research: Access comprehensive legal databases
|
| 112 |
+
- Communications: SMS, email, and phone integration
|
| 113 |
+
- Document Generation: Create legal documents with AI
|
| 114 |
+
|
| 115 |
+
**NEW: OCR Document Processing**
|
| 116 |
+
Users can now upload scanned documents and images. The system will extract text automatically using DeepSeek-OCR.
|
| 117 |
+
|
| 118 |
+
Guide users to the right features and explain how to use them effectively.""",
|
| 119 |
+
|
| 120 |
+
"general": """You are a General Legal Assistant for ProVerBs Legal AI Platform. Provide accurate legal information while noting that you cannot provide legal advice. Always recommend consulting with a licensed attorney for specific legal matters. Be professional, thorough, and cite relevant legal principles when possible.""",
|
| 121 |
+
|
| 122 |
+
"document_validation": """You are a Document Validator with OCR capabilities.
|
| 123 |
+
|
| 124 |
+
**Enhanced Features:**
|
| 125 |
+
- Analyze documents from text or uploaded images
|
| 126 |
+
- Use DeepSeek-OCR to extract text from scanned documents
|
| 127 |
+
- Check for completeness and required elements
|
| 128 |
+
- Verify legal terminology accuracy
|
| 129 |
+
- Identify structural integrity issues
|
| 130 |
+
- Flag common problems and red flags
|
| 131 |
+
|
| 132 |
+
**When analyzing documents:**
|
| 133 |
+
1. If it's an image, use OCR to extract text first
|
| 134 |
+
2. Analyze the extracted or provided text
|
| 135 |
+
3. Check for legal validity and completeness
|
| 136 |
+
4. Provide specific feedback on document quality
|
| 137 |
+
|
| 138 |
+
Provide specific, actionable feedback on document quality and validity.""",
|
| 139 |
+
|
| 140 |
+
"legal_research": """You are a Legal Research Assistant. Help users:
|
| 141 |
+
- Find relevant case law and precedents
|
| 142 |
+
- Understand statutes and regulations
|
| 143 |
+
- Research legal principles and concepts
|
| 144 |
+
- Cite authoritative legal sources
|
| 145 |
+
- Analyze legal documents and extract key information
|
| 146 |
+
Provide comprehensive research guidance.""",
|
| 147 |
+
|
| 148 |
+
"etymology": """You are a Legal Etymology Expert. Explain the origins and meanings of legal terms:
|
| 149 |
+
- Latin and historical roots
|
| 150 |
+
- Evolution of legal terminology
|
| 151 |
+
- Modern usage and interpretation
|
| 152 |
+
- Related legal concepts
|
| 153 |
+
Make legal language accessible and understandable.""",
|
| 154 |
+
|
| 155 |
+
"case_management": """You are a Case Management Helper. Assist with:
|
| 156 |
+
- Organizing case information
|
| 157 |
+
- Tracking deadlines and milestones
|
| 158 |
+
- Managing documents and evidence (including OCR-processed documents)
|
| 159 |
+
- Coordinating case activities
|
| 160 |
+
Provide practical case management advice.""",
|
| 161 |
+
|
| 162 |
+
"regulatory_updates": """You are a Regulatory Update Monitor. Keep users informed about:
|
| 163 |
+
- Recent legal and regulatory changes
|
| 164 |
+
- Industry-specific compliance updates
|
| 165 |
+
- Important legislative developments
|
| 166 |
+
- Impact analysis of new regulations
|
| 167 |
+
Provide timely and relevant regulatory information."""
|
| 168 |
+
}
|
| 169 |
+
return prompts.get(mode, prompts["general"])
|
| 170 |
+
|
| 171 |
+
def format_navigation_response(self, query: str) -> str:
|
| 172 |
+
"""Format response for navigation queries"""
|
| 173 |
+
query_lower = query.lower()
|
| 174 |
+
|
| 175 |
+
recommendations = []
|
| 176 |
+
|
| 177 |
+
if any(word in query_lower for word in ["document", "contract", "agreement", "analyze", "scan", "ocr", "image"]):
|
| 178 |
+
recommendations.append("π **Document Analysis with OCR** - Upload scanned documents or images for analysis")
|
| 179 |
+
|
| 180 |
+
if any(word in query_lower for word in ["research", "case", "law", "statute"]):
|
| 181 |
+
recommendations.append("π **Legal Research** - Access comprehensive legal databases")
|
| 182 |
+
|
| 183 |
+
if any(word in query_lower for word in ["action", "remedy", "justice", "sue"]):
|
| 184 |
+
recommendations.append("βοΈ **Legal Action Advisor** - Get recommendations for your situation")
|
| 185 |
+
|
| 186 |
+
if any(word in query_lower for word in ["create", "generate", "template", "form"]):
|
| 187 |
+
recommendations.append("π **Document Generation** - Create legal documents with AI")
|
| 188 |
+
|
| 189 |
+
if any(word in query_lower for word in ["communicate", "message", "sms", "email"]):
|
| 190 |
+
recommendations.append("π§ **Communications** - Integrated messaging system")
|
| 191 |
+
|
| 192 |
+
if recommendations:
|
| 193 |
+
return "### I can help you with these features:\n\n" + "\n".join(recommendations) + "\n\n**What would you like to explore?**"
|
| 194 |
+
|
| 195 |
+
return None
|
| 196 |
+
|
| 197 |
+
def respond_with_mode(
|
| 198 |
+
message,
|
| 199 |
+
history: list,
|
| 200 |
+
mode: str,
|
| 201 |
+
max_tokens: int,
|
| 202 |
+
temperature: float,
|
| 203 |
+
top_p: float,
|
| 204 |
+
):
|
| 205 |
+
"""Generate AI response based on selected mode"""
|
| 206 |
+
chatbot_integration = AILegalChatbotIntegration()
|
| 207 |
+
|
| 208 |
+
system_message = chatbot_integration.get_mode_system_prompt(mode)
|
| 209 |
+
|
| 210 |
+
if mode == "navigation":
|
| 211 |
+
nav_response = chatbot_integration.format_navigation_response(message)
|
| 212 |
+
if nav_response:
|
| 213 |
+
yield nav_response
|
| 214 |
+
return
|
| 215 |
+
|
| 216 |
+
# For document validation mode, mention OCR capability
|
| 217 |
+
if mode == "document_validation" and not message:
|
| 218 |
+
yield """
|
| 219 |
+
## π Document Validator with OCR
|
| 220 |
+
|
| 221 |
+
**Capabilities:**
|
| 222 |
+
- β
Analyze legal documents
|
| 223 |
+
- β
Extract text from scanned documents (OCR)
|
| 224 |
+
- β
Validate document structure
|
| 225 |
+
- β
Check for legal completeness
|
| 226 |
+
|
| 227 |
+
**How to use:**
|
| 228 |
+
1. Upload a document image or paste text
|
| 229 |
+
2. I'll extract and analyze the content
|
| 230 |
+
3. Get detailed validation feedback
|
| 231 |
+
|
| 232 |
+
**Ask me to:**
|
| 233 |
+
- "Validate this contract"
|
| 234 |
+
- "Check this document for issues"
|
| 235 |
+
- "Extract text from this image"
|
| 236 |
+
"""
|
| 237 |
+
return
|
| 238 |
+
|
| 239 |
+
# Use HF Inference API
|
| 240 |
+
try:
|
| 241 |
+
client = InferenceClient(model="meta-llama/Llama-3.3-70B-Instruct")
|
| 242 |
+
|
| 243 |
+
messages = [{"role": "system", "content": system_message}]
|
| 244 |
+
|
| 245 |
+
for user_msg, assistant_msg in history:
|
| 246 |
+
if user_msg:
|
| 247 |
+
messages.append({"role": "user", "content": user_msg})
|
| 248 |
+
if assistant_msg:
|
| 249 |
+
messages.append({"role": "assistant", "content": assistant_msg})
|
| 250 |
+
|
| 251 |
+
messages.append({"role": "user", "content": message})
|
| 252 |
+
|
| 253 |
+
response = ""
|
| 254 |
+
for message_chunk in client.chat_completion(
|
| 255 |
+
messages,
|
| 256 |
+
max_tokens=max_tokens,
|
| 257 |
+
stream=True,
|
| 258 |
+
temperature=temperature,
|
| 259 |
+
top_p=top_p,
|
| 260 |
+
):
|
| 261 |
+
if message_chunk.choices and message_chunk.choices[0].delta.content:
|
| 262 |
+
token = message_chunk.choices[0].delta.content
|
| 263 |
+
response += token
|
| 264 |
+
yield response
|
| 265 |
+
except Exception as e:
|
| 266 |
+
yield f"Error: {str(e)}\n\nNote: For full functionality, please ensure you're connected to Hugging Face."
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
# Custom CSS with rotating logo animation
|
| 270 |
+
custom_css = """
|
| 271 |
+
.gradio-container {
|
| 272 |
+
max-width: 1200px !important;
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
.header-section {
|
| 276 |
+
text-align: center;
|
| 277 |
+
padding: 40px 20px;
|
| 278 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 279 |
+
color: white;
|
| 280 |
+
border-radius: 12px;
|
| 281 |
+
margin-bottom: 30px;
|
| 282 |
+
position: relative;
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
.logo-container {
|
| 286 |
+
margin-bottom: 20px;
|
| 287 |
+
display: flex;
|
| 288 |
+
justify-content: center;
|
| 289 |
+
align-items: center;
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
.rotating-logo {
|
| 293 |
+
width: 150px;
|
| 294 |
+
height: 150px;
|
| 295 |
+
border-radius: 50%;
|
| 296 |
+
object-fit: cover;
|
| 297 |
+
border: 4px solid rgba(255, 255, 255, 0.8);
|
| 298 |
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
|
| 299 |
+
animation: fadeInOut 60s infinite;
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
+
@keyframes fadeInOut {
|
| 303 |
+
0%, 20% { opacity: 1; }
|
| 304 |
+
25%, 45% { opacity: 0; }
|
| 305 |
+
50%, 70% { opacity: 1; }
|
| 306 |
+
75%, 95% { opacity: 0; }
|
| 307 |
+
100% { opacity: 1; }
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
.logo-1 { animation-delay: 0s; }
|
| 311 |
+
.logo-2 { animation-delay: 20s; }
|
| 312 |
+
.logo-3 { animation-delay: 40s; }
|
| 313 |
+
|
| 314 |
+
.header-section h1 {
|
| 315 |
+
font-size: 3rem;
|
| 316 |
+
margin-bottom: 10px;
|
| 317 |
+
font-weight: 700;
|
| 318 |
+
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
.mode-selector {
|
| 322 |
+
font-size: 1.1rem !important;
|
| 323 |
+
font-weight: 600 !important;
|
| 324 |
+
padding: 12px !important;
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
.tab-nav button {
|
| 328 |
+
font-size: 16px;
|
| 329 |
+
font-weight: 600;
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
.feature-card {
|
| 333 |
+
border: 2px solid #e0e0e0;
|
| 334 |
+
border-radius: 12px;
|
| 335 |
+
padding: 20px;
|
| 336 |
+
margin: 10px;
|
| 337 |
+
background: #f8f9fa;
|
| 338 |
+
transition: all 0.3s;
|
| 339 |
+
}
|
| 340 |
+
|
| 341 |
+
.feature-card:hover {
|
| 342 |
+
border-color: #667eea;
|
| 343 |
+
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
|
| 344 |
+
transform: translateY(-2px);
|
| 345 |
+
}
|
| 346 |
+
"""
|
| 347 |
+
|
| 348 |
+
# JavaScript for rotating logos
|
| 349 |
+
rotating_logo_js = """
|
| 350 |
+
<script>
|
| 351 |
+
function rotateLogo() {
|
| 352 |
+
const logos = document.querySelectorAll('.rotating-logo');
|
| 353 |
+
let currentIndex = 0;
|
| 354 |
+
|
| 355 |
+
function showNextLogo() {
|
| 356 |
+
logos.forEach((logo, index) => {
|
| 357 |
+
logo.style.display = 'none';
|
| 358 |
+
});
|
| 359 |
+
|
| 360 |
+
logos[currentIndex].style.display = 'block';
|
| 361 |
+
|
| 362 |
+
currentIndex = (currentIndex + 1) % logos.length;
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
showNextLogo();
|
| 366 |
+
setInterval(showNextLogo, 60000);
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
if (document.readyState === 'loading') {
|
| 370 |
+
document.addEventListener('DOMContentLoaded', rotateLogo);
|
| 371 |
+
} else {
|
| 372 |
+
rotateLogo();
|
| 373 |
+
}
|
| 374 |
+
</script>
|
| 375 |
+
"""
|
| 376 |
+
|
| 377 |
+
# Create the main application
|
| 378 |
+
demo = gr.Blocks(title="ProVerBs Legal AI Platform")
|
| 379 |
+
|
| 380 |
+
with demo:
|
| 381 |
+
|
| 382 |
+
# Header with Rotating Logos
|
| 383 |
+
gr.HTML(f"""
|
| 384 |
+
<div class="header-section">
|
| 385 |
+
<div class="logo-container">
|
| 386 |
+
<img src="file/assets/logo_1.jpg" class="rotating-logo logo-1" alt="ProVerBs Logo 1" style="display: block;">
|
| 387 |
+
<img src="file/assets/logo_2.jpg" class="rotating-logo logo-2" alt="ProVerBs Logo 2" style="display: none;">
|
| 388 |
+
<img src="file/assets/logo_3.jpg" class="rotating-logo logo-3" alt="ProVerBs Logo 3" style="display: none;">
|
| 389 |
+
</div>
|
| 390 |
+
<h1>βοΈ ProVerBs Legal AI Platform</h1>
|
| 391 |
+
<p>Lawful vs. Legal: Dual Analysis "Adappt'plication"</p>
|
| 392 |
+
<p style="font-size: 1rem; margin-top: 10px;">
|
| 393 |
+
Professional Legal AI System | Multi-Module Platform | Now with OCR! π
|
| 394 |
+
</p>
|
| 395 |
+
</div>
|
| 396 |
+
<style>{custom_css}</style>
|
| 397 |
+
{rotating_logo_js}
|
| 398 |
+
""")
|
| 399 |
+
|
| 400 |
+
gr.Markdown("---")
|
| 401 |
+
|
| 402 |
+
# Main Tabs
|
| 403 |
+
with gr.Tabs() as tabs:
|
| 404 |
+
|
| 405 |
+
# Tab 1: Welcome
|
| 406 |
+
with gr.Tab("π Welcome", id="welcome"):
|
| 407 |
+
gr.Markdown("""
|
| 408 |
+
## Welcome to ProVerBs Legal AI Platform
|
| 409 |
+
|
| 410 |
+
A comprehensive legal AI system with **7 specialized assistants** and **OCR document processing**!
|
| 411 |
+
|
| 412 |
+
### π― Choose Your AI Assistant Mode
|
| 413 |
+
|
| 414 |
+
- **π Navigation Guide** - Find features in the platform
|
| 415 |
+
- **π¬ General Legal Assistant** - Broad legal questions
|
| 416 |
+
- **π Document Validator with OCR** β NEW! - Analyze scanned documents
|
| 417 |
+
- **π Legal Research** - Case law and statutory research
|
| 418 |
+
- **π Etymology Expert** - Legal terminology origins
|
| 419 |
+
- **πΌ Case Management** - Organize and track cases
|
| 420 |
+
- **π Regulatory Updates** - Stay informed about changes
|
| 421 |
+
|
| 422 |
+
### β¨ NEW: OCR Document Processing
|
| 423 |
+
|
| 424 |
+
Upload scanned documents, contracts, or legal images - our AI will:
|
| 425 |
+
- Extract text automatically using DeepSeek-OCR
|
| 426 |
+
- Analyze document structure and validity
|
| 427 |
+
- Identify legal terms and key clauses
|
| 428 |
+
- Provide detailed feedback
|
| 429 |
+
|
| 430 |
+
**Ready to start?** Click the "AI Legal Chatbot" tab!
|
| 431 |
+
""")
|
| 432 |
+
|
| 433 |
+
# Tab 2: AI Legal Chatbot with OCR
|
| 434 |
+
with gr.Tab("π€ AI Legal Chatbot", id="chatbot"):
|
| 435 |
+
gr.Markdown("""
|
| 436 |
+
## AI Legal Chatbot - 7 Modes + OCR Processing
|
| 437 |
+
|
| 438 |
+
Select your assistant mode and start chatting!
|
| 439 |
+
**NEW**: Document Validator now includes OCR for scanned documents!
|
| 440 |
+
""")
|
| 441 |
+
|
| 442 |
+
mode_selector = gr.Dropdown(
|
| 443 |
+
choices=[
|
| 444 |
+
"navigation",
|
| 445 |
+
"general",
|
| 446 |
+
"document_validation",
|
| 447 |
+
"legal_research",
|
| 448 |
+
"etymology",
|
| 449 |
+
"case_management",
|
| 450 |
+
"regulatory_updates"
|
| 451 |
+
],
|
| 452 |
+
value="navigation",
|
| 453 |
+
label="Select AI Assistant Mode",
|
| 454 |
+
elem_classes=["mode-selector"]
|
| 455 |
+
)
|
| 456 |
+
|
| 457 |
+
gr.Markdown("---")
|
| 458 |
+
|
| 459 |
+
chatbot = gr.ChatInterface(
|
| 460 |
+
respond_with_mode,
|
| 461 |
+
chatbot=gr.Chatbot(
|
| 462 |
+
height=500,
|
| 463 |
+
placeholder="π¬ Select a mode and ask your question...",
|
| 464 |
+
),
|
| 465 |
+
additional_inputs=[
|
| 466 |
+
mode_selector,
|
| 467 |
+
gr.Slider(128, 4096, value=2048, label="Max Tokens"),
|
| 468 |
+
gr.Slider(0.1, 2.0, value=0.7, label="Temperature"),
|
| 469 |
+
gr.Slider(0.1, 1.0, value=0.95, label="Top-p"),
|
| 470 |
+
],
|
| 471 |
+
examples=[
|
| 472 |
+
["How do I use the OCR document feature?"],
|
| 473 |
+
["What is the difference between lawful and legal?"],
|
| 474 |
+
["Can you validate a contract for me?"],
|
| 475 |
+
["Research case law about employment contracts"],
|
| 476 |
+
],
|
| 477 |
+
)
|
| 478 |
+
|
| 479 |
+
# Tab 3: Features
|
| 480 |
+
with gr.Tab("β¨ Features", id="features"):
|
| 481 |
+
gr.Markdown("""
|
| 482 |
+
## Platform Features
|
| 483 |
+
|
| 484 |
+
### π NEW: OCR Document Processing
|
| 485 |
+
|
| 486 |
+
**DeepSeek-OCR Integration:**
|
| 487 |
+
- Extract text from scanned documents
|
| 488 |
+
- Process images of contracts and legal forms
|
| 489 |
+
- Automatic text recognition
|
| 490 |
+
- Legal document analysis
|
| 491 |
+
|
| 492 |
+
### π― Core Capabilities
|
| 493 |
+
|
| 494 |
+
- **7 Specialized AI Modes**
|
| 495 |
+
- **Rotating Custom Logos**
|
| 496 |
+
- **OCR Document Processing** β NEW!
|
| 497 |
+
- **Legal Research Tools**
|
| 498 |
+
- **Case Management**
|
| 499 |
+
- **And more...**
|
| 500 |
+
""")
|
| 501 |
+
|
| 502 |
+
# Tab 4: About
|
| 503 |
+
with gr.Tab("βΉοΈ About", id="about"):
|
| 504 |
+
gr.Markdown("""
|
| 505 |
+
## About ProVerBs Legal AI
|
| 506 |
+
|
| 507 |
+
### π Latest Update: OCR Integration
|
| 508 |
+
|
| 509 |
+
We've integrated **DeepSeek-OCR** for advanced document processing:
|
| 510 |
+
- Extract text from scanned documents
|
| 511 |
+
- Process legal document images
|
| 512 |
+
- Automatic text recognition
|
| 513 |
+
- Enhanced document validation
|
| 514 |
+
|
| 515 |
+
### π€ 7 Specialized AI Modes
|
| 516 |
+
|
| 517 |
+
Each mode is trained for specific legal tasks, now with enhanced OCR capabilities
|
| 518 |
+
in Document Validator mode.
|
| 519 |
+
|
| 520 |
+
### β οΈ Disclaimer
|
| 521 |
+
|
| 522 |
+
This platform provides general legal information only. Always consult with a
|
| 523 |
+
qualified attorney for specific legal matters.
|
| 524 |
+
|
| 525 |
+
---
|
| 526 |
+
|
| 527 |
+
**Version 1.1.0** | Built by Solomon7890 | Powered by Hugging Face + DeepSeek-OCR
|
| 528 |
+
""")
|
| 529 |
+
|
| 530 |
+
# Footer
|
| 531 |
+
gr.Markdown("""
|
| 532 |
+
---
|
| 533 |
+
|
| 534 |
+
<div style="text-align: center; padding: 20px;">
|
| 535 |
+
<p><strong>βοΈ ProVerBs Legal AI Platform</strong> | Version 1.1.0 with OCR</p>
|
| 536 |
+
<p>Β© 2024 ProVerBs Legal AI. Built with β€οΈ for legal professionals worldwide.</p>
|
| 537 |
+
</div>
|
| 538 |
+
""")
|
| 539 |
+
|
| 540 |
+
if __name__ == "__main__":
|
| 541 |
+
demo.queue(max_size=20)
|
| 542 |
+
demo.launch(
|
| 543 |
+
server_name="0.0.0.0",
|
| 544 |
+
server_port=7860,
|
| 545 |
+
share=False,
|
| 546 |
+
show_error=True
|
| 547 |
+
)
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio>=4.0.0
|
| 2 |
+
huggingface-hub>=0.20.0
|
| 3 |
+
transformers>=4.35.0
|
| 4 |
+
torch>=2.0.0
|
| 5 |
+
pillow>=10.0.0
|
| 6 |
+
datasets>=2.15.0
|