Spaces:
Running
on
A10G
Running
on
A10G
MekkCyber
commited on
Commit
·
9be6f61
1
Parent(s):
749044f
update
Browse files- .gradio/certificate.pem +31 -0
- app.py +38 -31
- requirements.txt +2 -3
.gradio/certificate.pem
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
-----BEGIN CERTIFICATE-----
|
| 2 |
+
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
|
| 3 |
+
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
|
| 4 |
+
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4
|
| 5 |
+
WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu
|
| 6 |
+
ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY
|
| 7 |
+
MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc
|
| 8 |
+
h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+
|
| 9 |
+
0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U
|
| 10 |
+
A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW
|
| 11 |
+
T8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VyyghqpZXjFaH3pO3JLF+l+/+sKAIuvtd7u+Nxe5AW0wdeRlN8NwdC
|
| 26 |
+
jNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc
|
| 27 |
+
oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq
|
| 28 |
+
4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA
|
| 29 |
+
mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d
|
| 30 |
+
emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=
|
| 31 |
+
-----END CERTIFICATE-----
|
app.py
CHANGED
|
@@ -7,7 +7,6 @@ from huggingface_hub import list_models
|
|
| 7 |
from gradio_huggingfacehub_search import HuggingfaceHubSearch
|
| 8 |
from packaging import version
|
| 9 |
import os
|
| 10 |
-
import spaces
|
| 11 |
|
| 12 |
|
| 13 |
def hello(profile: gr.OAuthProfile | None, oauth_token: gr.OAuthToken | None) -> str:
|
|
@@ -62,10 +61,7 @@ model = AutoModel.from_pretrained("{model_name}")"""
|
|
| 62 |
return model_card
|
| 63 |
|
| 64 |
def load_model(model_name, quantization_config, auth_token) :
|
| 65 |
-
return AutoModel.from_pretrained(model_name, quantization_config=quantization_config, device_map="
|
| 66 |
-
|
| 67 |
-
def load_model_cpu(model_name, quantization_config, auth_token) :
|
| 68 |
-
return AutoModel.from_pretrained(model_name, quantization_config=quantization_config, use_auth_token=auth_token.token)
|
| 69 |
|
| 70 |
def quantize_model(model_name, quantization_type, threshold, quant_type_4, double_quant_4, auth_token=None, username=None):
|
| 71 |
print(f"Quantizing model: {quantization_type}")
|
|
@@ -89,14 +85,12 @@ def save_model(model, model_name, quantization_type, threshold, quant_type_4, do
|
|
| 89 |
with tempfile.TemporaryDirectory() as tmpdirname:
|
| 90 |
|
| 91 |
|
| 92 |
-
model.save_pretrained(tmpdirname, safe_serialization=
|
| 93 |
if quantized_model_name :
|
| 94 |
repo_name = f"{username}/{quantized_model_name}"
|
| 95 |
-
else :
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
else :
|
| 99 |
-
repo_name = f"{username}/{model_name.split('/')[-1]}-BNB-{quantization_type}"
|
| 100 |
|
| 101 |
model_card = create_model_card(repo_name, quantization_type, threshold, quant_type_4, double_quant_4)
|
| 102 |
with open(os.path.join(tmpdirname, "README.md"), "w") as f:
|
|
@@ -132,17 +126,18 @@ def quantize_and_save(profile: gr.OAuthProfile | None, oauth_token: gr.OAuthToke
|
|
| 132 |
|
| 133 |
threshold = float(threshold)
|
| 134 |
|
| 135 |
-
try:
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
except Exception as e :
|
| 139 |
-
|
|
|
|
| 140 |
|
| 141 |
|
| 142 |
css="""/* Custom CSS to allow scrolling */
|
| 143 |
.gradio-container {overflow-y: auto;}
|
| 144 |
"""
|
| 145 |
-
with gr.Blocks(theme=gr.themes.Ocean(), css=css) as
|
| 146 |
gr.Markdown(
|
| 147 |
"""
|
| 148 |
# 🤗 LLM Model BitsAndBytes Quantization App
|
|
@@ -154,10 +149,10 @@ with gr.Blocks(theme=gr.themes.Ocean(), css=css) as app:
|
|
| 154 |
gr.LoginButton(elem_id="login-button", elem_classes="center-button", min_width=250)
|
| 155 |
|
| 156 |
m1 = gr.Markdown()
|
| 157 |
-
|
| 158 |
|
| 159 |
|
| 160 |
-
radio = gr.Radio(["show", "hide"], label="Show Instructions")
|
| 161 |
instructions = gr.Markdown(
|
| 162 |
"""
|
| 163 |
## Instructions
|
|
@@ -174,13 +169,24 @@ with gr.Blocks(theme=gr.themes.Ocean(), css=css) as app:
|
|
| 174 |
""",
|
| 175 |
visible=False
|
| 176 |
)
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
|
| 185 |
with gr.Row():
|
| 186 |
with gr.Column():
|
|
@@ -228,18 +234,18 @@ with gr.Blocks(theme=gr.themes.Ocean(), css=css) as app:
|
|
| 228 |
)
|
| 229 |
with gr.Column():
|
| 230 |
quantize_button = gr.Button("Quantize and Save Model", variant="primary")
|
| 231 |
-
output_link = gr.Markdown(label="Quantized Model Link", container=True, min_height=
|
| 232 |
|
| 233 |
|
| 234 |
# Adding CSS styles for the username box
|
| 235 |
-
|
| 236 |
#username-box {
|
| 237 |
background-color: #f0f8ff; /* Light color */
|
| 238 |
border-radius: 8px;
|
| 239 |
padding: 10px;
|
| 240 |
}
|
| 241 |
"""
|
| 242 |
-
|
| 243 |
.center-button {
|
| 244 |
display: flex;
|
| 245 |
justify-content: center;
|
|
@@ -254,6 +260,7 @@ with gr.Blocks(theme=gr.themes.Ocean(), css=css) as app:
|
|
| 254 |
outputs=[output_link]
|
| 255 |
)
|
| 256 |
|
| 257 |
-
|
|
|
|
| 258 |
# Launch the app
|
| 259 |
-
|
|
|
|
| 7 |
from gradio_huggingfacehub_search import HuggingfaceHubSearch
|
| 8 |
from packaging import version
|
| 9 |
import os
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
def hello(profile: gr.OAuthProfile | None, oauth_token: gr.OAuthToken | None) -> str:
|
|
|
|
| 61 |
return model_card
|
| 62 |
|
| 63 |
def load_model(model_name, quantization_config, auth_token) :
|
| 64 |
+
return AutoModel.from_pretrained(model_name, quantization_config=quantization_config, device_map="cpu", use_auth_token=auth_token.token)
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
def quantize_model(model_name, quantization_type, threshold, quant_type_4, double_quant_4, auth_token=None, username=None):
|
| 67 |
print(f"Quantizing model: {quantization_type}")
|
|
|
|
| 85 |
with tempfile.TemporaryDirectory() as tmpdirname:
|
| 86 |
|
| 87 |
|
| 88 |
+
model.save_pretrained(tmpdirname, safe_serialization=True, use_auth_token=auth_token.token)
|
| 89 |
if quantized_model_name :
|
| 90 |
repo_name = f"{username}/{quantized_model_name}"
|
| 91 |
+
else :
|
| 92 |
+
repo_name = f"{username}/{model_name.split('/')[-1]}-BNB-{quantization_type}"
|
| 93 |
+
|
|
|
|
|
|
|
| 94 |
|
| 95 |
model_card = create_model_card(repo_name, quantization_type, threshold, quant_type_4, double_quant_4)
|
| 96 |
with open(os.path.join(tmpdirname, "README.md"), "w") as f:
|
|
|
|
| 126 |
|
| 127 |
threshold = float(threshold)
|
| 128 |
|
| 129 |
+
# try:
|
| 130 |
+
quantized_model = quantize_model(model_name, quantization_type, threshold, quant_type_4, double_quant_4, oauth_token, profile.username)
|
| 131 |
+
return save_model(quantized_model, model_name, quantization_type, threshold, quant_type_4, double_quant_4, profile.username, oauth_token, quantized_model_name)
|
| 132 |
+
# except Exception as e :
|
| 133 |
+
# print(e)
|
| 134 |
+
# return f"An error occurred: {str(e)}"
|
| 135 |
|
| 136 |
|
| 137 |
css="""/* Custom CSS to allow scrolling */
|
| 138 |
.gradio-container {overflow-y: auto;}
|
| 139 |
"""
|
| 140 |
+
with gr.Blocks(theme=gr.themes.Ocean(), css=css) as demo:
|
| 141 |
gr.Markdown(
|
| 142 |
"""
|
| 143 |
# 🤗 LLM Model BitsAndBytes Quantization App
|
|
|
|
| 149 |
gr.LoginButton(elem_id="login-button", elem_classes="center-button", min_width=250)
|
| 150 |
|
| 151 |
m1 = gr.Markdown()
|
| 152 |
+
demo.load(hello, inputs=None, outputs=m1)
|
| 153 |
|
| 154 |
|
| 155 |
+
# radio = gr.Radio(["show", "hide"], label="Show Instructions")
|
| 156 |
instructions = gr.Markdown(
|
| 157 |
"""
|
| 158 |
## Instructions
|
|
|
|
| 169 |
""",
|
| 170 |
visible=False
|
| 171 |
)
|
| 172 |
+
|
| 173 |
+
instructions_visible = gr.State(False)
|
| 174 |
+
toggle_button = gr.Button("▼ Show Instructions", elem_id="toggle-button", elem_classes="toggle-button")
|
| 175 |
+
|
| 176 |
+
def toggle_instructions(instructions_visible):
|
| 177 |
+
new_visibility = not instructions_visible # Toggle the state
|
| 178 |
+
new_label = "▲ Hide Instructions" if new_visibility else "▼ Show Instructions" # Change label based on visibility
|
| 179 |
+
return gr.update(visible=new_visibility), new_visibility, gr.update(value=new_label) # Toggle visibility and return new state
|
| 180 |
+
|
| 181 |
+
toggle_button.click(toggle_instructions, instructions_visible, [instructions, instructions_visible, toggle_button])
|
| 182 |
+
|
| 183 |
+
# def update_visibility(radio): # Accept the event argument, even if not used
|
| 184 |
+
# value = radio # Get the selected value from the radio button
|
| 185 |
+
# if value == "show":
|
| 186 |
+
# return gr.Textbox(visible=True) #make it visible
|
| 187 |
+
# else:
|
| 188 |
+
# return gr.Textbox(visible=False)
|
| 189 |
+
# radio.change(update_visibility, radio, instructions)
|
| 190 |
|
| 191 |
with gr.Row():
|
| 192 |
with gr.Column():
|
|
|
|
| 234 |
)
|
| 235 |
with gr.Column():
|
| 236 |
quantize_button = gr.Button("Quantize and Save Model", variant="primary")
|
| 237 |
+
output_link = gr.Markdown(label="Quantized Model Link", container=True, min_height=80)
|
| 238 |
|
| 239 |
|
| 240 |
# Adding CSS styles for the username box
|
| 241 |
+
demo.css = """
|
| 242 |
#username-box {
|
| 243 |
background-color: #f0f8ff; /* Light color */
|
| 244 |
border-radius: 8px;
|
| 245 |
padding: 10px;
|
| 246 |
}
|
| 247 |
"""
|
| 248 |
+
demo.css = """
|
| 249 |
.center-button {
|
| 250 |
display: flex;
|
| 251 |
justify-content: center;
|
|
|
|
| 260 |
outputs=[output_link]
|
| 261 |
)
|
| 262 |
|
| 263 |
+
if __name__ == "__main__":
|
| 264 |
+
demo.launch(share=True)
|
| 265 |
# Launch the app
|
| 266 |
+
# demo.launch(share=True, debug=True)
|
requirements.txt
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
-
|
| 2 |
accelerate
|
| 3 |
-
torchao
|
| 4 |
huggingface-hub
|
| 5 |
gradio-huggingfacehub-search
|
| 6 |
-
bitsandbytes
|
|
|
|
| 1 |
+
transformers
|
| 2 |
accelerate
|
|
|
|
| 3 |
huggingface-hub
|
| 4 |
gradio-huggingfacehub-search
|
| 5 |
+
https://github.com/bitsandbytes-foundation/bitsandbytes/releases/download/continuous-release_multi-backend-refactor/bitsandbytes-0.44.1.dev0-py3-none-manylinux_2_24_x86_64.whl
|