Spaces:
Runtime error
Runtime error
File size: 4,658 Bytes
82f1bf5 d754e91 82f1bf5 d754e91 82f1bf5 d754e91 82f1bf5 d754e91 82f1bf5 d754e91 82f1bf5 d754e91 82f1bf5 d754e91 66c7018 d754e91 66c7018 d754e91 66c7018 d754e91 66c7018 d754e91 66c7018 d754e91 |
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 |
import gradio as gr
from ..globals import Global
from ..models import get_model_with_lora
from .inference_ui import inference_ui
from .js_scripts import popperjs_core_code, tippy_js_code
def main_page():
title = get_page_title()
with gr.Blocks(
title=title,
css=main_page_custom_css()) as main_page_blocks:
gr.Markdown(f"""
<h1 class="app_title_text">{title}</h1> <wbr /><h2 class="app_subtitle_text">{Global.ui_subtitle}</h2>
""")
with gr.Tab("Inference"):
inference_ui()
if Global.ui_show_sys_info:
gr.Markdown(f"""
<small>Data dir: `{Global.data_dir}`</small>
""")
main_page_blocks.load(_js=f"""
function () {{
{popperjs_core_code()}
{tippy_js_code()}
""" + """
// Sync theme to body.
setTimeout(function () {
const gradio_container_element = document.querySelector(
".gradio-container"
);
function handle_gradio_container_element_class_change() {
if (Array.from(gradio_container_element.classList).includes("dark")) {
document.body.classList.add("dark");
} else {
document.body.classList.remove("dark");
}
}
new MutationObserver(function (mutationsList, observer) {
handle_gradio_container_element_class_change();
}).observe(gradio_container_element, {
attributes: true,
attributeFilter: ["class"],
});
handle_gradio_container_element_class_change();
}, 500);
}
""")
def get_page_title():
title = Global.ui_title
if (Global.ui_dev_mode):
title = f"[UI DEV MODE] {title}"
if (Global.ui_emoji):
title = f"{Global.ui_emoji} {title}"
return title
def main_page_custom_css():
css = """
.app_title_text {
display: inline-block;
margin-right: 0.5em !important;
}
.app_subtitle_text {
display: inline-block;
margin-top: 0 !important;
font-weight: 100 !important;
font-size: var(--text-md) !important;
}
.tippy-box {
background-color: var(--block-background-fill);
border: 1px solid var(--border-color-primary);
border-radius: 4px;
box-shadow: 0 2px 20px rgba(5,5,5,.08);
}
.tippy-arrow {
color: var(--block-background-fill);
}
.tippy-content {
color: var(--block-label-text-color);
font-family: var(--font);
font-weight: 100;
}
#inference_prompt_box > *:first-child {
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
}
#inference_prompt_box > *:last-child {
margin-top: -16px;
border-top: 0;
border-top-left-radius: 0;
border-top-right-radius: 0;
}
#inference_preview_prompt_container .label-wrap {
user-select: none;
}
#inference_preview_prompt {
padding: 0;
}
#inference_preview_prompt textarea {
border: 0;
}
@media screen and (min-width: 640px) {
#inference_lora_model {
border-top-right-radius: 0;
border-bottom-right-radius: 0;
border-right: 0;
margin-right: -16px;
}
#inference_prompt_template {
border-top-left-radius: 0;
border-bottom-left-radius: 0;
border-left: 0;
margin-right: -90px;
padding-right: 80px;
}
#inference_reload_selections_button {
margin: 16px;
margin-bottom: auto;
height: 42px !important;
min-width: 42px !important;
width: 42px !important;
z-index: 1;
}
}
@media screen and (max-width: 392px) {
#inference_lora_model {
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
}
#inference_prompt_template {
border-top-left-radius: 0;
border-top-right-radius: 0;
border-top: 0;
margin-top: -16px;
}
}
.tippy-box[data-animation=scale-subtle][data-placement^=top]{transform-origin:bottom}.tippy-box[data-animation=scale-subtle][data-placement^=bottom]{transform-origin:top}.tippy-box[data-animation=scale-subtle][data-placement^=left]{transform-origin:right}.tippy-box[data-animation=scale-subtle][data-placement^=right]{transform-origin:left}.tippy-box[data-animation=scale-subtle][data-state=hidden]{transform:scale(.8);opacity:0}
"""
return css
|