Spaces:
Running on Zero
Running on Zero
Deploybot commited on
Commit ·
d860a7b
0
Parent(s):
Deploy from stable branch
Browse files- .gitattributes +35 -0
- .gitignore +173 -0
- .gitlint +143 -0
- .pre-commit-config.yaml +48 -0
- DEVELOPMENT.md +154 -0
- README.md +12 -0
- poetry.lock +0 -0
- pyproject.toml +57 -0
- requirements.txt +261 -0
- src/app.css +75 -0
- src/app.py +213 -0
- src/app_head.html +16 -0
- src/themes/carbon.py +147 -0
- src/themes/research_monochrome.py +152 -0
- uv.lock +0 -0
.gitattributes
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz 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
|
.gitignore
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Byte-compiled / optimized / DLL files
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.py[cod]
|
| 4 |
+
*$py.class
|
| 5 |
+
|
| 6 |
+
# C extensions
|
| 7 |
+
*.so
|
| 8 |
+
|
| 9 |
+
# Distribution / packaging
|
| 10 |
+
.Python
|
| 11 |
+
build/
|
| 12 |
+
develop-eggs/
|
| 13 |
+
dist/
|
| 14 |
+
downloads/
|
| 15 |
+
eggs/
|
| 16 |
+
.eggs/
|
| 17 |
+
lib/
|
| 18 |
+
lib64/
|
| 19 |
+
parts/
|
| 20 |
+
sdist/
|
| 21 |
+
var/
|
| 22 |
+
wheels/
|
| 23 |
+
share/python-wheels/
|
| 24 |
+
*.egg-info/
|
| 25 |
+
.installed.cfg
|
| 26 |
+
*.egg
|
| 27 |
+
MANIFEST
|
| 28 |
+
|
| 29 |
+
# PyInstaller
|
| 30 |
+
# Usually these files are written by a python script from a template
|
| 31 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
| 32 |
+
*.manifest
|
| 33 |
+
*.spec
|
| 34 |
+
|
| 35 |
+
# Installer logs
|
| 36 |
+
pip-log.txt
|
| 37 |
+
pip-delete-this-directory.txt
|
| 38 |
+
|
| 39 |
+
# Unit test / coverage reports
|
| 40 |
+
htmlcov/
|
| 41 |
+
.tox/
|
| 42 |
+
.nox/
|
| 43 |
+
.coverage
|
| 44 |
+
.coverage.*
|
| 45 |
+
.cache
|
| 46 |
+
nosetests.xml
|
| 47 |
+
coverage.xml
|
| 48 |
+
*.cover
|
| 49 |
+
*.py,cover
|
| 50 |
+
.hypothesis/
|
| 51 |
+
.pytest_cache/
|
| 52 |
+
cover/
|
| 53 |
+
|
| 54 |
+
# Translations
|
| 55 |
+
*.mo
|
| 56 |
+
*.pot
|
| 57 |
+
|
| 58 |
+
# Django stuff:
|
| 59 |
+
*.log
|
| 60 |
+
local_settings.py
|
| 61 |
+
db.sqlite3
|
| 62 |
+
db.sqlite3-journal
|
| 63 |
+
|
| 64 |
+
# Flask stuff:
|
| 65 |
+
instance/
|
| 66 |
+
.webassets-cache
|
| 67 |
+
|
| 68 |
+
# Scrapy stuff:
|
| 69 |
+
.scrapy
|
| 70 |
+
|
| 71 |
+
# Sphinx documentation
|
| 72 |
+
docs/_build/
|
| 73 |
+
|
| 74 |
+
# PyBuilder
|
| 75 |
+
.pybuilder/
|
| 76 |
+
target/
|
| 77 |
+
|
| 78 |
+
# Jupyter Notebook
|
| 79 |
+
.ipynb_checkpoints
|
| 80 |
+
|
| 81 |
+
# IPython
|
| 82 |
+
profile_default/
|
| 83 |
+
ipython_config.py
|
| 84 |
+
|
| 85 |
+
# pyenv
|
| 86 |
+
# For a library or package, you might want to ignore these files since the code is
|
| 87 |
+
# intended to run in multiple environments; otherwise, check them in:
|
| 88 |
+
# .python-version
|
| 89 |
+
|
| 90 |
+
# pipenv
|
| 91 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
| 92 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
| 93 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
| 94 |
+
# install all needed dependencies.
|
| 95 |
+
#Pipfile.lock
|
| 96 |
+
|
| 97 |
+
# UV
|
| 98 |
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
| 99 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
| 100 |
+
# commonly ignored for libraries.
|
| 101 |
+
#uv.lock
|
| 102 |
+
|
| 103 |
+
# poetry
|
| 104 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
| 105 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
| 106 |
+
# commonly ignored for libraries.
|
| 107 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
| 108 |
+
#poetry.lock
|
| 109 |
+
|
| 110 |
+
# pdm
|
| 111 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
| 112 |
+
#pdm.lock
|
| 113 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
| 114 |
+
# in version control.
|
| 115 |
+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
| 116 |
+
.pdm.toml
|
| 117 |
+
.pdm-python
|
| 118 |
+
.pdm-build/
|
| 119 |
+
|
| 120 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
| 121 |
+
__pypackages__/
|
| 122 |
+
|
| 123 |
+
# Celery stuff
|
| 124 |
+
celerybeat-schedule
|
| 125 |
+
celerybeat.pid
|
| 126 |
+
|
| 127 |
+
# SageMath parsed files
|
| 128 |
+
*.sage.py
|
| 129 |
+
|
| 130 |
+
# Environments
|
| 131 |
+
.env
|
| 132 |
+
.venv
|
| 133 |
+
env/
|
| 134 |
+
venv/
|
| 135 |
+
ENV/
|
| 136 |
+
env.bak/
|
| 137 |
+
venv.bak/
|
| 138 |
+
|
| 139 |
+
# Spyder project settings
|
| 140 |
+
.spyderproject
|
| 141 |
+
.spyproject
|
| 142 |
+
|
| 143 |
+
# Rope project settings
|
| 144 |
+
.ropeproject
|
| 145 |
+
|
| 146 |
+
# mkdocs documentation
|
| 147 |
+
/site
|
| 148 |
+
|
| 149 |
+
# mypy
|
| 150 |
+
.mypy_cache/
|
| 151 |
+
.dmypy.json
|
| 152 |
+
dmypy.json
|
| 153 |
+
|
| 154 |
+
# Pyre type checker
|
| 155 |
+
.pyre/
|
| 156 |
+
|
| 157 |
+
# pytype static type analyzer
|
| 158 |
+
.pytype/
|
| 159 |
+
|
| 160 |
+
# Cython debug symbols
|
| 161 |
+
cython_debug/
|
| 162 |
+
|
| 163 |
+
# PyCharm
|
| 164 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
| 165 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
| 166 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
| 167 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
| 168 |
+
#.idea/
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
# Boilerplate specific ignores
|
| 172 |
+
.gradio/
|
| 173 |
+
.ruff_cache/
|
.gitlint
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Edit this file as you like.
|
| 2 |
+
#
|
| 3 |
+
# All these sections are optional. Each section with the exception of [general] represents
|
| 4 |
+
# one rule and each key in it is an option for that specific rule.
|
| 5 |
+
#
|
| 6 |
+
# Rules and sections can be referenced by their full name or by id. For example
|
| 7 |
+
# section "[body-max-line-length]" could also be written as "[B1]". Full section names are
|
| 8 |
+
# used in here for clarity.
|
| 9 |
+
#
|
| 10 |
+
# [general]
|
| 11 |
+
# Ignore certain rules, this example uses both full name and id
|
| 12 |
+
# ignore=title-trailing-punctuation, T3
|
| 13 |
+
|
| 14 |
+
[general]
|
| 15 |
+
# You HAVE to add the rule here to enable it, only configuring (such as below)
|
| 16 |
+
# does NOT enable it.
|
| 17 |
+
contrib=contrib-title-conventional-commits
|
| 18 |
+
|
| 19 |
+
[contrib-title-conventional-commits]
|
| 20 |
+
# Specify allowed commit types. For details see: https://www.conventionalcommits.org/
|
| 21 |
+
types = build,chore,ci,docs,feat,fix,perf,refactor,revert,style,test
|
| 22 |
+
|
| 23 |
+
# verbosity should be a value between 1 and 3, the commandline -v flags take precedence over this
|
| 24 |
+
# verbosity = 2
|
| 25 |
+
|
| 26 |
+
# By default gitlint will ignore merge, revert, fixup and squash commits.
|
| 27 |
+
# ignore-merge-commits=true
|
| 28 |
+
# ignore-revert-commits=true
|
| 29 |
+
# ignore-fixup-commits=true
|
| 30 |
+
# ignore-squash-commits=true
|
| 31 |
+
|
| 32 |
+
# Ignore any data send to gitlint via stdin
|
| 33 |
+
# ignore-stdin=true
|
| 34 |
+
|
| 35 |
+
# Fetch additional meta-data from the local repository when manually passing a
|
| 36 |
+
# commit message to gitlint via stdin or --commit-msg. Disabled by default.
|
| 37 |
+
# staged=true
|
| 38 |
+
|
| 39 |
+
# Hard fail when the target commit range is empty. Note that gitlint will
|
| 40 |
+
# already fail by default on invalid commit ranges. This option is specifically
|
| 41 |
+
# to tell gitlint to fail on *valid but empty* commit ranges.
|
| 42 |
+
# Disabled by default.
|
| 43 |
+
# fail-without-commits=true
|
| 44 |
+
|
| 45 |
+
# Enable debug mode (prints more output). Disabled by default.
|
| 46 |
+
# debug=true
|
| 47 |
+
|
| 48 |
+
# Enable community contributed rules
|
| 49 |
+
# See http://jorisroovers.github.io/gitlint/contrib_rules for details
|
| 50 |
+
# contrib=contrib-title-conventional-commits,CC1
|
| 51 |
+
|
| 52 |
+
# Set the extra-path where gitlint will search for user defined rules
|
| 53 |
+
# See http://jorisroovers.github.io/gitlint/user_defined_rules for details
|
| 54 |
+
# extra-path=examples/
|
| 55 |
+
|
| 56 |
+
# This is an example of how to configure the "title-max-length" rule and
|
| 57 |
+
# set the line-length it enforces to 50
|
| 58 |
+
# [title-max-length]
|
| 59 |
+
# line-length=50
|
| 60 |
+
|
| 61 |
+
# Conversely, you can also enforce minimal length of a title with the
|
| 62 |
+
# "title-min-length" rule:
|
| 63 |
+
# [title-min-length]
|
| 64 |
+
# min-length=5
|
| 65 |
+
|
| 66 |
+
# [title-must-not-contain-word]
|
| 67 |
+
# Comma-separated list of words that should not occur in the title. Matching is case
|
| 68 |
+
# insensitive. It's fine if the keyword occurs as part of a larger word (so "WIPING"
|
| 69 |
+
# will not cause a violation, but "WIP: my title" will.
|
| 70 |
+
# words=wip
|
| 71 |
+
|
| 72 |
+
# [title-match-regex]
|
| 73 |
+
# python-style regex that the commit-msg title must match
|
| 74 |
+
# Note that the regex can contradict with other rules if not used correctly
|
| 75 |
+
# (e.g. title-must-not-contain-word).
|
| 76 |
+
# regex=^US[0-9]*
|
| 77 |
+
|
| 78 |
+
# [body-max-line-length]
|
| 79 |
+
# line-length=72
|
| 80 |
+
|
| 81 |
+
# [body-min-length]
|
| 82 |
+
# min-length=5
|
| 83 |
+
|
| 84 |
+
# [body-is-missing]
|
| 85 |
+
# Whether to ignore this rule on merge commits (which typically only have a title)
|
| 86 |
+
# default = True
|
| 87 |
+
# ignore-merge-commits=false
|
| 88 |
+
|
| 89 |
+
# [body-changed-file-mention]
|
| 90 |
+
# List of files that need to be explicitly mentioned in the body when they are changed
|
| 91 |
+
# This is useful for when developers often erroneously edit certain files or git submodules.
|
| 92 |
+
# By specifying this rule, developers can only change the file when they explicitly reference
|
| 93 |
+
# it in the commit message.
|
| 94 |
+
# files=gitlint-core/gitlint/rules.py,README.md
|
| 95 |
+
|
| 96 |
+
# [body-match-regex]
|
| 97 |
+
# python-style regex that the commit-msg body must match.
|
| 98 |
+
# E.g. body must end in My-Commit-Tag: foo
|
| 99 |
+
# regex=My-Commit-Tag: foo$
|
| 100 |
+
|
| 101 |
+
# [author-valid-email]
|
| 102 |
+
# python-style regex that the commit author email address must match.
|
| 103 |
+
# For example, use the following regex if you only want to allow email addresses from foo.com
|
| 104 |
+
# regex=[^@]+@foo.com
|
| 105 |
+
|
| 106 |
+
# [ignore-by-title]
|
| 107 |
+
# Ignore certain rules for commits of which the title matches a regex
|
| 108 |
+
# E.g. Match commit titles that start with "Release"
|
| 109 |
+
# regex=^Release(.*)
|
| 110 |
+
|
| 111 |
+
# Ignore certain rules, you can reference them by their id or by their full name
|
| 112 |
+
# Use 'all' to ignore all rules
|
| 113 |
+
# ignore=T1,body-min-length
|
| 114 |
+
|
| 115 |
+
# [ignore-by-body]
|
| 116 |
+
# Ignore certain rules for commits of which the body has a line that matches a regex
|
| 117 |
+
# E.g. Match bodies that have a line that that contain "release"
|
| 118 |
+
# regex=(.*)release(.*)
|
| 119 |
+
#
|
| 120 |
+
# Ignore certain rules, you can reference them by their id or by their full name
|
| 121 |
+
# Use 'all' to ignore all rules
|
| 122 |
+
# ignore=T1,body-min-length
|
| 123 |
+
|
| 124 |
+
# [ignore-body-lines]
|
| 125 |
+
# Ignore certain lines in a commit body that match a regex.
|
| 126 |
+
# E.g. Ignore all lines that start with 'Co-Authored-By'
|
| 127 |
+
# regex=^Co-Authored-By
|
| 128 |
+
|
| 129 |
+
# [ignore-by-author-name]
|
| 130 |
+
# Ignore certain rules for commits of which the author name matches a regex
|
| 131 |
+
# E.g. Match commits made by dependabot
|
| 132 |
+
# regex=(.*)dependabot(.*)
|
| 133 |
+
#
|
| 134 |
+
# Ignore certain rules, you can reference them by their id or by their full name
|
| 135 |
+
# Use 'all' to ignore all rules
|
| 136 |
+
# ignore=T1,body-min-length
|
| 137 |
+
|
| 138 |
+
# This is a contrib rule - a community contributed rule. These are disabled by default.
|
| 139 |
+
# You need to explicitly enable them one-by-one by adding them to the "contrib" option
|
| 140 |
+
# under [general] section above.
|
| 141 |
+
# [contrib-title-conventional-commits]
|
| 142 |
+
# Specify allowed commit types. For details see: https://www.conventionalcommits.org/
|
| 143 |
+
# types = bugfix,user-story,epic
|
.pre-commit-config.yaml
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
repos:
|
| 2 |
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
| 3 |
+
rev: v5.0.0
|
| 4 |
+
hooks:
|
| 5 |
+
- id: check-added-large-files
|
| 6 |
+
- id: check-ast
|
| 7 |
+
- id: check-case-conflict
|
| 8 |
+
- id: check-json
|
| 9 |
+
- id: check-merge-conflict
|
| 10 |
+
- id: check-toml
|
| 11 |
+
- id: end-of-file-fixer
|
| 12 |
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
| 13 |
+
# Ruff version.
|
| 14 |
+
rev: v0.8.6
|
| 15 |
+
hooks:
|
| 16 |
+
- id: ruff
|
| 17 |
+
- repo: https://github.com/pycqa/isort
|
| 18 |
+
rev: 5.13.2
|
| 19 |
+
hooks:
|
| 20 |
+
- id: isort
|
| 21 |
+
args: ["--profile", "black"]
|
| 22 |
+
- repo: https://github.com/asottile/pyupgrade
|
| 23 |
+
rev: v3.19.1
|
| 24 |
+
hooks:
|
| 25 |
+
- id: pyupgrade
|
| 26 |
+
args: ["--py310-plus"]
|
| 27 |
+
- repo: https://github.com/psf/black
|
| 28 |
+
rev: 24.10.0
|
| 29 |
+
hooks:
|
| 30 |
+
- id: black
|
| 31 |
+
args:
|
| 32 |
+
- --line-length=120
|
| 33 |
+
- repo: https://github.com/jorisroovers/gitlint
|
| 34 |
+
rev: v0.19.1
|
| 35 |
+
hooks:
|
| 36 |
+
- id: gitlint
|
| 37 |
+
name: gitlint
|
| 38 |
+
language: python
|
| 39 |
+
entry: gitlint
|
| 40 |
+
args: [--staged, --msg-filename]
|
| 41 |
+
stages: [commit-msg]
|
| 42 |
+
- repo: https://github.com/astral-sh/uv
|
| 43 |
+
rev: '0.5.3'
|
| 44 |
+
hooks:
|
| 45 |
+
- id: uv-lock
|
| 46 |
+
- id: uv-export
|
| 47 |
+
name: uv export for base requirements
|
| 48 |
+
args: [--no-hashes, --format, requirements.txt, --output, requirements.txt]
|
DEVELOPMENT.md
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IBM Research Hugging Face Spaces gradio template
|
| 2 |
+
|
| 3 |
+
This template repository lets you quickly build a gradio Hugging Face spaces demo for the [ibm-granite org](https://huggingface.co/ibm-granite). It is set up with the requirements and theming for the ibm-granite org as well as pre-commit hooks and linting configuration to maintain a consistent code standard across all demos.
|
| 4 |
+
|
| 5 |
+
## 👩💻 Introduction
|
| 6 |
+
|
| 7 |
+
To deploy demos to the ibm-granite org on Hugging Face, you will be working with the Research Design Technical Experiences (RDTE) team via this GitHub org. You will not gain write access to Hugging Face org as there are limited seats available for those who are able to contribute. Hence, with read-only access you will work via the RDTE team (who have write access) to create and deploy demos to Hugging Face.
|
| 8 |
+
|
| 9 |
+
## 🛠️ Getting started
|
| 10 |
+
|
| 11 |
+
This is the place to start when building gradio demos for IBM Granite. Complete the following steps to get a repository set up and configured for your demo as well as the deployment pipeline to validate and push it to Hugging Face spaces.
|
| 12 |
+
|
| 13 |
+
1. [Raise an onboarding request](https://github.ibm.com/ibm-huggingface-space-demos/deployment/issues/new?assignees=james-sutton,gwhite&labels=onboarding%2Ctriage&projects=&template=onboarding.yaml&title=%5BOnboarding%5D%3A+). Please fill out the linked template to request a new repository be set up for you in this org and to give access to anything else required. You can always add more contributors later if needed.
|
| 14 |
+
2. Once your repository has been created, please either update it with your existing demo if you have one, or have a play with the example and modify it to create your new demo. You'll be working in the `main` branch whilst developing your demo.
|
| 15 |
+
3. Make sure that you follow the [development guide](#development-guide) and use the pre-configured pre-commit hooks before every commit and push. The validation pipeline will independently gate demos based on these hooks, so to avoid any deployment delays, it's best to run the checks with every commit.
|
| 16 |
+
4. Once you are happy with your demo and want to get it deployed to Hugging Face spaces in the ibm-granite org, open a pull request to merge the `main` branch into the `stable` branch. This will trigger a build and stage a deployment so that you and the RDTE team can validate the demo works well both from a technical and UX standpoint. If your demo needs any custom environment variables or secrets, let the RDTE team know and we will contact you directly to get them added to the Space configuration on Hugging Face.
|
| 17 |
+
5. Once the Pull request has been approved, you can merge it into the `stable` branch. A deployment will then push your changes into the Hugging Face spaces git repository and your demo will then be available.
|
| 18 |
+
|
| 19 |
+
## 🛠️ Development guide
|
| 20 |
+
|
| 21 |
+
Further information on developing the code in this repository is provided below.
|
| 22 |
+
|
| 23 |
+
### Create a code repository
|
| 24 |
+
|
| 25 |
+
[Use this template](https://github.ibm.com/new?template_name=gradio-template&template_owner=ibm-huggingface-space-demos) to create a new code repository for your demo. This could initially live somewhere else on GitHub if you wish but the RDTE team can also create a repository for you within this [ibm-hugging-face-space-demos](https://github.ibm.com/ibm-huggingface-space-demos) org.
|
| 26 |
+
|
| 27 |
+
Once your code repo has been created on GitHub (from this template), clone the repository to your local machine.
|
| 28 |
+
|
| 29 |
+
### Prerequisites
|
| 30 |
+
|
| 31 |
+
Some things you will need to do on your machine before developing.
|
| 32 |
+
|
| 33 |
+
#### Precommit
|
| 34 |
+
|
| 35 |
+
[Precommit](https://pre-commit.com) is a tool that adds git commit hooks. You will need to [install](https://pre-commit.com/#install) it on your machine and then run within your code repository:
|
| 36 |
+
|
| 37 |
+
```shell
|
| 38 |
+
pre-commit install
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
You can manually run pre-commit using the following command:
|
| 42 |
+
|
| 43 |
+
```shell
|
| 44 |
+
# To run against staged files:
|
| 45 |
+
pre-commit run
|
| 46 |
+
|
| 47 |
+
# If you want to run against staged and unstaged files:
|
| 48 |
+
pre-commit run --all-files
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
It is important to run the pre-commit hooks and fix any files that fail before you commit and push to the repository as the pull request build will fail any PR that does not adhere to them i.e. the RDTE team will only accept your code for deployment to Hugging Face once it has passed all of the pre-commit checks.
|
| 52 |
+
|
| 53 |
+
#### Poetry
|
| 54 |
+
|
| 55 |
+
[Poetry](https://python-poetry.org/) is a tool for Python packaging, dependency and virtual environment management that is used to manage the development of this project. You will need to install Poetry locally. There are several ways to install it including through the package manager of your operating system, however, the easiest way to install is likely using their installer, as follows:
|
| 56 |
+
|
| 57 |
+
```shell
|
| 58 |
+
curl -sSL https://install.python-poetry.org | python3 -
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
You can also use `pip` and `pipx` to install poetry, the details of which are at https://python-poetry.org/docs/
|
| 62 |
+
|
| 63 |
+
Once installed, the project is configured and controlled via the `pyproject.toml` file with the current dependency tree stored in `poetry.lock`. You may also [configure poetry](https://python-poetry.org/docs/configuration/) further if you wish but there is no need to do so as the default options are sufficient. You may, however, wish to change some of the options set in this template:
|
| 64 |
+
| Setting | Notes |
|
| 65 |
+
| ------- | ----- |
|
| 66 |
+
| name | **Update this**, to reflect the name of your demo |
|
| 67 |
+
| version | **Update this**, to reflect the current version of your demo |
|
| 68 |
+
| description | **Update this**, to a short description of your demo |
|
| 69 |
+
| authors | **Update this**, to the list of authors of your demo |
|
| 70 |
+
|
| 71 |
+
## Install and run locally
|
| 72 |
+
|
| 73 |
+
To get set up ready to run the code in development mode:
|
| 74 |
+
|
| 75 |
+
```shell
|
| 76 |
+
# create and activate a python virtual environment
|
| 77 |
+
poetry shell
|
| 78 |
+
poetry install
|
| 79 |
+
|
| 80 |
+
# run the demo locally
|
| 81 |
+
python src/app.py
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
## Testing
|
| 85 |
+
|
| 86 |
+
Each demo should have unit tests to validate that the generate functions work correctly, these can be stubbed out so that a GPU is not required. The UX elements will be tested manually in the staging environment.
|
| 87 |
+
|
| 88 |
+
1. Fork this template
|
| 89 |
+
2. Update the `.spaces-conf.yaml` with the correct metadata for your project. If you don't know what the fields should be, contact the Research Design Technical Experiences Team.
|
| 90 |
+
3. Create a virtual environment and install dependencies using poetry
|
| 91 |
+
4. Run some updates to make sure everything is up-to-date
|
| 92 |
+
5. Run the example code locally.
|
| 93 |
+
|
| 94 |
+
## Documenting your demo
|
| 95 |
+
|
| 96 |
+
If you would like to write some information/documentation about your demo that is intended for developers or other people that might want to run the demo from scratch, please use the [README.md](README.md) file, leaving the Hugging Face Spaces configuration header in place at the top of the file.
|
| 97 |
+
|
| 98 |
+
### Hugging face spaces configuration settings
|
| 99 |
+
|
| 100 |
+
Hugging Face allow the configuration of spaces demonstrations via the [README.md](README.md) file in the root of the project. There is a [Spaces Configuration Reference](https://huggingface.co/docs/hub/en/spaces-config-reference) guide that you can use to gain an understanding of the configuration options that can be specified here.
|
| 101 |
+
|
| 102 |
+
The template has a set of initial defaults, similar to these:
|
| 103 |
+
|
| 104 |
+
```
|
| 105 |
+
---
|
| 106 |
+
title: Granite 3.0 Chat
|
| 107 |
+
colorFrom: blue
|
| 108 |
+
colorTo: indigo
|
| 109 |
+
sdk: gradio
|
| 110 |
+
sdk_version: 5.9.1
|
| 111 |
+
app_file: src/app.py
|
| 112 |
+
pinned: false
|
| 113 |
+
license: apache-2.0
|
| 114 |
+
short_description: Chat with IBM Granite 3.0
|
| 115 |
+
---
|
| 116 |
+
```
|
| 117 |
+
|
| 118 |
+
#### Options
|
| 119 |
+
|
| 120 |
+
The default options specified above:
|
| 121 |
+
| Setting | Notes |
|
| 122 |
+
| ------- | ----- |
|
| 123 |
+
| title | **Update this**, keep this short (recommend max 24 chars), this information is displayed in the centre of the demo description card |
|
| 124 |
+
| emoji | Do not update this, our demos will use a consistent emoji character |
|
| 125 |
+
| colorFrom | Do not update this, used in combination with colorTo to colourize the demo description card |
|
| 126 |
+
| colorTo | see colorFrom |
|
| 127 |
+
| sdk | Do not update this, our Gradio demos will always use the "gradio" setting |
|
| 128 |
+
| sdk_version | Update this if necessary for your demo to function, ideally should be set to the latest gradio version |
|
| 129 |
+
| app_file | Update this if necessary for your demo to function, should be set to the path of the main entry point to the demo |
|
| 130 |
+
| license | Do not update this, our demos are to always be apache-2.0 licensed |
|
| 131 |
+
| short_description | **Update this**, should be set to a few words that describe the demo in a little more detail than the title, this information is displayed in the bottom-right of the demo description card |
|
| 132 |
+
|
| 133 |
+
Other available options:
|
| 134 |
+
| Setting | Notes |
|
| 135 |
+
| ------- | ----- |
|
| 136 |
+
| python_version | You may optionally set this, best advice is to use the default Python version if possible (current default is Python 3.10) |
|
| 137 |
+
| suggested_hardware | Do not use this, unlikely to be required as demos run on ZeroGPU |
|
| 138 |
+
| suggested_storage | Do not use this, our demos do not require storage |
|
| 139 |
+
| app_port | Do not use this, not relevant for gradio demos |
|
| 140 |
+
| base_path | Do not use this, use the app_file setting |
|
| 141 |
+
| fullWidth | Do not use this, our demos will use a consistent default width |
|
| 142 |
+
| header | Do not use this, our demos will use a consistent header |
|
| 143 |
+
| models | Do not use this, let their parsing discover these from our code |
|
| 144 |
+
| datasets | Do not use this, let their parsing discover these from our code |
|
| 145 |
+
| tags | Do not use this, we are not tagging our demos |
|
| 146 |
+
| thumbnail | Do not use this, provides a thumbnail for social sharing of demos |
|
| 147 |
+
| pinned | Do not use this, the RDTE team will change this setting if it's deemed necessary |
|
| 148 |
+
| hf_oauth | Do not use this, we are not using OAuth |
|
| 149 |
+
| hf_oauth_scopes | Do not use this, we are not using OAuth |
|
| 150 |
+
| hf_oauth_expiration_minutes | Do not use this, we are not using OAuth |
|
| 151 |
+
| disable_embedding | Do not use this, leave at the default that allows embedding to take place |
|
| 152 |
+
| startup_duration_timeout | Do not use this, leave at the default 30 minutes |
|
| 153 |
+
| custom_headers | Do not use this, we do not need to add any custom HTTP headers |
|
| 154 |
+
| preload_from_hub | Do not use this, specifying this builds the models and data sets into the container image with the goal of making start up times faster due to not needing to download them each time. However, RDTE testing indicates this setting significantly increases the start up time for our relatively small Granite models |
|
README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Granite 3.1 8b Instruct
|
| 3 |
+
emoji: 📝
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: indigo
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 5.9.1
|
| 8 |
+
app_file: src/app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
license: apache-2.0
|
| 11 |
+
short_description: Chat with IBM Granite 3.1 8b Instruct
|
| 12 |
+
---
|
poetry.lock
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
pyproject.toml
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[project]
|
| 2 |
+
name = "granite-3.1-8b-instruct"
|
| 3 |
+
version = "0.1.0"
|
| 4 |
+
description = "A demo of the IBM Granite 3.1 8b instruct model"
|
| 5 |
+
authors = [
|
| 6 |
+
{ name = "James Sutton", email = "james.sutton@uk.ibm.com" },
|
| 7 |
+
{ name = "Graham White", email = "gwhite@uk.ibm.com" },
|
| 8 |
+
{ name = "Michael Desmond", email = "mdesmond@us.ibm.com" },
|
| 9 |
+
]
|
| 10 |
+
license = { text = "Apache-2.0" }
|
| 11 |
+
readme = "README.md"
|
| 12 |
+
requires-python = ">=3.10,<3.11"
|
| 13 |
+
dependencies = [
|
| 14 |
+
"gradio==5.9.1",
|
| 15 |
+
"torch==2.10.0",
|
| 16 |
+
"spaces==0.50.2",
|
| 17 |
+
"transformers==4.47.1",
|
| 18 |
+
"accelerate==1.2.1",
|
| 19 |
+
"pydantic==2.10.6",
|
| 20 |
+
]
|
| 21 |
+
|
| 22 |
+
[project.optional-dependencies]
|
| 23 |
+
dev = [
|
| 24 |
+
"pre-commit>=4.0.1",
|
| 25 |
+
"git-lint>=0.1.2",
|
| 26 |
+
"ruff>=0.8.3",
|
| 27 |
+
"pytest>=8.3.4",
|
| 28 |
+
]
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
[tool.ruff]
|
| 32 |
+
select = [
|
| 33 |
+
"E", # pycodestyle
|
| 34 |
+
"F", # pyflakes
|
| 35 |
+
"UP", # pyupgrade
|
| 36 |
+
"D", # pydocstyle
|
| 37 |
+
"I", # isort
|
| 38 |
+
"B", # bugbear
|
| 39 |
+
"ANN", # annotations
|
| 40 |
+
"N", # pep8-naming
|
| 41 |
+
"C4", # Comprehensions
|
| 42 |
+
"DTZ", # DatetimeZ
|
| 43 |
+
"Q", # Quotes
|
| 44 |
+
"SIM", # Simplify
|
| 45 |
+
"RUF", # Ruff
|
| 46 |
+
]
|
| 47 |
+
ignore = ["D203", "D213"]
|
| 48 |
+
fixable = ["ALL"]
|
| 49 |
+
unfixable = []
|
| 50 |
+
line-length = 120
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
[tool.black]
|
| 54 |
+
line-length = 120
|
| 55 |
+
|
| 56 |
+
[tool.ruff.lint.pydocstyle]
|
| 57 |
+
convention = "google"
|
requirements.txt
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file was autogenerated by uv via the following command:
|
| 2 |
+
# uv export --format requirements.txt --no-hashes
|
| 3 |
+
accelerate==1.2.1
|
| 4 |
+
# via granite-3-1-8b-instruct
|
| 5 |
+
aiofiles==23.2.1
|
| 6 |
+
# via gradio
|
| 7 |
+
annotated-doc==0.0.4
|
| 8 |
+
# via
|
| 9 |
+
# fastapi
|
| 10 |
+
# typer
|
| 11 |
+
annotated-types==0.7.0
|
| 12 |
+
# via pydantic
|
| 13 |
+
anyio==4.13.0
|
| 14 |
+
# via
|
| 15 |
+
# gradio
|
| 16 |
+
# httpx
|
| 17 |
+
# starlette
|
| 18 |
+
certifi==2026.4.22
|
| 19 |
+
# via
|
| 20 |
+
# httpcore
|
| 21 |
+
# httpx
|
| 22 |
+
# requests
|
| 23 |
+
charset-normalizer==3.4.7
|
| 24 |
+
# via requests
|
| 25 |
+
click==8.3.3 ; sys_platform != 'emscripten'
|
| 26 |
+
# via
|
| 27 |
+
# typer
|
| 28 |
+
# uvicorn
|
| 29 |
+
colorama==0.4.6 ; sys_platform == 'win32'
|
| 30 |
+
# via
|
| 31 |
+
# click
|
| 32 |
+
# tqdm
|
| 33 |
+
cuda-bindings==12.9.4 ; platform_machine == 'x86_64' and sys_platform == 'linux'
|
| 34 |
+
# via torch
|
| 35 |
+
cuda-pathfinder==1.5.4 ; platform_machine == 'x86_64' and sys_platform == 'linux'
|
| 36 |
+
# via cuda-bindings
|
| 37 |
+
exceptiongroup==1.3.1
|
| 38 |
+
# via anyio
|
| 39 |
+
fastapi==0.136.1
|
| 40 |
+
# via gradio
|
| 41 |
+
ffmpy==1.0.0
|
| 42 |
+
# via gradio
|
| 43 |
+
filelock==3.29.0
|
| 44 |
+
# via
|
| 45 |
+
# huggingface-hub
|
| 46 |
+
# torch
|
| 47 |
+
# transformers
|
| 48 |
+
fsspec==2026.4.0
|
| 49 |
+
# via
|
| 50 |
+
# gradio-client
|
| 51 |
+
# huggingface-hub
|
| 52 |
+
# torch
|
| 53 |
+
gradio==5.9.1
|
| 54 |
+
# via
|
| 55 |
+
# granite-3-1-8b-instruct
|
| 56 |
+
# spaces
|
| 57 |
+
gradio-client==1.5.2
|
| 58 |
+
# via gradio
|
| 59 |
+
h11==0.16.0
|
| 60 |
+
# via
|
| 61 |
+
# httpcore
|
| 62 |
+
# uvicorn
|
| 63 |
+
hf-xet==1.5.0 ; platform_machine == 'aarch64' or platform_machine == 'amd64' or platform_machine == 'arm64' or platform_machine == 'x86_64'
|
| 64 |
+
# via huggingface-hub
|
| 65 |
+
httpcore==1.0.9
|
| 66 |
+
# via httpx
|
| 67 |
+
httpx==0.28.1
|
| 68 |
+
# via
|
| 69 |
+
# gradio
|
| 70 |
+
# gradio-client
|
| 71 |
+
# safehttpx
|
| 72 |
+
# spaces
|
| 73 |
+
huggingface-hub==0.36.2
|
| 74 |
+
# via
|
| 75 |
+
# accelerate
|
| 76 |
+
# gradio
|
| 77 |
+
# gradio-client
|
| 78 |
+
# tokenizers
|
| 79 |
+
# transformers
|
| 80 |
+
idna==3.15
|
| 81 |
+
# via
|
| 82 |
+
# anyio
|
| 83 |
+
# httpx
|
| 84 |
+
# requests
|
| 85 |
+
jinja2==3.1.6
|
| 86 |
+
# via
|
| 87 |
+
# gradio
|
| 88 |
+
# torch
|
| 89 |
+
markdown-it-py==4.2.0 ; sys_platform != 'emscripten'
|
| 90 |
+
# via rich
|
| 91 |
+
markupsafe==2.1.5
|
| 92 |
+
# via
|
| 93 |
+
# gradio
|
| 94 |
+
# jinja2
|
| 95 |
+
mdurl==0.1.2 ; sys_platform != 'emscripten'
|
| 96 |
+
# via markdown-it-py
|
| 97 |
+
mpmath==1.3.0
|
| 98 |
+
# via sympy
|
| 99 |
+
networkx==3.4.2
|
| 100 |
+
# via torch
|
| 101 |
+
numpy==2.2.6
|
| 102 |
+
# via
|
| 103 |
+
# accelerate
|
| 104 |
+
# gradio
|
| 105 |
+
# pandas
|
| 106 |
+
# transformers
|
| 107 |
+
nvidia-cublas-cu12==12.8.4.1 ; platform_machine == 'x86_64' and sys_platform == 'linux'
|
| 108 |
+
# via
|
| 109 |
+
# nvidia-cudnn-cu12
|
| 110 |
+
# nvidia-cusolver-cu12
|
| 111 |
+
# torch
|
| 112 |
+
nvidia-cuda-cupti-cu12==12.8.90 ; platform_machine == 'x86_64' and sys_platform == 'linux'
|
| 113 |
+
# via torch
|
| 114 |
+
nvidia-cuda-nvrtc-cu12==12.8.93 ; platform_machine == 'x86_64' and sys_platform == 'linux'
|
| 115 |
+
# via torch
|
| 116 |
+
nvidia-cuda-runtime-cu12==12.8.90 ; platform_machine == 'x86_64' and sys_platform == 'linux'
|
| 117 |
+
# via torch
|
| 118 |
+
nvidia-cudnn-cu12==9.10.2.21 ; platform_machine == 'x86_64' and sys_platform == 'linux'
|
| 119 |
+
# via torch
|
| 120 |
+
nvidia-cufft-cu12==11.3.3.83 ; platform_machine == 'x86_64' and sys_platform == 'linux'
|
| 121 |
+
# via torch
|
| 122 |
+
nvidia-cufile-cu12==1.13.1.3 ; platform_machine == 'x86_64' and sys_platform == 'linux'
|
| 123 |
+
# via torch
|
| 124 |
+
nvidia-curand-cu12==10.3.9.90 ; platform_machine == 'x86_64' and sys_platform == 'linux'
|
| 125 |
+
# via torch
|
| 126 |
+
nvidia-cusolver-cu12==11.7.3.90 ; platform_machine == 'x86_64' and sys_platform == 'linux'
|
| 127 |
+
# via torch
|
| 128 |
+
nvidia-cusparse-cu12==12.5.8.93 ; platform_machine == 'x86_64' and sys_platform == 'linux'
|
| 129 |
+
# via
|
| 130 |
+
# nvidia-cusolver-cu12
|
| 131 |
+
# torch
|
| 132 |
+
nvidia-cusparselt-cu12==0.7.1 ; platform_machine == 'x86_64' and sys_platform == 'linux'
|
| 133 |
+
# via torch
|
| 134 |
+
nvidia-nccl-cu12==2.27.5 ; platform_machine == 'x86_64' and sys_platform == 'linux'
|
| 135 |
+
# via torch
|
| 136 |
+
nvidia-nvjitlink-cu12==12.8.93 ; platform_machine == 'x86_64' and sys_platform == 'linux'
|
| 137 |
+
# via
|
| 138 |
+
# nvidia-cufft-cu12
|
| 139 |
+
# nvidia-cusolver-cu12
|
| 140 |
+
# nvidia-cusparse-cu12
|
| 141 |
+
# torch
|
| 142 |
+
nvidia-nvshmem-cu12==3.4.5 ; platform_machine == 'x86_64' and sys_platform == 'linux'
|
| 143 |
+
# via torch
|
| 144 |
+
nvidia-nvtx-cu12==12.8.90 ; platform_machine == 'x86_64' and sys_platform == 'linux'
|
| 145 |
+
# via torch
|
| 146 |
+
orjson==3.11.9
|
| 147 |
+
# via gradio
|
| 148 |
+
packaging==26.2
|
| 149 |
+
# via
|
| 150 |
+
# accelerate
|
| 151 |
+
# gradio
|
| 152 |
+
# gradio-client
|
| 153 |
+
# huggingface-hub
|
| 154 |
+
# spaces
|
| 155 |
+
# transformers
|
| 156 |
+
pandas==2.3.3
|
| 157 |
+
# via gradio
|
| 158 |
+
pillow==11.3.0
|
| 159 |
+
# via gradio
|
| 160 |
+
psutil==7.2.2
|
| 161 |
+
# via accelerate
|
| 162 |
+
pydantic==2.10.6
|
| 163 |
+
# via
|
| 164 |
+
# fastapi
|
| 165 |
+
# gradio
|
| 166 |
+
# granite-3-1-8b-instruct
|
| 167 |
+
# spaces
|
| 168 |
+
pydantic-core==2.27.2
|
| 169 |
+
# via pydantic
|
| 170 |
+
pydub==0.25.1
|
| 171 |
+
# via gradio
|
| 172 |
+
pygments==2.20.0 ; sys_platform != 'emscripten'
|
| 173 |
+
# via rich
|
| 174 |
+
python-dateutil==2.9.0.post0
|
| 175 |
+
# via pandas
|
| 176 |
+
python-multipart==0.0.28
|
| 177 |
+
# via gradio
|
| 178 |
+
pytz==2026.2
|
| 179 |
+
# via pandas
|
| 180 |
+
pyyaml==6.0.3
|
| 181 |
+
# via
|
| 182 |
+
# accelerate
|
| 183 |
+
# gradio
|
| 184 |
+
# huggingface-hub
|
| 185 |
+
# transformers
|
| 186 |
+
regex==2026.5.9
|
| 187 |
+
# via transformers
|
| 188 |
+
requests==2.34.2
|
| 189 |
+
# via
|
| 190 |
+
# huggingface-hub
|
| 191 |
+
# spaces
|
| 192 |
+
# transformers
|
| 193 |
+
rich==15.0.0 ; sys_platform != 'emscripten'
|
| 194 |
+
# via typer
|
| 195 |
+
ruff==0.15.13 ; sys_platform != 'emscripten'
|
| 196 |
+
# via gradio
|
| 197 |
+
safehttpx==0.1.7
|
| 198 |
+
# via gradio
|
| 199 |
+
safetensors==0.7.0
|
| 200 |
+
# via
|
| 201 |
+
# accelerate
|
| 202 |
+
# transformers
|
| 203 |
+
semantic-version==2.10.0
|
| 204 |
+
# via gradio
|
| 205 |
+
shellingham==1.5.4 ; sys_platform != 'emscripten'
|
| 206 |
+
# via typer
|
| 207 |
+
six==1.17.0
|
| 208 |
+
# via python-dateutil
|
| 209 |
+
spaces==0.50.2
|
| 210 |
+
# via granite-3-1-8b-instruct
|
| 211 |
+
starlette==0.52.1
|
| 212 |
+
# via
|
| 213 |
+
# fastapi
|
| 214 |
+
# gradio
|
| 215 |
+
sympy==1.14.0
|
| 216 |
+
# via torch
|
| 217 |
+
tokenizers==0.21.4
|
| 218 |
+
# via transformers
|
| 219 |
+
tomlkit==0.13.3
|
| 220 |
+
# via gradio
|
| 221 |
+
torch==2.10.0
|
| 222 |
+
# via
|
| 223 |
+
# accelerate
|
| 224 |
+
# granite-3-1-8b-instruct
|
| 225 |
+
tqdm==4.67.3
|
| 226 |
+
# via
|
| 227 |
+
# huggingface-hub
|
| 228 |
+
# transformers
|
| 229 |
+
transformers==4.47.1
|
| 230 |
+
# via granite-3-1-8b-instruct
|
| 231 |
+
triton==3.6.0 ; platform_machine == 'x86_64' and sys_platform == 'linux'
|
| 232 |
+
# via torch
|
| 233 |
+
typer==0.25.1 ; sys_platform != 'emscripten'
|
| 234 |
+
# via gradio
|
| 235 |
+
typing-extensions==4.15.0
|
| 236 |
+
# via
|
| 237 |
+
# anyio
|
| 238 |
+
# exceptiongroup
|
| 239 |
+
# fastapi
|
| 240 |
+
# gradio
|
| 241 |
+
# gradio-client
|
| 242 |
+
# huggingface-hub
|
| 243 |
+
# pydantic
|
| 244 |
+
# pydantic-core
|
| 245 |
+
# spaces
|
| 246 |
+
# starlette
|
| 247 |
+
# torch
|
| 248 |
+
# typing-inspection
|
| 249 |
+
# uvicorn
|
| 250 |
+
typing-inspection==0.4.2
|
| 251 |
+
# via fastapi
|
| 252 |
+
tzdata==2026.2
|
| 253 |
+
# via pandas
|
| 254 |
+
urllib3==2.7.0
|
| 255 |
+
# via
|
| 256 |
+
# gradio
|
| 257 |
+
# requests
|
| 258 |
+
uvicorn==0.47.0 ; sys_platform != 'emscripten'
|
| 259 |
+
# via gradio
|
| 260 |
+
websockets==14.2
|
| 261 |
+
# via gradio-client
|
src/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 |
+
}
|
src/app.py
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Template Demo for IBM Granite Hugging Face spaces."""
|
| 2 |
+
|
| 3 |
+
from collections.abc import Iterator
|
| 4 |
+
from datetime import datetime
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
from threading import Thread
|
| 7 |
+
|
| 8 |
+
import gradio as gr
|
| 9 |
+
import spaces
|
| 10 |
+
import torch
|
| 11 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
|
| 12 |
+
|
| 13 |
+
from themes.research_monochrome import theme
|
| 14 |
+
|
| 15 |
+
today_date = datetime.today().strftime("%B %-d, %Y") # noqa: DTZ002
|
| 16 |
+
|
| 17 |
+
SYS_PROMPT = f"""Knowledge Cutoff Date: April 2024.
|
| 18 |
+
Today's Date: {today_date}.
|
| 19 |
+
You are Granite, developed by IBM. You are a helpful AI assistant"""
|
| 20 |
+
TITLE = "IBM Granite 3.1 8b Instruct"
|
| 21 |
+
DESCRIPTION = """
|
| 22 |
+
<p>Granite 3.1 8b instruct is an open-source LLM supporting a 128k context window. Start with one of the sample prompts
|
| 23 |
+
or enter your own. Keep in mind that AI can occasionally make mistakes.
|
| 24 |
+
<span class="gr_docs_link">
|
| 25 |
+
<a href="https://www.ibm.com/granite/docs/">View Documentation <i class="fa fa-external-link"></i></a>
|
| 26 |
+
</span>
|
| 27 |
+
</p>
|
| 28 |
+
"""
|
| 29 |
+
MAX_INPUT_TOKEN_LENGTH = 128_000
|
| 30 |
+
MAX_NEW_TOKENS = 1024
|
| 31 |
+
TEMPERATURE = 0.7
|
| 32 |
+
TOP_P = 0.85
|
| 33 |
+
TOP_K = 50
|
| 34 |
+
REPETITION_PENALTY = 1.05
|
| 35 |
+
|
| 36 |
+
if not torch.cuda.is_available():
|
| 37 |
+
print("This demo may not work on CPU.")
|
| 38 |
+
|
| 39 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 40 |
+
"ibm-granite/granite-3.1-8b-instruct", torch_dtype=torch.float16, device_map="auto"
|
| 41 |
+
)
|
| 42 |
+
tokenizer = AutoTokenizer.from_pretrained("ibm-granite/granite-3.1-8b-instruct")
|
| 43 |
+
tokenizer.use_default_system_prompt = False
|
| 44 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
@spaces.GPU
|
| 48 |
+
def generate(
|
| 49 |
+
message: str,
|
| 50 |
+
chat_history: list[dict],
|
| 51 |
+
temperature: float = TEMPERATURE,
|
| 52 |
+
repetition_penalty: float = REPETITION_PENALTY,
|
| 53 |
+
top_p: float = TOP_P,
|
| 54 |
+
top_k: float = TOP_K,
|
| 55 |
+
max_new_tokens: int = MAX_NEW_TOKENS,
|
| 56 |
+
) -> Iterator[str]:
|
| 57 |
+
"""Generate function for chat demo."""
|
| 58 |
+
# Build messages
|
| 59 |
+
conversation = []
|
| 60 |
+
conversation.append({"role": "system", "content": SYS_PROMPT})
|
| 61 |
+
conversation += chat_history
|
| 62 |
+
conversation.append({"role": "user", "content": message})
|
| 63 |
+
|
| 64 |
+
# Convert messages to prompt format
|
| 65 |
+
input_ids = tokenizer.apply_chat_template(
|
| 66 |
+
conversation,
|
| 67 |
+
return_tensors="pt",
|
| 68 |
+
add_generation_prompt=True,
|
| 69 |
+
truncation=True,
|
| 70 |
+
max_length=MAX_INPUT_TOKEN_LENGTH - max_new_tokens,
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
input_ids = input_ids.to(model.device)
|
| 74 |
+
streamer = TextIteratorStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
|
| 75 |
+
generate_kwargs = dict(
|
| 76 |
+
{"input_ids": input_ids},
|
| 77 |
+
attention_mask=torch.ones_like(input_ids),
|
| 78 |
+
streamer=streamer,
|
| 79 |
+
max_new_tokens=max_new_tokens,
|
| 80 |
+
do_sample=True,
|
| 81 |
+
top_p=top_p,
|
| 82 |
+
top_k=top_k,
|
| 83 |
+
temperature=temperature,
|
| 84 |
+
num_beams=1,
|
| 85 |
+
repetition_penalty=repetition_penalty,
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
t = Thread(target=model.generate, kwargs=generate_kwargs)
|
| 89 |
+
t.start()
|
| 90 |
+
|
| 91 |
+
outputs = []
|
| 92 |
+
for text in streamer:
|
| 93 |
+
outputs.append(text)
|
| 94 |
+
yield "".join(outputs)
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
css_file_path = Path(Path(__file__).parent / "app.css")
|
| 98 |
+
head_file_path = Path(Path(__file__).parent / "app_head.html")
|
| 99 |
+
|
| 100 |
+
# advanced settings (displayed in Accordion)
|
| 101 |
+
temperature_slider = gr.Slider(
|
| 102 |
+
minimum=0, maximum=1.0, value=TEMPERATURE, step=0.1, label="Temperature", elem_classes=["gr_accordion_element"]
|
| 103 |
+
)
|
| 104 |
+
top_p_slider = gr.Slider(
|
| 105 |
+
minimum=0, maximum=1.0, value=TOP_P, step=0.05, label="Top P", elem_classes=["gr_accordion_element"]
|
| 106 |
+
)
|
| 107 |
+
top_k_slider = gr.Slider(
|
| 108 |
+
minimum=0, maximum=100, value=TOP_K, step=1, label="Top K", elem_classes=["gr_accordion_element"]
|
| 109 |
+
)
|
| 110 |
+
repetition_penalty_slider = gr.Slider(
|
| 111 |
+
minimum=0,
|
| 112 |
+
maximum=2.0,
|
| 113 |
+
value=REPETITION_PENALTY,
|
| 114 |
+
step=0.05,
|
| 115 |
+
label="Repetition Penalty",
|
| 116 |
+
elem_classes=["gr_accordion_element"],
|
| 117 |
+
)
|
| 118 |
+
max_new_tokens_slider = gr.Slider(
|
| 119 |
+
minimum=1,
|
| 120 |
+
maximum=2000,
|
| 121 |
+
value=MAX_NEW_TOKENS,
|
| 122 |
+
step=1,
|
| 123 |
+
label="Max New Tokens",
|
| 124 |
+
elem_classes=["gr_accordion_element"],
|
| 125 |
+
)
|
| 126 |
+
chat_interface_accordion = gr.Accordion(label="Advanced Settings", open=False)
|
| 127 |
+
|
| 128 |
+
with gr.Blocks(fill_height=True, css_paths=css_file_path, head_paths=head_file_path, theme=theme, title=TITLE) as demo:
|
| 129 |
+
gr.HTML(f"<h1>{TITLE}</h1>", elem_classes=["gr_title"])
|
| 130 |
+
gr.HTML(DESCRIPTION)
|
| 131 |
+
chat_interface = gr.ChatInterface(
|
| 132 |
+
fn=generate,
|
| 133 |
+
examples=[
|
| 134 |
+
["Explain the concept of quantum computing to someone with no background in physics or computer science."],
|
| 135 |
+
["What is OpenShift?"],
|
| 136 |
+
["What's the importance of low latency inference?"],
|
| 137 |
+
["Help me boost productivity habits."],
|
| 138 |
+
[
|
| 139 |
+
"""Explain the following code in a concise manner:
|
| 140 |
+
|
| 141 |
+
```java
|
| 142 |
+
import java.util.ArrayList;
|
| 143 |
+
import java.util.List;
|
| 144 |
+
|
| 145 |
+
public class Main {
|
| 146 |
+
|
| 147 |
+
public static void main(String[] args) {
|
| 148 |
+
int[] arr = {1, 5, 3, 4, 2};
|
| 149 |
+
int diff = 3;
|
| 150 |
+
List<Pair> pairs = findPairs(arr, diff);
|
| 151 |
+
for (Pair pair : pairs) {
|
| 152 |
+
System.out.println(pair.x + " " + pair.y);
|
| 153 |
+
}
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
public static List<Pair> findPairs(int[] arr, int diff) {
|
| 157 |
+
List<Pair> pairs = new ArrayList<>();
|
| 158 |
+
for (int i = 0; i < arr.length; i++) {
|
| 159 |
+
for (int j = i + 1; j < arr.length; j++) {
|
| 160 |
+
if (Math.abs(arr[i] - arr[j]) < diff) {
|
| 161 |
+
pairs.add(new Pair(arr[i], arr[j]));
|
| 162 |
+
}
|
| 163 |
+
}
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
return pairs;
|
| 167 |
+
}
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
class Pair {
|
| 171 |
+
int x;
|
| 172 |
+
int y;
|
| 173 |
+
public Pair(int x, int y) {
|
| 174 |
+
this.x = x;
|
| 175 |
+
this.y = y;
|
| 176 |
+
}
|
| 177 |
+
}
|
| 178 |
+
```"""
|
| 179 |
+
],
|
| 180 |
+
[
|
| 181 |
+
"""Generate a Java code block from the following explanation:
|
| 182 |
+
|
| 183 |
+
The code in the Main class finds all pairs in an array whose absolute difference is less than a given value.
|
| 184 |
+
|
| 185 |
+
The findPairs method takes two arguments: an array of integers and a difference value. It iterates over the array and compares each element to every other element in the array. If the absolute difference between the two elements is less than the difference value, a new Pair object is created and added to a list.
|
| 186 |
+
|
| 187 |
+
The Pair class is a simple data structure that stores two integers.
|
| 188 |
+
|
| 189 |
+
The main method creates an array of integers, initializes the difference value, and calls the findPairs method to find all pairs in the array. Finally, the code iterates over the list of pairs and prints each pair to the console.""" # noqa: E501
|
| 190 |
+
],
|
| 191 |
+
],
|
| 192 |
+
example_labels=[
|
| 193 |
+
"Explain quantum computing",
|
| 194 |
+
"What is OpenShift?",
|
| 195 |
+
"Importance of low latency inference",
|
| 196 |
+
"Boosting productivity habits",
|
| 197 |
+
"Explain and document your code",
|
| 198 |
+
"Generate Java Code",
|
| 199 |
+
],
|
| 200 |
+
cache_examples=False,
|
| 201 |
+
type="messages",
|
| 202 |
+
additional_inputs=[
|
| 203 |
+
temperature_slider,
|
| 204 |
+
repetition_penalty_slider,
|
| 205 |
+
top_p_slider,
|
| 206 |
+
top_k_slider,
|
| 207 |
+
max_new_tokens_slider,
|
| 208 |
+
],
|
| 209 |
+
additional_inputs_accordion=chat_interface_accordion,
|
| 210 |
+
)
|
| 211 |
+
|
| 212 |
+
if __name__ == "__main__":
|
| 213 |
+
demo.queue().launch()
|
src/app_head.html
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<link
|
| 2 |
+
rel="stylesheet"
|
| 3 |
+
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"
|
| 4 |
+
/>
|
| 5 |
+
<script
|
| 6 |
+
async
|
| 7 |
+
src="https://www.googletagmanager.com/gtag/js?id=G-C6LFT227RC"
|
| 8 |
+
></script>
|
| 9 |
+
<script>
|
| 10 |
+
window.dataLayer = window.dataLayer || [];
|
| 11 |
+
function gtag() {
|
| 12 |
+
dataLayer.push(arguments);
|
| 13 |
+
}
|
| 14 |
+
gtag("js", new Date());
|
| 15 |
+
gtag("config", "G-C6LFT227RC");
|
| 16 |
+
</script>
|
src/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 |
+
)
|
src/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 |
+
)
|
uv.lock
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|