bugaku commited on
Commit
e34fd28
Β·
verified Β·
1 Parent(s): 2cb666f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -18
app.py CHANGED
@@ -8,29 +8,43 @@ from transformers import AutoModelForCausalLM, AutoTokenizer, AutoConfig
8
  import torch
9
 
10
  # ──────────────────────────────────────────────
11
- MODEL_REPO = "bugaku/fufufafa"
 
 
 
12
  # ──────────────────────────────────────────────
13
 
14
- print(f"Loading model: {MODEL_REPO}")
15
- tokenizer = AutoTokenizer.from_pretrained(MODEL_REPO)
16
 
17
- config = AutoConfig.from_pretrained(MODEL_REPO)
18
- if hasattr(config, "quantization_config"):
19
- delattr(config, "quantization_config")
20
- if hasattr(config, "_pre_quantization_dtype"):
21
- delattr(config, "_pre_quantization_dtype")
22
 
23
- model = AutoModelForCausalLM.from_pretrained(
24
- MODEL_REPO,
25
- config=config,
26
- torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
27
- device_map="auto",
28
- )
29
- model.eval()
30
- print("Model loaded!")
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
- def respond(message, history, max_new_tokens, temperature):
34
  messages = [{"role": "user", "content": message}]
35
 
36
  encoded = tokenizer.apply_chat_template(
@@ -62,10 +76,11 @@ with gr.Blocks(title="Style Model") as demo:
62
  chatbot = gr.ChatInterface(
63
  fn=respond,
64
  additional_inputs=[
 
65
  gr.Slider(32, 512, value=256, step=32, label="Max response length"),
66
  gr.Slider(0.1, 2.0, value=0.8, step=0.1, label="Temperature"),
67
  ],
68
  chatbot=gr.Chatbot(height=500),
69
  )
70
 
71
- demo.launch()
 
8
  import torch
9
 
10
  # ──────────────────────────────────────────────
11
+ MODELS = {
12
+ "3B": "bugaku/igpt",
13
+ "1.5B": "bugaku/igpt-smol",
14
+ }
15
  # ──────────────────────────────────────────────
16
 
17
+ loaded_models = {}
 
18
 
19
+ def load_model(model_repo):
20
+ if model_repo in loaded_models:
21
+ return loaded_models[model_repo]
 
 
22
 
23
+ print(f"Loading model: {model_repo}")
24
+ tokenizer = AutoTokenizer.from_pretrained(model_repo)
 
 
 
 
 
 
25
 
26
+ config = AutoConfig.from_pretrained(model_repo)
27
+ if hasattr(config, "quantization_config"):
28
+ delattr(config, "quantization_config")
29
+ if hasattr(config, "_pre_quantization_dtype"):
30
+ delattr(config, "_pre_quantization_dtype")
31
+
32
+ model = AutoModelForCausalLM.from_pretrained(
33
+ model_repo,
34
+ config=config,
35
+ torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
36
+ device_map="auto",
37
+ )
38
+ model.eval()
39
+ loaded_models[model_repo] = (model, tokenizer)
40
+ print(f"Loaded: {model_repo}")
41
+ return model, tokenizer
42
+
43
+
44
+ def respond(message, history, model_choice, max_new_tokens, temperature):
45
+ model_repo = MODELS[model_choice]
46
+ model, tokenizer = load_model(model_repo)
47
 
 
48
  messages = [{"role": "user", "content": message}]
49
 
50
  encoded = tokenizer.apply_chat_template(
 
76
  chatbot = gr.ChatInterface(
77
  fn=respond,
78
  additional_inputs=[
79
+ gr.Dropdown(choices=list(MODELS.keys()), value=list(MODELS.keys())[0], label="Model"),
80
  gr.Slider(32, 512, value=256, step=32, label="Max response length"),
81
  gr.Slider(0.1, 2.0, value=0.8, step=0.1, label="Temperature"),
82
  ],
83
  chatbot=gr.Chatbot(height=500),
84
  )
85
 
86
+ demo.launch()