Gemma3N / webui.py
R-Kentaren's picture
Create webui.py
9eb7c70 verified
import gradio as gr
def install_everything():
import os
if "COLAB_" not in "".join(os.environ.keys()):
os.system("pip install unsloth")
else:
# Do this only in Colab notebooks! Otherwise use pip install unsloth
os.system("pip install --no-deps bitsandbytes accelerate xformers==0.0.29.post3 peft trl==0.19.1 triton cut_cross_entropy unsloth_zoo")
os.system("pip install sentencepiece protobuf "datasets>=3.4.1,<4.0.0" "huggingface_hub>=0.34.0" hf_transfer")
os.system("pip install --no-deps unsloth")
os.system("pip install --no-deps --upgrade timm")
def load_model():
from unsloth import FastModel
import torch
model, tokenizer = FastModel.from_pretrained(
model_name = "unsloth/gemma-3n-E4B-it-unsloth-bnb-4bit",
dtype = None, # None for auto detection
max_seq_length = 1024, # Choose any for long context!
load_in_4bit = True, # 4 bit quantization to reduce memory
full_finetuning = True, # [NEW!] We have full finetuning now!
)
with gr.Blocks() as demo:
with gr.Tab("Install"):
with gr.Tab("Install Dependecies"):
install = gr.Button("Install")
inatall.click(fn=install_everything, inputs=None, outputs=None)
with gr.Tab("Load Models"):
load = gr.Button("Install models")
load.clixk(fn=load_model, inputs=None, outputs=None)