Spaces:
Runtime error
Runtime error
Commit
Β·
d6cef6f
1
Parent(s):
5e18695
[feat] simple app framework
Browse files- .pdm-python +1 -0
- app.py +0 -151
- axolotl-config.md +0 -0
- pdm.lock +0 -0
- pyproject.toml +21 -0
- src/axolotl_ui/__init__.py +0 -0
- src/axolotl_ui/app.py +116 -0
- src/axolotl_ui/hf.py +0 -0
- src/axolotl_ui/utils.py +48 -0
- tests/__init__.py +0 -0
- www/Axolotl.png +0 -0
- www/Chinstrap.png +0 -0
- www/Gentoo.png +0 -0
- www/penguins.png +0 -0
- www/tweet-from-abhishek.jpeg +0 -0
.pdm-python
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
/Users/ua21849/Documents/axolotl-ui/.venv/bin/python
|
app.py
DELETED
@@ -1,151 +0,0 @@
|
|
1 |
-
from pathlib import Path
|
2 |
-
from typing import List, Dict, Tuple
|
3 |
-
import matplotlib.colors as mpl_colors
|
4 |
-
|
5 |
-
import pandas as pd
|
6 |
-
import seaborn as sns
|
7 |
-
import shinyswatch
|
8 |
-
|
9 |
-
from shiny import App, Inputs, Outputs, Session, reactive, render, req, ui
|
10 |
-
|
11 |
-
sns.set_theme()
|
12 |
-
|
13 |
-
www_dir = Path(__file__).parent.resolve() / "www"
|
14 |
-
|
15 |
-
df = pd.read_csv(Path(__file__).parent / "penguins.csv", na_values="NA")
|
16 |
-
numeric_cols: List[str] = df.select_dtypes(include=["float64"]).columns.tolist()
|
17 |
-
species: List[str] = df["Species"].unique().tolist()
|
18 |
-
species.sort()
|
19 |
-
|
20 |
-
app_ui = ui.page_fillable(
|
21 |
-
shinyswatch.theme.minty(),
|
22 |
-
ui.layout_sidebar(
|
23 |
-
ui.sidebar(
|
24 |
-
# Artwork by @allison_horst
|
25 |
-
ui.input_selectize(
|
26 |
-
"xvar",
|
27 |
-
"X variable",
|
28 |
-
numeric_cols,
|
29 |
-
selected="Bill Length (mm)",
|
30 |
-
),
|
31 |
-
ui.input_selectize(
|
32 |
-
"yvar",
|
33 |
-
"Y variable",
|
34 |
-
numeric_cols,
|
35 |
-
selected="Bill Depth (mm)",
|
36 |
-
),
|
37 |
-
ui.input_checkbox_group(
|
38 |
-
"species", "Filter by species", species, selected=species
|
39 |
-
),
|
40 |
-
ui.hr(),
|
41 |
-
ui.input_switch("by_species", "Show species", value=True),
|
42 |
-
ui.input_switch("show_margins", "Show marginal plots", value=True),
|
43 |
-
),
|
44 |
-
ui.output_ui("value_boxes"),
|
45 |
-
ui.output_plot("scatter", fill=True),
|
46 |
-
ui.help_text(
|
47 |
-
"Artwork by ",
|
48 |
-
ui.a("@allison_horst", href="https://twitter.com/allison_horst"),
|
49 |
-
class_="text-end",
|
50 |
-
),
|
51 |
-
),
|
52 |
-
)
|
53 |
-
|
54 |
-
|
55 |
-
def server(input: Inputs, output: Outputs, session: Session):
|
56 |
-
@reactive.Calc
|
57 |
-
def filtered_df() -> pd.DataFrame:
|
58 |
-
"""Returns a Pandas data frame that includes only the desired rows"""
|
59 |
-
|
60 |
-
# This calculation "req"uires that at least one species is selected
|
61 |
-
req(len(input.species()) > 0)
|
62 |
-
|
63 |
-
# Filter the rows so we only include the desired species
|
64 |
-
return df[df["Species"].isin(input.species())]
|
65 |
-
|
66 |
-
@output
|
67 |
-
@render.plot
|
68 |
-
def scatter():
|
69 |
-
"""Generates a plot for Shiny to display to the user"""
|
70 |
-
|
71 |
-
# The plotting function to use depends on whether margins are desired
|
72 |
-
plotfunc = sns.jointplot if input.show_margins() else sns.scatterplot
|
73 |
-
|
74 |
-
plotfunc(
|
75 |
-
data=filtered_df(),
|
76 |
-
x=input.xvar(),
|
77 |
-
y=input.yvar(),
|
78 |
-
palette=palette,
|
79 |
-
hue="Species" if input.by_species() else None,
|
80 |
-
hue_order=species,
|
81 |
-
legend=False,
|
82 |
-
)
|
83 |
-
|
84 |
-
@output
|
85 |
-
@render.ui
|
86 |
-
def value_boxes():
|
87 |
-
df = filtered_df()
|
88 |
-
|
89 |
-
def penguin_value_box(title: str, count: int, bgcol: str, showcase_img: str):
|
90 |
-
return ui.value_box(
|
91 |
-
title,
|
92 |
-
count,
|
93 |
-
{"class_": "pt-1 pb-0"},
|
94 |
-
showcase=ui.fill.as_fill_item(
|
95 |
-
ui.tags.img(
|
96 |
-
{"style": "object-fit:contain;"},
|
97 |
-
src=showcase_img,
|
98 |
-
)
|
99 |
-
),
|
100 |
-
theme_color=None,
|
101 |
-
style=f"background-color: {bgcol};",
|
102 |
-
)
|
103 |
-
|
104 |
-
if not input.by_species():
|
105 |
-
return penguin_value_box(
|
106 |
-
"Penguins",
|
107 |
-
len(df.index),
|
108 |
-
bg_palette["default"],
|
109 |
-
# Artwork by @allison_horst
|
110 |
-
showcase_img="penguins.png",
|
111 |
-
)
|
112 |
-
|
113 |
-
value_boxes = [
|
114 |
-
penguin_value_box(
|
115 |
-
name,
|
116 |
-
len(df[df["Species"] == name]),
|
117 |
-
bg_palette[name],
|
118 |
-
# Artwork by @allison_horst
|
119 |
-
showcase_img=f"{name}.png",
|
120 |
-
)
|
121 |
-
for name in species
|
122 |
-
# Only include boxes for _selected_ species
|
123 |
-
if name in input.species()
|
124 |
-
]
|
125 |
-
|
126 |
-
return ui.layout_column_wrap(*value_boxes, width = 1 / len(value_boxes))
|
127 |
-
|
128 |
-
|
129 |
-
# "darkorange", "purple", "cyan4"
|
130 |
-
colors = [[255, 140, 0], [160, 32, 240], [0, 139, 139]]
|
131 |
-
colors = [(r / 255.0, g / 255.0, b / 255.0) for r, g, b in colors]
|
132 |
-
|
133 |
-
palette: Dict[str, Tuple[float, float, float]] = {
|
134 |
-
"Adelie": colors[0],
|
135 |
-
"Chinstrap": colors[1],
|
136 |
-
"Gentoo": colors[2],
|
137 |
-
"default": sns.color_palette()[0], # type: ignore
|
138 |
-
}
|
139 |
-
|
140 |
-
bg_palette = {}
|
141 |
-
# Use `sns.set_style("whitegrid")` to help find approx alpha value
|
142 |
-
for name, col in palette.items():
|
143 |
-
# Adjusted n_colors until `axe` accessibility did not complain about color contrast
|
144 |
-
bg_palette[name] = mpl_colors.to_hex(sns.light_palette(col, n_colors=7)[1]) # type: ignore
|
145 |
-
|
146 |
-
|
147 |
-
app = App(
|
148 |
-
app_ui,
|
149 |
-
server,
|
150 |
-
static_assets=str(www_dir),
|
151 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
axolotl-config.md
ADDED
File without changes
|
pdm.lock
ADDED
The diff for this file is too large to render.
See raw diff
|
|
pyproject.toml
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[project]
|
2 |
+
name = "axolotl-ui"
|
3 |
+
version = "0.0.1"
|
4 |
+
description = "Default template for PDM package"
|
5 |
+
authors = [
|
6 |
+
{name = "James Wade", email = "[email protected]"},
|
7 |
+
]
|
8 |
+
dependencies = [
|
9 |
+
"shiny==0.7.0",
|
10 |
+
"shinyswatch==0.4.2",
|
11 |
+
"seaborn==0.12.2",
|
12 |
+
"matplotlib==3.7.1",
|
13 |
+
"autotrain-advanced>=0.6.83",
|
14 |
+
]
|
15 |
+
requires-python = ">=3.9"
|
16 |
+
readme = "README.md"
|
17 |
+
license = {text = "Apache-2"}
|
18 |
+
|
19 |
+
|
20 |
+
[tool.pdm]
|
21 |
+
distribution = false
|
src/axolotl_ui/__init__.py
ADDED
File without changes
|
src/axolotl_ui/app.py
ADDED
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pathlib import Path
|
2 |
+
|
3 |
+
import seaborn as sns
|
4 |
+
import shinyswatch
|
5 |
+
|
6 |
+
from shiny import App, Inputs, Outputs, Session, ui
|
7 |
+
from htmltools import HTML
|
8 |
+
|
9 |
+
from utils import background_img, question_circle_fill
|
10 |
+
|
11 |
+
sns.set_theme()
|
12 |
+
|
13 |
+
www_dir = Path(__file__).parent.resolve() / "www"
|
14 |
+
|
15 |
+
project_config = ui.accordion_panel(
|
16 |
+
"Project Config",
|
17 |
+
*[
|
18 |
+
ui.input_text(
|
19 |
+
id="project_name",
|
20 |
+
label=ui.tooltip(
|
21 |
+
ui.span("Project Name ", question_circle_fill()), "Additional info"
|
22 |
+
),
|
23 |
+
placeholder="Awesome Axolotl"
|
24 |
+
),
|
25 |
+
ui.input_password(
|
26 |
+
id="hf_token",
|
27 |
+
label=ui.tooltip(
|
28 |
+
ui.span("HuggingFace Token ", question_circle_fill()), "T"
|
29 |
+
)
|
30 |
+
),
|
31 |
+
ui.input_text(
|
32 |
+
id="base_model",
|
33 |
+
label=ui.tooltip(
|
34 |
+
ui.span("Base Model ", question_circle_fill()),
|
35 |
+
"This is the huggingface model that contains *.pt, *.safetensors, or *.bin files",
|
36 |
+
),
|
37 |
+
placeholder="meta-llama/Llama-2-7b-chat-hf",
|
38 |
+
),
|
39 |
+
ui.input_select(
|
40 |
+
id="model_type",
|
41 |
+
label=ui.tooltip(
|
42 |
+
ui.span("Model Type ", question_circle_fill()),
|
43 |
+
"If you want to specify the type of model to load, AutoModelForCausalLM is a good choice too.",
|
44 |
+
),
|
45 |
+
choices=["AutoModelForCausalLM", "LlamaForCausalLM"],
|
46 |
+
selected="AutoModelForCausalLM",
|
47 |
+
),
|
48 |
+
ui.input_select(
|
49 |
+
id="model_derivation",
|
50 |
+
label=ui.tooltip(
|
51 |
+
ui.span("Model Source ", question_circle_fill()),
|
52 |
+
'Used to identify which the model is based on. Please note that if you set this to mistral, `padding_side` will be set to "left" by default',
|
53 |
+
),
|
54 |
+
choices=["falcon", "llama", "mistra", "qwen"],
|
55 |
+
selected="llama",
|
56 |
+
),
|
57 |
+
ui.accordion(
|
58 |
+
ui.accordion_panel(
|
59 |
+
"Advanced Config",
|
60 |
+
ui.input_text(id="test1", label="Test 2", placeholder="placeholder"),
|
61 |
+
),
|
62 |
+
open=False,
|
63 |
+
),
|
64 |
+
]
|
65 |
+
)
|
66 |
+
|
67 |
+
dataset_config = ui.accordion_panel(
|
68 |
+
"Datasets",
|
69 |
+
*[
|
70 |
+
ui.input_text(
|
71 |
+
id="dataset_path",
|
72 |
+
label=ui.tooltip(
|
73 |
+
ui.span("Dataset Path ", question_circle_fill()), "A list of one or more paths to datasets to finetune the model with. HuggingFace dataset repo | s3://,gs:// path | \"json\" for local dataset, make sure to fill data_files"
|
74 |
+
),
|
75 |
+
placeholder="vicgalle/alpaca-gpt4"
|
76 |
+
),
|
77 |
+
ui.input_select(
|
78 |
+
id="dataset_type",
|
79 |
+
label=ui.tooltip(
|
80 |
+
ui.span("Dataset Type ", question_circle_fill()), "The type of prompt to use for training. [alpaca, sharegpt, gpteacher, oasst, reflection]"
|
81 |
+
),
|
82 |
+
choices=["alpaca", "sharegpt", "gpteacher", "oasst", "reflection"],
|
83 |
+
selected="alpaca"
|
84 |
+
)
|
85 |
+
]
|
86 |
+
)
|
87 |
+
|
88 |
+
app_ui = ui.page_fillable(
|
89 |
+
shinyswatch.theme.minty(),
|
90 |
+
ui.layout_sidebar(
|
91 |
+
ui.sidebar(
|
92 |
+
ui.h3("Axolotl Laucher π"),
|
93 |
+
ui.accordion(project_config, id="project_config"),
|
94 |
+
ui.accordion(dataset_config, id="dataset_config", open=False),
|
95 |
+
ui.input_action_button(
|
96 |
+
"create_space",
|
97 |
+
"Create HF Space",
|
98 |
+
),
|
99 |
+
width=400,
|
100 |
+
class_="opacity-75"
|
101 |
+
),
|
102 |
+
HTML(background_img(url="https://github.com/OpenAccess-AI-Collective/axolotl/raw/main/image/axolotl.png",
|
103 |
+
opacity=0.1))
|
104 |
+
)
|
105 |
+
)
|
106 |
+
|
107 |
+
|
108 |
+
def server(input: Inputs, output: Outputs, session: Session):
|
109 |
+
return ()
|
110 |
+
|
111 |
+
|
112 |
+
app = App(
|
113 |
+
app_ui,
|
114 |
+
server,
|
115 |
+
static_assets=str(www_dir),
|
116 |
+
)
|
src/axolotl_ui/hf.py
ADDED
File without changes
|
src/axolotl_ui/utils.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from shiny import ui
|
2 |
+
|
3 |
+
# https://icons.getbootstrap.com/icons/question-circle-fill/
|
4 |
+
def question_circle_fill():
|
5 |
+
ui.HTML(
|
6 |
+
'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-question-circle-fill mb-1" viewBox="0 0 16 16"><path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM5.496 6.033h.825c.138 0 .248-.113.266-.25.09-.656.54-1.134 1.342-1.134.686 0 1.314.343 1.314 1.168 0 .635-.374.927-.965 1.371-.673.489-1.206 1.06-1.168 1.987l.003.217a.25.25 0 0 0 .25.246h.811a.25.25 0 0 0 .25-.25v-.105c0-.718.273-.927 1.01-1.486.609-.463 1.244-.977 1.244-2.056 0-1.511-1.276-2.241-2.673-2.241-1.267 0-2.655.59-2.75 2.286a.237.237 0 0 0 .241.247zm2.325 6.443c.61 0 1.029-.394 1.029-.927 0-.552-.42-.94-1.029-.94-.584 0-1.009.388-1.009.94 0 .533.425.927 1.01.927z"/></svg>'
|
7 |
+
)
|
8 |
+
|
9 |
+
def background_img(url: str, opacity: float) -> str:
|
10 |
+
"""
|
11 |
+
Generate CSS style for setting a somewhat transparent background image.
|
12 |
+
|
13 |
+
Parameters
|
14 |
+
----------
|
15 |
+
url : str
|
16 |
+
URL of the image to be used as a background.
|
17 |
+
opacity : float
|
18 |
+
Opacity level of the background image (0.0 to 1.0).
|
19 |
+
|
20 |
+
Returns
|
21 |
+
-------
|
22 |
+
str
|
23 |
+
A CSS style string to set the somewhat transparent background image.
|
24 |
+
"""
|
25 |
+
return f"""
|
26 |
+
<style>
|
27 |
+
body, html {{
|
28 |
+
width: 100%;
|
29 |
+
height: 100%;
|
30 |
+
margin: 0;
|
31 |
+
padding: 0;
|
32 |
+
}}
|
33 |
+
body::before {{
|
34 |
+
content: "";
|
35 |
+
position: fixed; /* Cover the entire page */
|
36 |
+
left: 0;
|
37 |
+
right: 0;
|
38 |
+
z-index: -1; /* Ensure the image stays in the background */
|
39 |
+
display: block;
|
40 |
+
background-image: url('{url}');
|
41 |
+
background-size: cover; /* Cover the entire page */
|
42 |
+
background-position: center; /* Center the background image */
|
43 |
+
opacity: {opacity}; /* Set the opacity for the image */
|
44 |
+
width: 100%;
|
45 |
+
height: 100%;
|
46 |
+
}}
|
47 |
+
</style>
|
48 |
+
"""
|
tests/__init__.py
ADDED
File without changes
|
www/Axolotl.png
ADDED
![]() |
www/Chinstrap.png
DELETED
Binary file (82 kB)
|
|
www/Gentoo.png
DELETED
Binary file (85.1 kB)
|
|
www/penguins.png
DELETED
Binary file (279 kB)
|
|
www/tweet-from-abhishek.jpeg
ADDED
![]() |