Spaces:
Running on Zero
Running on Zero
Commit ·
bd03c92
1
Parent(s): 3cb64b7
Change model selection
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import spaces
|
| 2 |
import gradio as gr
|
| 3 |
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer, StoppingCriteria, StoppingCriteriaList
|
|
|
|
| 4 |
from threading import Thread
|
| 5 |
import gc
|
| 6 |
import os
|
|
@@ -32,7 +33,6 @@ MODELS = [
|
|
| 32 |
"microsoft/Phi-3-mini-4k-instruct",
|
| 33 |
"openai-community/gpt2",
|
| 34 |
"openai-community/gpt2-medium",
|
| 35 |
-
"openai-community/gpt2-large",
|
| 36 |
"EleutherAI/pythia-70m",
|
| 37 |
"EleutherAI/pythia-160m",
|
| 38 |
"EleutherAI/pythia-410m",
|
|
@@ -43,9 +43,6 @@ MODELS = [
|
|
| 43 |
"stabilityai/StableLM-Zephyr-3B",
|
| 44 |
"NousResearch/Hermes-3-Llama-3.1-8B",
|
| 45 |
"meta-llama/Llama-3.2-1B",
|
| 46 |
-
"meta-llama/Llama-3.2-3B",
|
| 47 |
-
"THUDM/glm-4-1b-flash",
|
| 48 |
-
"2Butch/MiniCPM-1B-sft-bf16",
|
| 49 |
"SupraLabs/Supra-50M-Base",
|
| 50 |
"SupraLabs/Supra-50M-Instruct",
|
| 51 |
"SupraLabs/Supra-50M-Reasoning",
|
|
@@ -56,8 +53,6 @@ MODELS = [
|
|
| 56 |
"Aravindan/awesome-gpt-2-coder",
|
| 57 |
"LiquidAI/LFM2-1.2B",
|
| 58 |
"LiquidAI/LFM2-2.6B",
|
| 59 |
-
"LiquidAI/LFM-350M",
|
| 60 |
-
"LiquidAI/LFM-700M",
|
| 61 |
"LiquidAI/LFM2.5-230M",
|
| 62 |
"LiquidAI/LFM2.5-350M",
|
| 63 |
"LiquidAI/LFM2.5-1.2B-Instruct",
|
|
@@ -106,6 +101,31 @@ class StopOnFlag(StoppingCriteria):
|
|
| 106 |
return model_manager.stop_generation
|
| 107 |
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
def get_system_stats(request: gr.Request = None):
|
| 110 |
mem = psutil.virtual_memory()
|
| 111 |
disk = psutil.disk_usage('/')
|
|
@@ -327,10 +347,11 @@ with gr.Blocks(title="SLM Model Tester") as app:
|
|
| 327 |
gr.Timer(2).tick(get_system_stats, None, stats_output)
|
| 328 |
|
| 329 |
with gr.Group():
|
| 330 |
-
|
| 331 |
-
choices=MODELS, label="Model",
|
| 332 |
-
|
| 333 |
)
|
|
|
|
| 334 |
with gr.Row():
|
| 335 |
load_btn = gr.Button("Load Model", variant="primary", scale=2)
|
| 336 |
clean_btn = gr.Button("Clear Cache", variant="stop", scale=1)
|
|
@@ -383,9 +404,15 @@ with gr.Blocks(title="SLM Model Tester") as app:
|
|
| 383 |
label="Output", lines=15, buttons=["copy"], autoscroll=True
|
| 384 |
)
|
| 385 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 386 |
load_btn.click(
|
| 387 |
fn=load_new_model,
|
| 388 |
-
inputs=[
|
| 389 |
outputs=[status_output]
|
| 390 |
)
|
| 391 |
|
|
|
|
| 1 |
import spaces
|
| 2 |
import gradio as gr
|
| 3 |
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer, StoppingCriteria, StoppingCriteriaList
|
| 4 |
+
from huggingface_hub import HfApi
|
| 5 |
from threading import Thread
|
| 6 |
import gc
|
| 7 |
import os
|
|
|
|
| 33 |
"microsoft/Phi-3-mini-4k-instruct",
|
| 34 |
"openai-community/gpt2",
|
| 35 |
"openai-community/gpt2-medium",
|
|
|
|
| 36 |
"EleutherAI/pythia-70m",
|
| 37 |
"EleutherAI/pythia-160m",
|
| 38 |
"EleutherAI/pythia-410m",
|
|
|
|
| 43 |
"stabilityai/StableLM-Zephyr-3B",
|
| 44 |
"NousResearch/Hermes-3-Llama-3.1-8B",
|
| 45 |
"meta-llama/Llama-3.2-1B",
|
|
|
|
|
|
|
|
|
|
| 46 |
"SupraLabs/Supra-50M-Base",
|
| 47 |
"SupraLabs/Supra-50M-Instruct",
|
| 48 |
"SupraLabs/Supra-50M-Reasoning",
|
|
|
|
| 53 |
"Aravindan/awesome-gpt-2-coder",
|
| 54 |
"LiquidAI/LFM2-1.2B",
|
| 55 |
"LiquidAI/LFM2-2.6B",
|
|
|
|
|
|
|
| 56 |
"LiquidAI/LFM2.5-230M",
|
| 57 |
"LiquidAI/LFM2.5-350M",
|
| 58 |
"LiquidAI/LFM2.5-1.2B-Instruct",
|
|
|
|
| 101 |
return model_manager.stop_generation
|
| 102 |
|
| 103 |
|
| 104 |
+
_search_cache = {}
|
| 105 |
+
_last_search_time = 0
|
| 106 |
+
|
| 107 |
+
def search_hf_models(query):
|
| 108 |
+
global _last_search_time
|
| 109 |
+
import time as _time
|
| 110 |
+
_last_search_time = _time.time()
|
| 111 |
+
|
| 112 |
+
if not query or len(query) < 2:
|
| 113 |
+
return gr.update(choices=MODELS)
|
| 114 |
+
q = query.strip().lower()
|
| 115 |
+
if q in _search_cache:
|
| 116 |
+
return gr.update(choices=_search_cache[q])
|
| 117 |
+
try:
|
| 118 |
+
api = HfApi()
|
| 119 |
+
models = list(api.list_models(search=query, limit=15, sort="downloads"))
|
| 120 |
+
model_ids = [m.id for m in models if m.id]
|
| 121 |
+
if model_ids:
|
| 122 |
+
_search_cache[q] = model_ids
|
| 123 |
+
return gr.update(choices=model_ids)
|
| 124 |
+
return gr.update(choices=MODELS)
|
| 125 |
+
except Exception:
|
| 126 |
+
return gr.update(choices=MODELS)
|
| 127 |
+
|
| 128 |
+
|
| 129 |
def get_system_stats(request: gr.Request = None):
|
| 130 |
mem = psutil.virtual_memory()
|
| 131 |
disk = psutil.disk_usage('/')
|
|
|
|
| 347 |
gr.Timer(2).tick(get_system_stats, None, stats_output)
|
| 348 |
|
| 349 |
with gr.Group():
|
| 350 |
+
model_input = gr.Dropdown(
|
| 351 |
+
choices=MODELS, label="Model", value=DEFAULT_MODEL,
|
| 352 |
+
allow_custom_value=True,
|
| 353 |
)
|
| 354 |
+
search_btn = gr.Button("Search HuggingFace", variant="secondary")
|
| 355 |
with gr.Row():
|
| 356 |
load_btn = gr.Button("Load Model", variant="primary", scale=2)
|
| 357 |
clean_btn = gr.Button("Clear Cache", variant="stop", scale=1)
|
|
|
|
| 404 |
label="Output", lines=15, buttons=["copy"], autoscroll=True
|
| 405 |
)
|
| 406 |
|
| 407 |
+
search_btn.click(
|
| 408 |
+
fn=search_hf_models,
|
| 409 |
+
inputs=[model_input],
|
| 410 |
+
outputs=[model_input],
|
| 411 |
+
)
|
| 412 |
+
|
| 413 |
load_btn.click(
|
| 414 |
fn=load_new_model,
|
| 415 |
+
inputs=[model_input],
|
| 416 |
outputs=[status_output]
|
| 417 |
)
|
| 418 |
|