Spaces:
Running
Running
File size: 10,754 Bytes
6cb2ff0 c458f41 6cb2ff0 c458f41 6cb2ff0 79a256a 6cb2ff0 79a256a 6cb2ff0 79a256a 6cb2ff0 79a256a 6cb2ff0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
---
title: HF-Inferoxy AI Hub
emoji: π
colorFrom: purple
colorTo: blue
sdk: gradio
app_file: app.py
pinned: false
---
# π HF-Inferoxy AI Hub
A comprehensive AI platform that combines conversational AI and text-to-image generation capabilities with intelligent HuggingFace API token management through HF-Inferoxy.
## β¨ Features
### π¬ Chat Assistant
- **π€ Smart Conversations**: Advanced chat interface with streaming responses
- **π― Model Flexibility**: Support for any HuggingFace chat model
- **βοΈ Customizable Parameters**: Control temperature, top-p, max tokens, and system messages
- **π Multi-Provider Support**: Works with Cerebras, Cohere, Groq, Together, and more
### π¨ Image Generator
- **πΌοΈ Text-to-Image Generation**: Create stunning images from text descriptions
- **ποΈ Advanced Controls**: Fine-tune dimensions, inference steps, guidance scale, and seeds
- **π― Multiple Providers**: HF Inference, Fal.ai, Nebius, NScale, Replicate, Together
- **π± Beautiful UI**: Modern interface with preset configurations and examples
### π Smart Token Management
- **π Automatic Token Provisioning**: No manual token management required
- **β‘ Intelligent Rotation**: Automatic switching when tokens fail or reach limits
- **π‘οΈ Error Resilience**: Failed tokens are quarantined and replaced seamlessly
- **π Usage Tracking**: Comprehensive monitoring of token usage and errors
## π οΈ Setup
### 1. HuggingFace Space Secrets
Add the following secret to your HuggingFace Space:
- **Key**: `PROXY_KEY`
- **Value**: Your HF-Inferoxy proxy API key
### 2. HF-Inferoxy Server
The app is configured to use the HF-Inferoxy server at: `http://scw.nazdev.tech:11155`
### 3. Dependencies
The app requires:
- `gradio` - Modern web interface framework
- `huggingface-hub` - HuggingFace API integration
- `requests` - HTTP communication with the proxy
- `Pillow` - Image processing capabilities
- `torch` & `transformers` - Model support
## π― How It Works
### Token Management Flow
1. **Token Provisioning**: The app requests a valid token from the HF-Inferoxy server
2. **API Calls**: Uses the provisioned token for HuggingFace API requests
3. **Status Reporting**: Reports token usage success/failure back to the proxy
4. **Automatic Rotation**: HF-Inferoxy handles token rotation and error management
### Chat Assistant
1. **Model Selection**: Choose any HuggingFace model with optional provider specification
2. **Conversation**: Engage in natural conversations with streaming responses
3. **Customization**: Adjust the AI's personality with system messages and parameters
### Image Generation
1. **Prompt Creation**: Write detailed descriptions of desired images
2. **Model & Provider**: Select from preset combinations or specify custom ones
3. **Parameter Tuning**: Fine-tune generation settings for optimal results
4. **Image Creation**: Generate high-quality images with automatic token management
## π Supported Models & Providers
### Chat Models
| Model | Provider | Description |
|-------|----------|-------------|
| `openai/gpt-oss-20b` | Fireworks AI, Cerebras, Groq | Fast general purpose model |
| `meta-llama/Llama-2-7b-chat-hf` | HF Inference | Chat-optimized model |
| `mistralai/Mistral-7B-Instruct-v0.2` | Featherless AI | Instruction following |
| `CohereLabs/c4ai-command-r-plus` | Cohere | Advanced language model |
### Image Models
| Model | Provider | Description |
|-------|----------|-------------|
| `Qwen/Qwen-Image` | Fal.ai, Replicate | Advanced image generation (default) |
| `black-forest-labs/FLUX.1-dev` | Nebius, Together | State-of-the-art image model |
| `stabilityai/stable-diffusion-xl-base-1.0` | HF Inference, NScale | High-quality SDXL model |
## π¨ Usage Examples
### Chat Assistant
#### Basic Conversation
1. Go to the "π¬ Chat Assistant" tab
2. Type your message in the chat input
3. Adjust parameters if needed (temperature, model, etc.)
4. Watch the AI respond with streaming text
#### Model Examples
```
# Auto provider (default - let HF choose best)
Model Name: openai/gpt-oss-20b
# Specific provider
Model Name: openai/gpt-oss-20b:fireworks-ai
System Message: You are a helpful coding assistant specializing in Python.
```
### Image Generation
#### Basic Image Creation
1. Go to the "π¨ Image Generator" tab
2. Enter your prompt: "A serene mountain lake at sunset, photorealistic, 8k"
3. Choose a model and provider
4. Click "π¨ Generate Image"
#### Advanced Settings
- **Dimensions**: 1024x1024 (must be divisible by 8)
- **Inference Steps**: 20-50 for good quality
- **Guidance Scale**: 7-10 for following prompts closely
- **Negative Prompt**: "blurry, low quality, distorted"
## βοΈ Configuration Options
### Chat Parameters
- **System Message**: Define the AI's personality and behavior
- **Max New Tokens**: Control response length (1-4096)
- **Temperature**: Creativity level (0.1-2.0)
- **Top-p**: Response diversity (0.1-1.0)
### Image Parameters
- **Prompt**: Detailed description of desired image
- **Negative Prompt**: What to avoid in the image
- **Dimensions**: Width and height (256-2048, divisible by 8)
- **Inference Steps**: Quality vs speed trade-off (10-100)
- **Guidance Scale**: Prompt adherence (1.0-20.0)
- **Seed**: Reproducibility (-1 for random)
## π― Provider-Specific Features
### Chat Providers
- **Auto**: Let HuggingFace choose the best provider (default)
- **Fireworks AI**: Fast and reliable inference service
- **Cerebras**: High-performance inference with low latency
- **Cohere**: Advanced language models with multilingual support
- **Groq**: Ultra-fast inference, optimized for speed
- **Together**: Collaborative AI hosting, wide model support
- **Featherless AI**: Specialized fine-tuned models
### Image Providers
- **HF Inference**: Core API with comprehensive model support
- **Fal.ai**: High-quality image generation with fast processing
- **Nebius**: Cloud-native services with enterprise features
- **NScale**: Optimized inference performance
- **Replicate**: Collaborative AI hosting with version control
- **Together**: Fast inference service with wide model support
## π‘ Tips for Better Results
### Chat Tips
- **Clear Instructions**: Be specific about what you want
- **System Messages**: Set context and personality upfront
- **Model Selection**: Choose appropriate models for your task
- **Parameter Tuning**: Lower temperature for factual responses, higher for creativity
### Image Tips
- **Detailed Prompts**: Use specific, descriptive language
- **Style Keywords**: Include art style, lighting, and quality descriptors
- **Negative Prompts**: Specify what you don't want to avoid common issues
- **Aspect Ratios**: Consider the subject when choosing dimensions
- **Provider Testing**: Try different providers for varied artistic styles
### Example Prompts
#### Chat Examples
```
# Using auto provider (default)
Model: openai/gpt-oss-20b
Prompt: "Explain quantum computing in simple terms"
# Using specific provider
Model: openai/gpt-oss-20b:fireworks-ai
Prompt: "Help me debug this Python code: [paste code]"
# Other example prompts:
"Write a creative story about a time-traveling cat"
"What are the pros and cons of renewable energy?"
```
#### Image Examples
```
"A majestic dragon flying over a medieval castle, epic fantasy art, detailed, 8k"
"A serene Japanese garden with cherry blossoms, zen atmosphere, peaceful, high quality"
"A futuristic cityscape with flying cars and neon lights, cyberpunk style, cinematic"
"Portrait of a wise old wizard with flowing robes, magical aura, fantasy character art"
```
## π Security & Authentication
### RBAC System
- All operations require authentication with the HF-Inferoxy proxy server
- API keys are managed securely through HuggingFace Space secrets
- No sensitive information is logged or exposed
### Token Security
- Tokens are automatically rotated when they fail or reach limits
- Failed tokens are quarantined to prevent repeated failures
- Usage is tracked comprehensively for monitoring and optimization
## π Troubleshooting
### Common Issues
#### Setup Issues
1. **PROXY_KEY Missing**: Ensure the secret is set in your HuggingFace Space settings
2. **Connection Errors**: Verify the HF-Inferoxy server is accessible
3. **Import Errors**: Check that all dependencies are properly installed
#### Chat Issues
1. **No Response**: Check model name format and provider availability
2. **Slow Responses**: Try different providers or smaller models
3. **Poor Quality**: Adjust temperature and top-p parameters
#### Image Issues
1. **Generation Fails**: Verify model supports text-to-image generation
2. **Dimension Errors**: Ensure width and height are divisible by 8
3. **Poor Quality**: Increase inference steps or adjust guidance scale
### Error Types
- **401 Errors**: Authentication issues (handled automatically by token rotation)
- **402 Errors**: Credit limit exceeded (reported to proxy for token management)
- **Network Errors**: Connection issues (reported to proxy for monitoring)
- **Model Errors**: Invalid model or provider combinations
## π Additional Resources
- **[HF-Inferoxy Documentation](https://nazdridoy.github.io/hf-inferoxy/)**: Complete platform documentation
- **[HuggingFace Hub Integration Guide](https://nazdridoy.github.io/hf-inferoxy/huggingface-hub-integration/)**: Detailed integration instructions
- **[Provider Examples](https://nazdridoy.github.io/hf-inferoxy/examples/)**: Code examples for different providers
- **[Gradio Documentation](https://gradio.app/docs/)**: Interface framework documentation
## π€ Contributing
This application is part of the HF-Inferoxy ecosystem. For contributions or issues:
1. Review the [HF-Inferoxy documentation](https://nazdridoy.github.io/hf-inferoxy/)
2. Test with different models and providers
3. Report any issues or suggest improvements
4. Contribute examples and use cases
## π Advanced Usage
### Environment Variables
You can customize the proxy URL using environment variables:
```python
import os
os.environ["HF_PROXY_URL"] = "http://your-proxy-server:8000"
```
### Custom Providers
The app supports any provider that works with HF-Inferoxy. Simply specify the provider name when entering model information.
### Batch Operations
For multiple operations, consider the token reuse patterns documented in the HF-Inferoxy integration guide.
## π License
This project is part of the HF-Inferoxy ecosystem. Please refer to the main project for licensing information.
---
**Built with β€οΈ using [HF-Inferoxy](https://nazdridoy.github.io/hf-inferoxy/) for intelligent token management**
**Ready to explore AI? Start chatting or generating images above! π**
|