import json import os import importlib import gradio as gr import sys now_dir = os.getcwd() folder = os.path.join( os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), "assets", "themes", ) config_file = os.path.join(now_dir, "assets", "config.json") sys.path.append(folder) def read_json_file(filename): """Helper function to read a JSON file and return its contents.""" with open(filename, "r", encoding="utf8") as json_file: return json.load(json_file) def load_theme(): """Load the selected theme based on the configuration file.""" try: config_data = read_json_file(config_file) selected_file = config_data["theme"]["file"] class_name = config_data["theme"]["class"] if class_name: if selected_file: module = importlib.import_module(selected_file[:-3]) obtained_class = getattr(module, class_name) return obtained_class() else: return class_name else: print("No valid theme class found.") return None except Exception as error: print(f"An error occurred while loading the theme: {error}") return None