Refactor code structure for improved readability and maintainability

This commit is contained in:
2025-03-26 12:14:58 +00:00
parent a4683023ad
commit bd56cc839d
5 changed files with 1386 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
[base] [base]
# provider can be [ openai|openrouter|anthropic|google] # provider can be [ openai|openrouter|anthropic|google]
provider = openrouter provider = openrouter
streamlit_headless = true
[openrouter] [openrouter]
api_key = YOUR_API_KEY api_key = YOUR_API_KEY

View File

@@ -27,6 +27,9 @@ license-files = ["LICEN[CS]E*"]
GitHub = "https://git.bhakat.dev/abhishekbhakat/mcpapp" GitHub = "https://git.bhakat.dev/abhishekbhakat/mcpapp"
Issues = "https://git.bhakat.dev/abhishekbhakat/mcpapp/issues" Issues = "https://git.bhakat.dev/abhishekbhakat/mcpapp/issues"
[project.scripts]
mcpapp = "run_app:run_streamlit_app"
[project.optional-dependencies] [project.optional-dependencies]
dev = [ dev = [
"build>=1.2.2", "build>=1.2.2",

57
run_app.py Normal file
View File

@@ -0,0 +1,57 @@
import configparser
import os
import subprocess
import sys
def run_streamlit_app():
"""
Reads the configuration file and launches the Streamlit app,
optionally in headless mode.
"""
config_path = "config/config.ini"
headless = False
try:
if os.path.exists(config_path):
config = configparser.ConfigParser()
config.read(config_path)
if config.has_section("base"):
headless = config.getboolean("base", "streamlit_headless", fallback=False)
if headless:
print(f"INFO: Headless mode enabled via {config_path}.")
else:
print(f"INFO: Headless mode disabled via {config_path}.")
else:
print(f"WARNING: [base] section not found in {config_path}. Defaulting to non-headless.")
else:
print(f"WARNING: Configuration file not found at {config_path}. Defaulting to non-headless.")
except Exception as e:
print(f"ERROR: Could not read headless config from {config_path}: {e}. Defaulting to non-headless.")
headless = False # Ensure default on error
# Construct the command
command = [sys.executable, "-m", "streamlit", "run", "src/app.py"]
if headless:
command.extend(["--server.headless", "true"])
print(f"Running command: {' '.join(command)}")
try:
# Run Streamlit using subprocess.run which waits for completion
# Use check=True to raise an error if Streamlit fails
# Capture output might be useful for debugging but can be complex with interactive apps
process = subprocess.Popen(command)
process.wait() # Wait for the Streamlit process to exit
print(f"Streamlit process finished with exit code: {process.returncode}")
except FileNotFoundError:
print("ERROR: 'streamlit' command not found. Make sure Streamlit is installed and in your PATH.")
sys.exit(1)
except Exception as e:
print(f"ERROR: Failed to run Streamlit: {e}")
sys.exit(1)
if __name__ == "__main__":
run_streamlit_app()

View File

@@ -1,13 +1,12 @@
import atexit import atexit
import configparser import configparser
import json # For handling potential error JSON in stream import json
import logging import logging
import streamlit as st import streamlit as st
# Updated imports
from llm_client import LLMClient from llm_client import LLMClient
from src.custom_mcp.manager import SyncMCPManager # Updated import path from src.custom_mcp.manager import SyncMCPManager
# Configure logging for the app # Configure logging for the app
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s") logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")

1323
uv.lock generated Normal file

File diff suppressed because it is too large Load Diff