File size: 7,049 Bytes
fc657fc
 
6fc3759
fc657fc
 
 
6fc3759
fc657fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6fc3759
fc657fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6fc3759
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fc657fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6fc3759
 
 
 
 
 
 
 
 
 
fc657fc
 
 
 
 
 
 
 
6fc3759
 
 
 
 
 
 
b37167e
fc657fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6fc3759
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fc657fc
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
"""
Configuration module for Universal MCP Client
Enhanced with HuggingFace Inference Provider support
"""
import os
from dataclasses import dataclass
from typing import Optional, Dict, List
import logging

# Set up enhanced logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)

@dataclass
class MCPServerConfig:
    """Configuration for an MCP server connection"""
    name: str
    url: str
    description: str
    space_id: Optional[str] = None

class AppConfig:
    """Application configuration settings"""
    
    # API Configuration
    ANTHROPIC_API_KEY = os.getenv("ANTHROPIC_API_KEY")
    HF_TOKEN = os.getenv("HF_TOKEN")
    
    # Model Configuration
    CLAUDE_MODEL = "claude-sonnet-4-20250514"
    MAX_TOKENS = 2048
    
    # MCP Configuration
    MCP_BETA_VERSION = "mcp-client-2025-04-04"
    MCP_TIMEOUT_SECONDS = 20.0
    
    # UI Configuration
    GRADIO_THEME = "citrus"
    DEBUG_MODE = True
    
    # File Support
    SUPPORTED_IMAGE_EXTENSIONS = ['.png', '.jpg', '.jpeg', '.gif', '.webp']
    SUPPORTED_AUDIO_EXTENSIONS = ['.mp3', '.wav', '.ogg', '.m4a', '.flac']
    SUPPORTED_VIDEO_EXTENSIONS = ['.mp4', '.avi', '.mov']
    SUPPORTED_DOCUMENT_EXTENSIONS = ['.pdf', '.txt', '.docx']
    
    # Inference Providers Configuration
    INFERENCE_PROVIDERS = {
        "sambanova": {
            "name": "SambaNova",
            "description": "Ultra-fast inference on optimized hardware",
            "supports_tools": True,
            "models": [
                "meta-llama/Llama-3.3-70B-Instruct",
                "deepseek-ai/DeepSeek-R1-0528", 
                "meta-llama/Llama-4-Maverick-17B-128E-Instruct",
                "intfloat/e5-mistral-7b-instruct"
            ]
        },
        "together": {
            "name": "Together AI",
            "description": "High-performance inference for open models",
            "supports_tools": True,
            "models": [
                "deepseek-ai/DeepSeek-V3-0324",
                "Qwen/Qwen2.5-72B-Instruct",
                "meta-llama/Llama-3.1-8B-Instruct",
                "black-forest-labs/FLUX.1-dev"
            ]
        },
        "replicate": {
            "name": "Replicate",
            "description": "Run AI models in the cloud",
            "supports_tools": True,
            "models": [
                "meta/llama-2-70b-chat",
                "mistralai/mixtral-8x7b-instruct-v0.1",
                "black-forest-labs/flux-schnell"
            ]
        },
        "groq": {
            "name": "Groq",
            "description": "Ultra-low latency LPU inference",
            "supports_tools": True,
            "models": [
                "meta-llama/Llama-4-Scout-17B-16E-Instruct",
                "llama-3.1-70b-versatile",
                "mixtral-8x7b-32768"
            ]
        },
        "fal-ai": {
            "name": "fal.ai",
            "description": "Fast AI model inference",
            "supports_tools": True,
            "models": [
                "meta-llama/Llama-3.1-8B-Instruct",
                "black-forest-labs/flux-pro"
            ]
        },
        "fireworks-ai": {
            "name": "Fireworks AI",
            "description": "Production-ready inference platform",
            "supports_tools": True,
            "models": [
                "accounts/fireworks/models/llama-v3p1-70b-instruct",
                "accounts/fireworks/models/mixtral-8x7b-instruct"
            ]
        },
        "cohere": {
            "name": "Cohere",
            "description": "Enterprise-grade language AI",
            "supports_tools": True,
            "models": [
                "command-r-plus",
                "command-r",
                "command"
            ]
        },
        "hf-inference": {
            "name": "HF Inference",
            "description": "Hugging Face serverless inference",
            "supports_tools": True,
            "models": [
                "meta-llama/Llama-3.2-11B-Vision-Instruct",
                "microsoft/DialoGPT-medium",
                "intfloat/multilingual-e5-large"
            ]
        }
    }
    
    @classmethod
    def get_all_media_extensions(cls):
        """Get all supported media file extensions"""
        return (cls.SUPPORTED_IMAGE_EXTENSIONS + 
                cls.SUPPORTED_AUDIO_EXTENSIONS + 
                cls.SUPPORTED_VIDEO_EXTENSIONS)
    
    @classmethod
    def is_image_file(cls, file_path: str) -> bool:
        """Check if file is an image"""
        return any(ext in file_path.lower() for ext in cls.SUPPORTED_IMAGE_EXTENSIONS)
    
    @classmethod
    def is_audio_file(cls, file_path: str) -> bool:
        """Check if file is an audio file"""
        return any(ext in file_path.lower() for ext in cls.SUPPORTED_AUDIO_EXTENSIONS)
    
    @classmethod
    def is_video_file(cls, file_path: str) -> bool:
        """Check if file is a video file"""
        return any(ext in file_path.lower() for ext in cls.SUPPORTED_VIDEO_EXTENSIONS)
    
    @classmethod
    def is_media_file(cls, file_path: str) -> bool:
        """Check if file is any supported media type"""
        return any(ext in file_path.lower() for ext in cls.get_all_media_extensions())

    @classmethod
    def get_provider_models(cls, provider: str) -> List[str]:
        """Get available models for a specific provider"""
        return cls.INFERENCE_PROVIDERS.get(provider, {}).get("models", [])
    
    @classmethod
    def get_all_providers(cls) -> Dict[str, Dict]:
        """Get all available inference providers"""
        return cls.INFERENCE_PROVIDERS

# Check for dependencies
try:
    import httpx
    HTTPX_AVAILABLE = True
except ImportError:
    HTTPX_AVAILABLE = False
    logger.warning("httpx not available - file upload functionality limited")

try:
    from huggingface_hub import InferenceClient
    HF_INFERENCE_AVAILABLE = True
except ImportError:
    HF_INFERENCE_AVAILABLE = False
    logger.warning("huggingface_hub not available - inference provider functionality limited")

# CSS Configuration
CUSTOM_CSS = """
/* Hide Gradio footer */
footer {
    display: none !important;
}
/* Make chatbot expand to fill available space */
.gradio-container {
    height: 100vh !important;
}
/* Ensure proper flex layout */
.main-content {
    display: flex;
    flex-direction: column;
    height: 100%;
}
/* Input area stays at bottom with minimal padding */
.input-area {
    margin-top: auto;
    padding-top: 0.25rem !important;
    padding-bottom: 0 !important;
    margin-bottom: 0 !important;
}
/* Reduce padding around chatbot */
.chatbot {
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
}
/* Provider selection styling */
.provider-selection {
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 10px;
    margin: 5px 0;
}
.anthropic-config {
    background-color: #f8f9fa;
    border-left: 4px solid #28a745;
}
.hf-config {
    background-color: #fff8e1;
    border-left: 4px solid #ff9800;
}
"""