ndc8 commited on
Commit Β·
8208c22
1
Parent(s): 1ba257c
change model
Browse filesFiles changed (2)
- MODEL_CONFIG.mdAdded+190
- backend_service.py+6-5
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190# π§ Model Configuration Guide
The backend now supports **configurable models via environment variables**, making it easy to switch between different AI models without code changes.
## π Environment Variables
### **Primary Configuration**
```bash# Main AI model for text generation (required)export AI_MODEL="deepseek-ai/DeepSeek-R1-0528-Qwen3-8B"
# Vision model for image processing (optional)export VISION_MODEL="Salesforce/blip-image-captioning-base"
# HuggingFace token for private models (optional)export HF_TOKEN="your_huggingface_token_here"```
---
## π Usage Examples
### **1. Use DeepSeek-R1 (Default)**
```bash# Uses your originally requested modelexport AI_MODEL="deepseek-ai/DeepSeek-R1-0528-Qwen3-8B"./gradio_env/bin/python backend_service.py```
### **2. Use DialoGPT (Faster, smaller)**
```bash# Switch to lighter model for development/testingexport AI_MODEL="microsoft/DialoGPT-medium"./gradio_env/bin/python backend_service.py```
### **3. Use Other Popular Models**
```bash# Use Zephyr chat modelexport AI_MODEL="HuggingFaceH4/zephyr-7b-beta"./gradio_env/bin/python backend_service.py
# Use CodeLlama for code generationexport AI_MODEL="codellama/CodeLlama-7b-Instruct-hf"./gradio_env/bin/python backend_service.py
# Use Mistralexport AI_MODEL="mistralai/Mistral-7B-Instruct-v0.2"./gradio_env/bin/python backend_service.py```
### **4. Use Different Vision Model**
```bashexport AI_MODEL="microsoft/DialoGPT-medium"export VISION_MODEL="nlpconnect/vit-gpt2-image-captioning"./gradio_env/bin/python backend_service.py```
---
## π Startup Script Examples
### **Development Mode (Fast startup)**
```bash#!/bin/bash# dev_mode.shexport AI_MODEL="microsoft/DialoGPT-medium"export VISION_MODEL="Salesforce/blip-image-captioning-base"./gradio_env/bin/python backend_service.py```
### **Production Mode (Your preferred model)**
```bash#!/bin/bash# production_mode.shexport AI_MODEL="deepseek-ai/DeepSeek-R1-0528-Qwen3-8B"export VISION_MODEL="Salesforce/blip-image-captioning-base"export HF_TOKEN="$YOUR_HF_TOKEN"./gradio_env/bin/python backend_service.py```
### **Testing Mode (Lightweight)**
```bash#!/bin/bash# test_mode.shexport AI_MODEL="microsoft/DialoGPT-medium"export VISION_MODEL="Salesforce/blip-image-captioning-base"./gradio_env/bin/python backend_service.py```
---
## π Model Verification
After starting the backend, check which model is loaded:
```bashcurl http://localhost:8000/health```
Response will show:
```json{ "status": "healthy", "model": "deepseek-ai/DeepSeek-R1-0528-Qwen3-8B", "version": "1.0.0"}```
---
## π Model Comparison
| Model | Size | Speed | Quality | Use Case || --------------------------------------- | ------ | ------- | ------------ | ------------------- || `microsoft/DialoGPT-medium` | ~355MB | β‘ Fast | Good | Development/Testing || `deepseek-ai/DeepSeek-R1-0528-Qwen3-8B` | ~16GB | π Slow | β Excellent | Production || `HuggingFaceH4/zephyr-7b-beta` | ~14GB | π Slow | β Excellent | Chat/Conversation || `codellama/CodeLlama-7b-Instruct-hf` | ~13GB | π Slow | β Good | Code Generation |
---
## π οΈ Troubleshooting
### **Model Not Found**
```bash# Verify model exists on HuggingFace./gradio_env/bin/python -c "from huggingface_hub import HfApiapi = HfApi()try: info = api.model_info('your-model-name') print(f'β
Model exists: {info.id}')except: print('β Model not found')"```
### **Memory Issues**
```bash# Use smaller model for limited RAMexport AI_MODEL="microsoft/DialoGPT-medium" # ~355MB# orexport AI_MODEL="distilgpt2" # ~82MB```
### **Authentication Issues**
```bash# Set HuggingFace token for private modelsexport HF_TOKEN="hf_your_token_here"```
---
## π― Quick Switch Commands
```bash# Quick switch to development modeexport AI_MODEL="microsoft/DialoGPT-medium" && ./gradio_env/bin/python backend_service.py
# Quick switch to production modeexport AI_MODEL="deepseek-ai/DeepSeek-R1-0528-Qwen3-8B" && ./gradio_env/bin/python backend_service.py
# Quick switch with custom vision modelexport AI_MODEL="microsoft/DialoGPT-medium" AI_VISION="nlpconnect/vit-gpt2-image-captioning" && ./gradio_env/bin/python backend_service.py```
---
## β
Summary
- **Environment Variable**: `AI_MODEL` controls the main text generation model- **Default**: `deepseek-ai/DeepSeek-R1-0528-Qwen3-8B` (your original preference)- **Alternative**: `microsoft/DialoGPT-medium` (faster for development)- **Vision Model**: `VISION_MODEL` controls image processing model- **No Code Changes**: Switch models by changing environment variables only
**Your original DeepSeek-R1 model is still the default** - I simply made it configurable so you can easily switch when needed!75 unmodified lines7677787980818241 unmodified lines12412512612712812913013144 unmodified lines17617717817918018118218318418518618718818975 unmodified linesreturn vclass ChatCompletionRequest(BaseModel):model: str = Field(default="unsloth/DeepSeek-R1-0528-Qwen3-8B-GGUF", description="The model to use for completion")messages: List[ChatMessage] = Field(..., description="List of messages in the conversation")max_tokens: Optional[int] = Field(default=512, ge=1, le=2048, description="Maximum tokens to generate")temperature: Optional[float] = Field(default=0.7, ge=0.0, le=2.0, description="Sampling temperature")41 unmodified lines# Global variables for model managementcurrent_model = "microsoft/DialoGPT-medium"vision_model = "Salesforce/blip-image-captioning-base" # Working model for image captioningtokenizer = Nonemodel = Noneimage_text_pipeline = None # type: ignore44 unmodified linesglobal tokenizer, model, image_text_pipelinelogger.info("π Starting AI Backend Service...")try:# Load tokenizer and model directly from HuggingFace repo (GGUF format supported)logger.info(f"π₯ Loading tokenizer from {current_model}...")tokenizer = AutoTokenizer.from_pretrained(current_model)logger.info(f"π₯ Loading model from {current_model}...")model = AutoModelForCausalLM.from_pretrained(current_model)logger.info(f"β Successfully loaded GGUF model and tokenizer: {current_model}")# Load image pipeline for multimodal supporttry:75 unmodified lines7677787980818241 unmodified lines12412512612712812913013113244 unmodified lines17717817918018118218318418518618718818919075 unmodified linesreturn vclass ChatCompletionRequest(BaseModel):model: str = Field(default_factory=lambda: os.environ.get("AI_MODEL", "deepseek-ai/DeepSeek-R1-0528-Qwen3-8B"), description="The model to use for completion")messages: List[ChatMessage] = Field(..., description="List of messages in the conversation")max_tokens: Optional[int] = Field(default=512, ge=1, le=2048, description="Maximum tokens to generate")temperature: Optional[float] = Field(default=0.7, ge=0.0, le=2.0, description="Sampling temperature")41 unmodified lines# Global variables for model management# Model can be configured via environment variable - defaults to DeepSeek-R1current_model = os.environ.get("AI_MODEL", "deepseek-ai/DeepSeek-R1-0528-Qwen3-8B")vision_model = os.environ.get("VISION_MODEL", "Salesforce/blip-image-captioning-base")tokenizer = Nonemodel = Noneimage_text_pipeline = None # type: ignore44 unmodified linesglobal tokenizer, model, image_text_pipelinelogger.info("π Starting AI Backend Service...")try:# Load tokenizer and model directly from HuggingFace repo (standard transformers format)logger.info(f"π₯ Loading tokenizer from {current_model}...")tokenizer = AutoTokenizer.from_pretrained(current_model)logger.info(f"π₯ Loading model from {current_model}...")model = AutoModelForCausalLM.from_pretrained(current_model)logger.info(f"β Successfully loaded model and tokenizer: {current_model}")# Load image pipeline for multimodal supporttry:
MODEL_CONFIG.mdAdded+190
backend_service.py+6-5