Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Universal MCP Client - Main Application
|
3 |
+
A modular Gradio chatbot that uses HuggingFace Inference Providers to access OpenAI GPT OSS models
|
4 |
+
and can connect to various MCP servers for enhanced functionality.
|
5 |
+
"""
|
6 |
+
import logging
|
7 |
+
import os
|
8 |
+
|
9 |
+
from config import AppConfig
|
10 |
+
from mcp_client import UniversalMCPClient
|
11 |
+
from ui_components import UIComponents
|
12 |
+
|
13 |
+
# Set up logging
|
14 |
+
logger = logging.getLogger(__name__)
|
15 |
+
|
16 |
+
def main():
|
17 |
+
"""Main application entry point"""
|
18 |
+
logger.info("π Starting Universal MCP Client with HuggingFace Inference Providers...")
|
19 |
+
|
20 |
+
try:
|
21 |
+
# Check for HuggingFace token
|
22 |
+
if not AppConfig.HF_TOKEN:
|
23 |
+
logger.warning("β οΈ No HF_TOKEN found in environment variables")
|
24 |
+
logger.info("π‘ Users will need to login manually or set HF_TOKEN")
|
25 |
+
else:
|
26 |
+
logger.info("β
HF_TOKEN found in environment")
|
27 |
+
|
28 |
+
# Initialize the MCP client
|
29 |
+
mcp_client = UniversalMCPClient()
|
30 |
+
|
31 |
+
# Create UI components
|
32 |
+
ui_components = UIComponents(mcp_client)
|
33 |
+
|
34 |
+
# Create the Gradio interface
|
35 |
+
demo = ui_components.create_interface()
|
36 |
+
|
37 |
+
# Launch the application
|
38 |
+
demo.launch(
|
39 |
+
debug=AppConfig.DEBUG_MODE,
|
40 |
+
share=False, # Set to True if you want to create a public link
|
41 |
+
server_name="0.0.0.0", # Allow external connections
|
42 |
+
server_port=7860, # Default Gradio port
|
43 |
+
auth=None, # No authentication (handled by HF login)
|
44 |
+
max_threads=40 # Allow multiple concurrent users
|
45 |
+
)
|
46 |
+
|
47 |
+
logger.info("β
Universal MCP Client started successfully!")
|
48 |
+
|
49 |
+
except Exception as e:
|
50 |
+
logger.error(f"β Failed to start application: {e}")
|
51 |
+
raise
|
52 |
+
|
53 |
+
if __name__ == "__main__":
|
54 |
+
main()
|