Spaces:
Running
Running
Tobias Bergmann
commited on
Commit
Β·
251a15f
1
Parent(s):
9884118
first release with pure C
Browse files- .gitattributes +1 -0
- README.md +9 -9
- app.css +75 -0
- app.py +180 -0
- index.html +0 -19
- llama-server +3 -0
- requirements.txt +3 -0
- themes/carbon.py +147 -0
- themes/research_monochrome.py +152 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
llama-server filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
-
sdk:
|
|
|
|
|
7 |
pinned: false
|
8 |
-
license:
|
9 |
-
short_description:
|
10 |
---
|
11 |
-
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: Gemma3 1B IT IQ4NL via local GGUF
|
3 |
+
emoji: π
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: indigo
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 5.16.2
|
8 |
+
app_file: app.py
|
9 |
pinned: false
|
10 |
+
license: apache-2.0
|
11 |
+
short_description: Chat with Local GGUF server
|
12 |
---
|
|
|
|
app.css
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* Hide the standard Gradio footer */
|
2 |
+
footer {
|
3 |
+
display: none !important;
|
4 |
+
}
|
5 |
+
/* Make the text in the input box and chat label bigger */
|
6 |
+
textarea, .wrapper > label {
|
7 |
+
font-size: var(--text-md)
|
8 |
+
}
|
9 |
+
.input-container {
|
10 |
+
align-items: center;
|
11 |
+
}
|
12 |
+
/* Make the chat label bold */
|
13 |
+
.wrapper > label {
|
14 |
+
font-weight: 600;
|
15 |
+
}
|
16 |
+
/* Limit the overall width of the demo */
|
17 |
+
.gradio-container {
|
18 |
+
max-width: 1024px !important;
|
19 |
+
margin: 5vh auto !important;
|
20 |
+
}
|
21 |
+
/* Theme anchor links with Carbon coloring */
|
22 |
+
.gr_docs_link a, .gr_docs_link a > i {
|
23 |
+
color: #78A9FF;
|
24 |
+
text-decoration: none;
|
25 |
+
}
|
26 |
+
/* Title alignment with the Granite icon */
|
27 |
+
.gr_title {
|
28 |
+
display: flex;
|
29 |
+
align-items: center;
|
30 |
+
margin-bottom: -0.5rem;
|
31 |
+
}
|
32 |
+
.gr_title img {
|
33 |
+
height: 42px;
|
34 |
+
width: 42px;
|
35 |
+
margin-right: 1rem;
|
36 |
+
filter: invert(0%) sepia(0%) saturate(7459%) hue-rotate(154deg) brightness(96%) contrast(100%);
|
37 |
+
}
|
38 |
+
.gr_title h1 {
|
39 |
+
margin: auto !important;
|
40 |
+
font-size: 36px;
|
41 |
+
font-weight: 600;
|
42 |
+
}
|
43 |
+
/* Only one form on the page, within the Accordion component */
|
44 |
+
.form {
|
45 |
+
flex-direction: row;
|
46 |
+
background-color: var(--block-background-fill);
|
47 |
+
}
|
48 |
+
.gr_accordion_element {
|
49 |
+
width: 50%;
|
50 |
+
margin: 0px;
|
51 |
+
}
|
52 |
+
/* Color the example background */
|
53 |
+
.example:hover {
|
54 |
+
background-color: #D0E2FF
|
55 |
+
}
|
56 |
+
/* Centre the example text within the example box */
|
57 |
+
.example-text-content {
|
58 |
+
margin-top: auto;
|
59 |
+
margin-bottom: auto;
|
60 |
+
}
|
61 |
+
/* Centre the values in advanced settings */
|
62 |
+
.tab-like-container {
|
63 |
+
align-items: center;
|
64 |
+
}
|
65 |
+
/* dark mode */
|
66 |
+
@media (prefers-color-scheme: dark) {
|
67 |
+
/* Color the Granite icon in white */
|
68 |
+
.gr_title img {
|
69 |
+
filter: invert(100%) sepia(100%) saturate(0%) hue-rotate(162deg) brightness(101%) contrast(104%);
|
70 |
+
}
|
71 |
+
/* Color the example background */
|
72 |
+
.example:hover {
|
73 |
+
background-color: #4589FF
|
74 |
+
}
|
75 |
+
}
|
app.py
ADDED
@@ -0,0 +1,180 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from collections.abc import Iterator
|
2 |
+
from datetime import datetime
|
3 |
+
from pathlib import Path
|
4 |
+
from threading import Thread
|
5 |
+
from huggingface_hub import hf_hub_download
|
6 |
+
from themes.research_monochrome import theme
|
7 |
+
from typing import Iterator, List, Dict
|
8 |
+
|
9 |
+
import requests
|
10 |
+
import json
|
11 |
+
import subprocess
|
12 |
+
import gradio as gr
|
13 |
+
|
14 |
+
today_date = datetime.today().strftime("%B %-d, %Y") # noqa: DTZ002
|
15 |
+
|
16 |
+
SYS_PROMPT = f"""Today's Date: {today_date}.
|
17 |
+
You are Gemma, developed by Google. You are a helpful AI assistant"""
|
18 |
+
TITLE = "Gemma3 1b instruct IQ4_NL from local GGUF server"
|
19 |
+
DESCRIPTION = """
|
20 |
+
<p>Gemma3 1b instruct is an open-source LLM supporting a 128k context window. This demo uses only 2K context.
|
21 |
+
</p>
|
22 |
+
"""
|
23 |
+
LLAMA_CPP_SERVER = "http://127.0.0.1:8081"
|
24 |
+
MAX_NEW_TOKENS = 1024
|
25 |
+
TEMPERATURE = 0.7
|
26 |
+
TOP_P = 0.85
|
27 |
+
TOP_K = 50
|
28 |
+
REPETITION_PENALTY = 1.05
|
29 |
+
|
30 |
+
# download GGUF into local directory
|
31 |
+
gguf_path = hf_hub_download(
|
32 |
+
repo_id="bartowski/google_gemma-3-1b-it-GGUF",
|
33 |
+
filename="google_gemma-3-1b-it-IQ4_NL.gguf",
|
34 |
+
local_dir="."
|
35 |
+
)
|
36 |
+
|
37 |
+
# start llama-server
|
38 |
+
subprocess.run(["chmod", "+x", "llama-server"])
|
39 |
+
command = ["./llama-server", "-m", "google_gemma-3-1b-it-IQ4_NL.gguf", "-ngl", "0", "--temp", "0.0", "-c", "2048", "-t", "8", "--port", "8081"]
|
40 |
+
process = subprocess.Popen(command)
|
41 |
+
print(f"Llama-server process started with PID {process.pid}")
|
42 |
+
|
43 |
+
|
44 |
+
def generate(
|
45 |
+
message: str,
|
46 |
+
chat_history: List[Dict],
|
47 |
+
temperature: float = TEMPERATURE,
|
48 |
+
repetition_penalty: float = REPETITION_PENALTY,
|
49 |
+
top_p: float = TOP_P,
|
50 |
+
top_k: float = TOP_K,
|
51 |
+
max_new_tokens: int = MAX_NEW_TOKENS,
|
52 |
+
) -> Iterator[str]:
|
53 |
+
"""Generate function for chat demo using Llama.cpp server."""
|
54 |
+
|
55 |
+
# Build messages
|
56 |
+
conversation = []
|
57 |
+
conversation.append({"role": "system", "content": SYS_PROMPT})
|
58 |
+
conversation += chat_history
|
59 |
+
conversation.append({"role": "user", "content": message})
|
60 |
+
|
61 |
+
# Prepare the prompt for the Llama.cpp server
|
62 |
+
prompt = ""
|
63 |
+
for item in conversation:
|
64 |
+
if item["role"] == "system":
|
65 |
+
prompt += f"<|system|>\n{item['content']}\n<|file_separator|>\n"
|
66 |
+
elif item["role"] == "user":
|
67 |
+
prompt += f"<|user|>\n{item['content']}\n<|file_separator|>\n"
|
68 |
+
elif item["role"] == "assistant":
|
69 |
+
prompt += f"<|model|>\n{item['content']}\n<|file_separator|>\n"
|
70 |
+
prompt += "<|model|>\n" # Add the beginning token for the assistant
|
71 |
+
|
72 |
+
|
73 |
+
# Construct the request payload
|
74 |
+
payload = {
|
75 |
+
"prompt": prompt,
|
76 |
+
"stream": True, # Enable streaming
|
77 |
+
"max_tokens": max_new_tokens,
|
78 |
+
"temperature": temperature,
|
79 |
+
"repeat_penalty": repetition_penalty,
|
80 |
+
"top_p": top_p,
|
81 |
+
"top_k": top_k,
|
82 |
+
"stop": ["<|file_separator|>"], #stops after it sees this
|
83 |
+
}
|
84 |
+
|
85 |
+
try:
|
86 |
+
# Make the request to the Llama.cpp server
|
87 |
+
with requests.post(f"{LLAMA_CPP_SERVER}/completion", json=payload, stream=True, timeout=60) as response:
|
88 |
+
response.raise_for_status() # Raise HTTPError for bad responses (4xx or 5xx)
|
89 |
+
|
90 |
+
# Stream the response from the server
|
91 |
+
outputs = []
|
92 |
+
for line in response.iter_lines():
|
93 |
+
if line:
|
94 |
+
# Decode the line
|
95 |
+
decoded_line = line.decode('utf-8')
|
96 |
+
# Remove 'data: ' prefix if present
|
97 |
+
if decoded_line.startswith("data: "):
|
98 |
+
decoded_line = decoded_line[6:]
|
99 |
+
|
100 |
+
# Handle potential JSON decoding errors
|
101 |
+
try:
|
102 |
+
json_data = json.loads(decoded_line)
|
103 |
+
text = json_data.get("content", "") # Extract content field. crucial.
|
104 |
+
if text:
|
105 |
+
outputs.append(text)
|
106 |
+
yield "".join(outputs)
|
107 |
+
|
108 |
+
except json.JSONDecodeError:
|
109 |
+
print(f"JSONDecodeError: {decoded_line}")
|
110 |
+
# Handle the error, potentially skipping the line or logging it.
|
111 |
+
|
112 |
+
except requests.exceptions.RequestException as e:
|
113 |
+
print(f"Request failed: {e}")
|
114 |
+
yield f"Error: {e}" # Yield an error message to the user
|
115 |
+
except Exception as e:
|
116 |
+
print(f"An unexpected error occurred: {e}")
|
117 |
+
yield f"Error: {e}" # Yield error message
|
118 |
+
|
119 |
+
|
120 |
+
css_file_path = Path(Path(__file__).parent / "app.css")
|
121 |
+
|
122 |
+
# advanced settings (displayed in Accordion)
|
123 |
+
temperature_slider = gr.Slider(
|
124 |
+
minimum=0, maximum=1.0, value=TEMPERATURE, step=0.1, label="Temperature", elem_classes=["gr_accordion_element"]
|
125 |
+
)
|
126 |
+
top_p_slider = gr.Slider(
|
127 |
+
minimum=0, maximum=1.0, value=TOP_P, step=0.05, label="Top P", elem_classes=["gr_accordion_element"]
|
128 |
+
)
|
129 |
+
top_k_slider = gr.Slider(
|
130 |
+
minimum=0, maximum=100, value=TOP_K, step=1, label="Top K", elem_classes=["gr_accordion_element"]
|
131 |
+
)
|
132 |
+
repetition_penalty_slider = gr.Slider(
|
133 |
+
minimum=0,
|
134 |
+
maximum=2.0,
|
135 |
+
value=REPETITION_PENALTY,
|
136 |
+
step=0.05,
|
137 |
+
label="Repetition Penalty",
|
138 |
+
elem_classes=["gr_accordion_element"],
|
139 |
+
)
|
140 |
+
max_new_tokens_slider = gr.Slider(
|
141 |
+
minimum=1,
|
142 |
+
maximum=2000,
|
143 |
+
value=MAX_NEW_TOKENS,
|
144 |
+
step=1,
|
145 |
+
label="Max New Tokens",
|
146 |
+
elem_classes=["gr_accordion_element"],
|
147 |
+
)
|
148 |
+
chat_interface_accordion = gr.Accordion(label="Advanced Settings", open=False)
|
149 |
+
|
150 |
+
with gr.Blocks(fill_height=True, css_paths=css_file_path, theme=theme, title=TITLE) as demo:
|
151 |
+
gr.HTML(f"<h2>{TITLE}</h2>", elem_classes=["gr_title"])
|
152 |
+
gr.HTML(DESCRIPTION)
|
153 |
+
chat_interface = gr.ChatInterface(
|
154 |
+
fn=generate,
|
155 |
+
examples=[
|
156 |
+
["Explain the concept of quantum computing to someone with no background in physics or computer science."],
|
157 |
+
["What is OpenShift?"],
|
158 |
+
["What's the importance of low latency inference?"],
|
159 |
+
["Help me boost productivity habits."],
|
160 |
+
],
|
161 |
+
example_labels=[
|
162 |
+
"Explain quantum computing",
|
163 |
+
"What is OpenShift?",
|
164 |
+
"Importance of low latency inference",
|
165 |
+
"Boosting productivity habits",
|
166 |
+
],
|
167 |
+
cache_examples=False,
|
168 |
+
type="messages",
|
169 |
+
additional_inputs=[
|
170 |
+
temperature_slider,
|
171 |
+
repetition_penalty_slider,
|
172 |
+
top_p_slider,
|
173 |
+
top_k_slider,
|
174 |
+
max_new_tokens_slider,
|
175 |
+
],
|
176 |
+
additional_inputs_accordion=chat_interface_accordion,
|
177 |
+
)
|
178 |
+
|
179 |
+
if __name__ == "__main__":
|
180 |
+
demo.queue().launch()
|
index.html
DELETED
@@ -1,19 +0,0 @@
|
|
1 |
-
<!doctype html>
|
2 |
-
<html>
|
3 |
-
<head>
|
4 |
-
<meta charset="utf-8" />
|
5 |
-
<meta name="viewport" content="width=device-width" />
|
6 |
-
<title>My static Space</title>
|
7 |
-
<link rel="stylesheet" href="style.css" />
|
8 |
-
</head>
|
9 |
-
<body>
|
10 |
-
<div class="card">
|
11 |
-
<h1>Welcome to your static Space!</h1>
|
12 |
-
<p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
|
13 |
-
<p>
|
14 |
-
Also don't forget to check the
|
15 |
-
<a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
|
16 |
-
</p>
|
17 |
-
</div>
|
18 |
-
</body>
|
19 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
llama-server
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:fbd926bad47fcff408ed4065ef70ce6f468d519494bab31c80d0e3400cf449f1
|
3 |
+
size 2220844
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio-client
|
2 |
+
gradio
|
3 |
+
huggingface-hub
|
themes/carbon.py
ADDED
@@ -0,0 +1,147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""IBM Carbon theme for gradio demos.
|
2 |
+
|
3 |
+
This version builds on top of the Carbon theme to make it more playful with rounded corners, a larger font family to
|
4 |
+
enhance readability, and the IBM Cool Gray color palette for better consistency with other IBM Research demos, such as
|
5 |
+
Bee.
|
6 |
+
"""
|
7 |
+
|
8 |
+
import gradio as gr
|
9 |
+
from gradio.themes.utils import sizes
|
10 |
+
|
11 |
+
theme = gr.themes.Base(
|
12 |
+
primary_hue=gr.themes.Color(
|
13 |
+
c100="#EDF5FF",
|
14 |
+
c200="#D0E2FF",
|
15 |
+
c300="#A6C8FF",
|
16 |
+
c400="#78A9FF",
|
17 |
+
c50="#F9F9FB",
|
18 |
+
c500="#4589FF",
|
19 |
+
c600="#0F62FE",
|
20 |
+
c700="#0043CE",
|
21 |
+
c800="#002D9C",
|
22 |
+
c900="#001D6C",
|
23 |
+
c950="#001141",
|
24 |
+
),
|
25 |
+
secondary_hue=gr.themes.Color(
|
26 |
+
c100="#EDF5FF",
|
27 |
+
c200="#D0E2FF",
|
28 |
+
c300="#A6C8FF",
|
29 |
+
c400="#78A9FF",
|
30 |
+
c50="#F9F9FB",
|
31 |
+
c500="#4589FF",
|
32 |
+
c600="#0F62FE",
|
33 |
+
c700="#0043CE",
|
34 |
+
c800="#002D9C",
|
35 |
+
c900="#001D6C",
|
36 |
+
c950="#001141",
|
37 |
+
),
|
38 |
+
neutral_hue=gr.themes.Color(
|
39 |
+
c100="#F2F4F8",
|
40 |
+
c200="#DDE1E6",
|
41 |
+
c300="#C1C7CD",
|
42 |
+
c400="#A2A9B0",
|
43 |
+
c50="#F9F9FB",
|
44 |
+
c500="#878D96",
|
45 |
+
c600="#697077",
|
46 |
+
c700="#4D5358",
|
47 |
+
c800="#393939",
|
48 |
+
c900="#21272A",
|
49 |
+
c950="#121619",
|
50 |
+
),
|
51 |
+
spacing_size=sizes.spacing_md, # change spacing to default size
|
52 |
+
radius_size=sizes.radius_md, # change spacing to default size and Keep Radius to make demo feel more playful
|
53 |
+
text_size=sizes.text_lg, # change fontsize to default size
|
54 |
+
# spacing_size: sizes.Size | str = sizes.spacing_md, #change spacing to default size
|
55 |
+
# radius_size: sizes.Size | str = sizes.radius_md, #change spacing to default size and Keep Radius to make
|
56 |
+
# demo feel more playful
|
57 |
+
# text_size: sizes.Size | str = sizes.text_lg, #change fontsize to default size
|
58 |
+
font=["IBM Plex Sans", "ui-sans-serif", "system-ui", "sans-serif"], # update font
|
59 |
+
font_mono=["IBM Plex Mono", "ui-monospace", "Consolas", "monospace"], # update font
|
60 |
+
).set(
|
61 |
+
# Colors
|
62 |
+
background_fill_primary="*neutral_100", # Coolgray10 background
|
63 |
+
background_fill_primary_dark="*neutral_950", # Coolgray95 background for dark mode
|
64 |
+
slider_color="*primary_600", # Blue60
|
65 |
+
slider_color_dark="*primary_500", # Blue50
|
66 |
+
# Shadows
|
67 |
+
shadow_drop="0 1px 4px 0 rgb(0 0 0 / 0.1)",
|
68 |
+
shadow_drop_lg="0 2px 5px 0 rgb(0 0 0 / 0.1)",
|
69 |
+
# Block Labels
|
70 |
+
block_background_fill="white",
|
71 |
+
block_label_background_fill="white", # same color as blockback gound fill
|
72 |
+
block_label_radius="*radius_md",
|
73 |
+
block_label_text_size="*text_md",
|
74 |
+
block_label_text_weight="600",
|
75 |
+
block_label_text_color="black",
|
76 |
+
block_label_text_color_dark="white",
|
77 |
+
block_title_radius="*block_label_radius",
|
78 |
+
block_title_background_fill="*block_label_background_fill",
|
79 |
+
block_title_text_weight="600",
|
80 |
+
block_title_text_color="black",
|
81 |
+
block_title_text_color_dark="white",
|
82 |
+
block_label_margin="*spacing_md",
|
83 |
+
# Inputs
|
84 |
+
input_background_fill="white",
|
85 |
+
input_background_fill_dark="*block-background-fill",
|
86 |
+
input_border_color="*neutral_100",
|
87 |
+
input_shadow="*shadow_drop",
|
88 |
+
input_shadow_focus="*shadow_drop_lg",
|
89 |
+
checkbox_shadow="none",
|
90 |
+
# Buttons
|
91 |
+
shadow_spread="6px",
|
92 |
+
button_primary_shadow="*shadow_drop_lg",
|
93 |
+
button_primary_shadow_hover="*shadow_drop_lg",
|
94 |
+
button_primary_shadow_active="*shadow_inset",
|
95 |
+
button_secondary_shadow="*shadow_drop_lg",
|
96 |
+
button_secondary_shadow_hover="*shadow_drop_lg",
|
97 |
+
button_secondary_shadow_active="*shadow_inset",
|
98 |
+
checkbox_label_shadow="*shadow_drop_lg",
|
99 |
+
button_primary_background_fill="*primary_600",
|
100 |
+
button_primary_background_fill_hover="*primary_500",
|
101 |
+
button_primary_background_fill_hover_dark="*primary_500",
|
102 |
+
button_primary_text_color="white",
|
103 |
+
button_secondary_background_fill="white",
|
104 |
+
button_secondary_background_fill_hover="*neutral_100",
|
105 |
+
button_secondary_background_fill_dark="*neutral_800", # Secondary cool gray 80
|
106 |
+
button_secondary_background_fill_hover_dark="*primary_500",
|
107 |
+
button_secondary_text_color="*neutral_800",
|
108 |
+
button_cancel_background_fill="*button_secondary_background_fill",
|
109 |
+
button_cancel_background_fill_hover="*button_secondary_background_fill_hover",
|
110 |
+
button_cancel_background_fill_hover_dark="*button_secondary_background_fill_hover",
|
111 |
+
button_cancel_text_color="*button_secondary_text_color",
|
112 |
+
checkbox_label_background_fill_selected="*primary_200",
|
113 |
+
checkbox_label_background_fill_selected_dark="*primary_500",
|
114 |
+
checkbox_border_width="1px",
|
115 |
+
checkbox_border_color="*neutral_200",
|
116 |
+
checkbox_background_color_dark="*neutral_700", # Jan 18 test to fix checkbox, radio button background color
|
117 |
+
checkbox_background_color_selected="*primary_600",
|
118 |
+
checkbox_background_color_selected_dark="*primary_500",
|
119 |
+
checkbox_border_color_focus="*primary_600",
|
120 |
+
checkbox_border_color_focus_dark="*primary_500",
|
121 |
+
checkbox_border_color_selected="*primary_600",
|
122 |
+
checkbox_border_color_selected_dark="*primary_500",
|
123 |
+
checkbox_label_text_color_selected="black",
|
124 |
+
# Borders
|
125 |
+
block_border_width="1px", # test example border
|
126 |
+
panel_border_width="1px",
|
127 |
+
# Chatbubble related colors
|
128 |
+
# light
|
129 |
+
# color_accent = "*secondary_400",
|
130 |
+
border_color_accent_subdued="*color_accent_soft", # chatbubble human border color, use Blue 20 as an accent color
|
131 |
+
color_accent_soft="*secondary_200", # chatbubble human color
|
132 |
+
# darkmode
|
133 |
+
# chatbubble human border color in darkmode, use Blue 20 as an accent color
|
134 |
+
border_color_accent_subdued_dark="*secondary_500",
|
135 |
+
color_accent_soft_dark="*secondary_500", # chatbubble human color in dark mode
|
136 |
+
# Chatbot related font
|
137 |
+
chatbot_text_size="*text_md", # make it larger
|
138 |
+
# additional dark mode related tweaks:
|
139 |
+
# block_background_fill_dark="*neutral_950", # Jan 18 test coolgray95 background for dark mode
|
140 |
+
block_label_background_fill_dark="*neutral_800", # same color as blockback gound fill
|
141 |
+
block_title_background_fill_dark="*block_label_background_fill",
|
142 |
+
# input_background_fill_dark="*neutral_800", #This attribute help match fill color cool gray 80 to match background
|
143 |
+
# however cause the problem for the general theme.
|
144 |
+
# input_shadow_dark="*shadow_drop", #Test if it could make the border without the color
|
145 |
+
# input_border_color_dark="*neutral_200",#add attribute for border Jan 18
|
146 |
+
checkbox_border_color_dark="*neutral_600", # Jan 18 test to fix border
|
147 |
+
)
|
themes/research_monochrome.py
ADDED
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""IBM Research Monochrome theme for gradio demos.
|
2 |
+
|
3 |
+
This version is a variation of CarbonSoft style, where the primary button is dark gray to create monochrome style. This
|
4 |
+
version uses the style from Research demos such as Bee to make it more playful with rounded corners, a larger font
|
5 |
+
family to enhance readability, and the IBM Cool Gray color palette for better consistency with other IBM Research demos,
|
6 |
+
such as Bee.
|
7 |
+
"""
|
8 |
+
|
9 |
+
import gradio as gr
|
10 |
+
from gradio.themes.utils import sizes
|
11 |
+
|
12 |
+
theme = gr.themes.Base(
|
13 |
+
primary_hue=gr.themes.Color(
|
14 |
+
c100="#EDF5FF",
|
15 |
+
c200="#D0E2FF",
|
16 |
+
c300="#A6C8FF",
|
17 |
+
c400="#78A9FF",
|
18 |
+
c50="#F9F9FB",
|
19 |
+
c500="#4589FF",
|
20 |
+
c600="#0F62FE",
|
21 |
+
c700="#0043CE",
|
22 |
+
c800="#002D9C",
|
23 |
+
c900="#001D6C",
|
24 |
+
c950="#001141",
|
25 |
+
),
|
26 |
+
secondary_hue=gr.themes.Color(
|
27 |
+
c100="#EDF5FF",
|
28 |
+
c200="#D0E2FF",
|
29 |
+
c300="#A6C8FF",
|
30 |
+
c400="#78A9FF",
|
31 |
+
c50="#F9F9FB",
|
32 |
+
c500="#4589FF",
|
33 |
+
c600="#0F62FE",
|
34 |
+
c700="#0043CE",
|
35 |
+
c800="#002D9C",
|
36 |
+
c900="#001D6C",
|
37 |
+
c950="#001141",
|
38 |
+
),
|
39 |
+
neutral_hue=gr.themes.Color(
|
40 |
+
c100="#F2F4F8",
|
41 |
+
c200="#DDE1E6",
|
42 |
+
c300="#C1C7CD",
|
43 |
+
c400="#A2A9B0",
|
44 |
+
c50="#F9F9FB",
|
45 |
+
c500="#878D96",
|
46 |
+
c600="#697077",
|
47 |
+
c700="#4D5358",
|
48 |
+
c800="#393939",
|
49 |
+
c900="#21272A",
|
50 |
+
c950="#121619",
|
51 |
+
),
|
52 |
+
spacing_size=sizes.spacing_md, # change spacing to default size
|
53 |
+
radius_size=sizes.radius_md, # change spacing to default size and Keep Radius to make demo feel more playful
|
54 |
+
text_size=sizes.text_md, # change fontsize to default size
|
55 |
+
# spacing_size: sizes.Size | str = sizes.spacing_md, #change spacing to default size
|
56 |
+
# radius_size: sizes.Size | str = sizes.radius_md, #change spacing to default size and Keep Radius to make
|
57 |
+
# demo feel more playful
|
58 |
+
# text_size: sizes.Size | str = sizes.text_lg, #change fontsize to default size
|
59 |
+
font=["IBM Plex Sans", "ui-sans-serif", "system-ui", "sans-serif"], # update font
|
60 |
+
font_mono=["IBM Plex Mono", "ui-monospace", "Consolas", "monospace"], # update font
|
61 |
+
).set(
|
62 |
+
# Colors
|
63 |
+
background_fill_primary="*neutral_100", # Coolgray10 background
|
64 |
+
background_fill_primary_dark="*neutral_950", # Coolgray95 background for dark mode
|
65 |
+
# Change blue to black to create monochrome style
|
66 |
+
slider_color="*neutral_900",
|
67 |
+
slider_color_dark="*primary_500",
|
68 |
+
# Shadows
|
69 |
+
shadow_drop="0 1px 4px 0 rgb(0 0 0 / 0.1)",
|
70 |
+
shadow_drop_lg="0 2px 5px 0 rgb(0 0 0 / 0.1)",
|
71 |
+
# Block Labels
|
72 |
+
block_background_fill="white",
|
73 |
+
block_label_background_fill="white", # same color as blockback gound fill
|
74 |
+
block_label_radius="*radius_md",
|
75 |
+
block_label_text_size="*text_md",
|
76 |
+
block_label_text_weight="600",
|
77 |
+
block_label_text_color="black",
|
78 |
+
block_label_text_color_dark="white",
|
79 |
+
block_title_radius="*block_label_radius",
|
80 |
+
block_title_background_fill="*block_label_background_fill",
|
81 |
+
block_title_text_weight="400",
|
82 |
+
block_title_text_color="black",
|
83 |
+
block_title_text_color_dark="white",
|
84 |
+
block_label_margin="*spacing_md",
|
85 |
+
# Inputs
|
86 |
+
input_background_fill="white",
|
87 |
+
input_background_fill_dark="*block-background-fill",
|
88 |
+
input_border_color="*neutral_100",
|
89 |
+
input_shadow="*shadow_drop",
|
90 |
+
input_shadow_dark="0 1px 4px #000",
|
91 |
+
input_shadow_focus="*shadow_drop_lg",
|
92 |
+
checkbox_shadow="none",
|
93 |
+
# Buttons
|
94 |
+
shadow_spread="6px",
|
95 |
+
button_primary_shadow="*shadow_drop_lg",
|
96 |
+
button_primary_shadow_hover="*shadow_drop_lg",
|
97 |
+
button_primary_shadow_active="*shadow_inset",
|
98 |
+
button_secondary_shadow="*shadow_drop_lg",
|
99 |
+
button_secondary_shadow_hover="*shadow_drop_lg",
|
100 |
+
button_secondary_shadow_active="*shadow_inset",
|
101 |
+
checkbox_label_shadow="*shadow_drop_lg",
|
102 |
+
# Change blue to black to create monochrome style
|
103 |
+
button_primary_background_fill="*neutral_900",
|
104 |
+
button_primary_background_fill_dark="*neutral_600",
|
105 |
+
button_primary_background_fill_hover="*neutral_700",
|
106 |
+
button_primary_background_fill_hover_dark="*primary_500", # hover to be blue
|
107 |
+
button_primary_text_color="white",
|
108 |
+
button_secondary_background_fill="white",
|
109 |
+
button_secondary_background_fill_hover="*neutral_100",
|
110 |
+
button_secondary_background_fill_dark="*neutral_800", # Secondary cool gray 80
|
111 |
+
button_secondary_background_fill_hover_dark="*primary_500",
|
112 |
+
button_secondary_text_color="*neutral_800",
|
113 |
+
button_cancel_background_fill="*button_secondary_background_fill",
|
114 |
+
button_cancel_background_fill_hover="*button_secondary_background_fill_hover",
|
115 |
+
button_cancel_background_fill_hover_dark="*button_secondary_background_fill_hover",
|
116 |
+
button_cancel_text_color="*button_secondary_text_color",
|
117 |
+
checkbox_label_background_fill_selected="*primary_200",
|
118 |
+
checkbox_label_background_fill_selected_dark="*primary_500",
|
119 |
+
checkbox_border_width="1px",
|
120 |
+
checkbox_border_color="*neutral_200",
|
121 |
+
checkbox_background_color_dark="*neutral_700", # Jan 18 test to fix checkbox, radio button background color
|
122 |
+
checkbox_background_color_selected="*primary_600",
|
123 |
+
checkbox_background_color_selected_dark="*primary_500",
|
124 |
+
checkbox_border_color_focus="*primary_600",
|
125 |
+
checkbox_border_color_focus_dark="*primary_500",
|
126 |
+
checkbox_border_color_selected="*primary_600",
|
127 |
+
checkbox_border_color_selected_dark="*primary_500",
|
128 |
+
checkbox_label_text_color_selected="black",
|
129 |
+
# Borders
|
130 |
+
block_border_width="1px", # test example border
|
131 |
+
panel_border_width="1px",
|
132 |
+
# Chatbubble related colors
|
133 |
+
# light
|
134 |
+
# color_accent = "*secondary_400",
|
135 |
+
border_color_accent_subdued="*color_accent_soft", # chatbubble human border color, use Blue 20 as an accent color
|
136 |
+
color_accent_soft="*secondary_200", # chatbubble human color
|
137 |
+
# darkmode
|
138 |
+
# chatbubble human border color in darkmode, use Blue 20 as an accent color
|
139 |
+
border_color_accent_subdued_dark="*secondary_500",
|
140 |
+
color_accent_soft_dark="*secondary_500", # chatbubble human color in dark mode
|
141 |
+
# Chatbot related font
|
142 |
+
chatbot_text_size="*text_md", # make it larger
|
143 |
+
# additional dark mode related tweaks:
|
144 |
+
# block_background_fill_dark="*neutral_950", # Jan 18 test coolgray95 background for dark mode
|
145 |
+
block_label_background_fill_dark="*neutral_800", # same color as blockback gound fill
|
146 |
+
block_title_background_fill_dark="*block_label_background_fill",
|
147 |
+
# input_background_fill_dark="*neutral_800", #This attribute help match fill color cool gray 80 to match background
|
148 |
+
# however cause the problem for the general theme.
|
149 |
+
# input_shadow_dark="*shadow_drop", #Test if it could make the border without the color
|
150 |
+
# input_border_color_dark="*neutral_200",#add attribute for border Jan 18
|
151 |
+
checkbox_border_color_dark="*neutral_600", # Jan 18 test to fix border
|
152 |
+
)
|