# # Copyright 2016 The BigDL Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # This file is adapted from # https://github.com/oobabooga/text-generation-webui/blob/main/extensions/gallery/script.py from pathlib import Path import gradio as gr from modules.html_generator import get_image_cache from modules.shared import gradio, settings cards = [] def generate_css(): css = """ .highlighted-border { border-color: rgb(249, 115, 22) !important; } .character-gallery > .gallery { margin: 1rem 0; display: grid !important; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); grid-column-gap: 0.4rem; grid-row-gap: 1.2rem; } .character-gallery > .label { display: none !important; } .character-gallery button.gallery-item { display: contents; } .character-container { cursor: pointer; text-align: center; position: relative; opacity: 0.85; } .character-container:hover { opacity: 1; } .character-container .placeholder, .character-container img { width: 150px; height: 200px; background-color: gray; object-fit: cover; margin: 0 auto; border-radius: 1rem; border: 3px solid white; box-shadow: 3px 3px 6px 0px rgb(0 0 0 / 50%); } .character-name { margin-top: 0.3rem; display: block; font-size: 1.2rem; font-weight: 600; overflow-wrap: anywhere; } """ return css def generate_html(): global cards cards = [] # Iterate through files in image folder for file in sorted(Path("characters").glob("*")): if file.suffix in [".json", ".yml", ".yaml"]: character = file.stem container_html = '