Create webui.py
Browse files
webui.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
def install_everything():
|
| 4 |
+
import os
|
| 5 |
+
if "COLAB_" not in "".join(os.environ.keys()):
|
| 6 |
+
os.system("pip install unsloth")
|
| 7 |
+
else:
|
| 8 |
+
# Do this only in Colab notebooks! Otherwise use pip install unsloth
|
| 9 |
+
os.system("pip install --no-deps bitsandbytes accelerate xformers==0.0.29.post3 peft trl==0.19.1 triton cut_cross_entropy unsloth_zoo")
|
| 10 |
+
os.system("pip install sentencepiece protobuf "datasets>=3.4.1,<4.0.0" "huggingface_hub>=0.34.0" hf_transfer")
|
| 11 |
+
os.system("pip install --no-deps unsloth")
|
| 12 |
+
os.system("pip install --no-deps --upgrade timm")
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def load_model():
|
| 16 |
+
from unsloth import FastModel
|
| 17 |
+
import torch
|
| 18 |
+
|
| 19 |
+
model, tokenizer = FastModel.from_pretrained(
|
| 20 |
+
model_name = "unsloth/gemma-3n-E4B-it-unsloth-bnb-4bit",
|
| 21 |
+
dtype = None, # None for auto detection
|
| 22 |
+
max_seq_length = 1024, # Choose any for long context!
|
| 23 |
+
load_in_4bit = True, # 4 bit quantization to reduce memory
|
| 24 |
+
full_finetuning = True, # [NEW!] We have full finetuning now!
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
with gr.Blocks() as demo:
|
| 28 |
+
with gr.Tab("Install"):
|
| 29 |
+
with gr.Tab("Install Dependecies"):
|
| 30 |
+
install = gr.Button("Install")
|
| 31 |
+
inatall.click(fn=install_everything, inputs=None, outputs=None)
|
| 32 |
+
with gr.Tab("Load Models"):
|
| 33 |
+
load = gr.Button("Install models")
|
| 34 |
+
load.clixk(fn=load_model, inputs=None, outputs=None)
|