Spaces:
Running
Running
fix: add missing custom_model_metadata state variable and update get_model_info to handle custom models
Browse files
app.py
CHANGED
|
@@ -901,16 +901,56 @@ def calculate_effective_max_tokens(model_key: str, max_tokens: int, enable_reaso
|
|
| 901 |
return max_tokens
|
| 902 |
|
| 903 |
|
| 904 |
-
def get_model_info(model_key: str, n_threads: int = 2) -> Tuple[str, str, float, int]:
|
| 905 |
"""Get model information and inference settings for UI display.
|
| 906 |
|
| 907 |
Args:
|
| 908 |
model_key: Model identifier from AVAILABLE_MODELS
|
| 909 |
n_threads: Number of CPU threads currently configured
|
|
|
|
| 910 |
|
| 911 |
Returns:
|
| 912 |
Tuple of (info_text, temperature, top_p, top_k)
|
| 913 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 914 |
m = AVAILABLE_MODELS[model_key]
|
| 915 |
usable_ctx = min(m["max_context"], MAX_USABLE_CTX)
|
| 916 |
settings = m["inference_settings"]
|
|
@@ -1654,6 +1694,13 @@ def create_interface():
|
|
| 1654 |
|
| 1655 |
# Hidden state to store loaded custom model
|
| 1656 |
custom_model_state = gr.State(value=None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1657 |
|
| 1658 |
# Model info section (dynamic)
|
| 1659 |
with gr.Group():
|
|
@@ -1708,7 +1755,7 @@ def create_interface():
|
|
| 1708 |
)
|
| 1709 |
|
| 1710 |
# Function to update settings when model changes
|
| 1711 |
-
def update_settings_on_model_change(model_key, thread_config, custom_threads):
|
| 1712 |
"""Update all Advanced Settings when model selection changes."""
|
| 1713 |
# Calculate n_threads based on preset
|
| 1714 |
thread_preset_map = {
|
|
@@ -1718,7 +1765,7 @@ def create_interface():
|
|
| 1718 |
}
|
| 1719 |
n_threads = thread_preset_map.get(thread_config, 2)
|
| 1720 |
|
| 1721 |
-
info_text, temp_str, top_p_val, top_k_val = get_model_info(model_key, n_threads=n_threads)
|
| 1722 |
temperature = float(temp_str) if temp_str else 0.6
|
| 1723 |
return temperature, top_p_val, top_k_val, info_text
|
| 1724 |
|
|
|
|
| 901 |
return max_tokens
|
| 902 |
|
| 903 |
|
| 904 |
+
def get_model_info(model_key: str, n_threads: int = 2, custom_metadata: Optional[dict] = None) -> Tuple[str, str, float, int]:
|
| 905 |
"""Get model information and inference settings for UI display.
|
| 906 |
|
| 907 |
Args:
|
| 908 |
model_key: Model identifier from AVAILABLE_MODELS
|
| 909 |
n_threads: Number of CPU threads currently configured
|
| 910 |
+
custom_metadata: Optional metadata for custom models (repo_id, filename, size_mb)
|
| 911 |
|
| 912 |
Returns:
|
| 913 |
Tuple of (info_text, temperature, top_p, top_k)
|
| 914 |
"""
|
| 915 |
+
# Handle custom model case
|
| 916 |
+
if model_key == "custom_hf" and custom_metadata:
|
| 917 |
+
repo_id = custom_metadata.get("repo_id", "Unknown")
|
| 918 |
+
filename = custom_metadata.get("filename", "Unknown")
|
| 919 |
+
size_mb = custom_metadata.get("size_mb", 0)
|
| 920 |
+
size_str = f"{size_mb:.1f} MB" if size_mb > 0 else "Unknown"
|
| 921 |
+
|
| 922 |
+
# Determine thread preset label
|
| 923 |
+
if n_threads == 2:
|
| 924 |
+
thread_label = "HF Free Tier"
|
| 925 |
+
elif n_threads == 8:
|
| 926 |
+
thread_label = "HF Upgrade Tier"
|
| 927 |
+
else:
|
| 928 |
+
thread_label = "Custom"
|
| 929 |
+
|
| 930 |
+
info_text = (
|
| 931 |
+
f"## 🤖 Custom GGUF Model\n\n"
|
| 932 |
+
f"### 📊 Model Specs\n"
|
| 933 |
+
f"| Property | Value |\n"
|
| 934 |
+
f"|----------|-------|\n"
|
| 935 |
+
f"| **Repository** | `{repo_id}` |\n"
|
| 936 |
+
f"| **Quantization** | `{filename}` |\n"
|
| 937 |
+
f"| **Size** | {size_str} |\n"
|
| 938 |
+
f"| **Context** | Dynamic (up to 32K) |\n\n"
|
| 939 |
+
f"### 🖥️ Hardware Configuration\n"
|
| 940 |
+
f"| Property | Value |\n"
|
| 941 |
+
f"|----------|-------|\n"
|
| 942 |
+
f"| **CPU Threads** | {n_threads} ({thread_label}) |\n\n"
|
| 943 |
+
f"### ⚙️ Inference Settings\n"
|
| 944 |
+
f"| Property | Value |\n"
|
| 945 |
+
f"|----------|-------|\n"
|
| 946 |
+
f"| **Temperature** | 0.6 |\n"
|
| 947 |
+
f"| **Top P** | 0.9 |\n"
|
| 948 |
+
f"| **Top K** | 40 |\n"
|
| 949 |
+
f"| **Repeat Penalty** | 1.0 |"
|
| 950 |
+
)
|
| 951 |
+
return info_text, "0.6", 0.9, 40
|
| 952 |
+
|
| 953 |
+
# Handle predefined models
|
| 954 |
m = AVAILABLE_MODELS[model_key]
|
| 955 |
usable_ctx = min(m["max_context"], MAX_USABLE_CTX)
|
| 956 |
settings = m["inference_settings"]
|
|
|
|
| 1694 |
|
| 1695 |
# Hidden state to store loaded custom model
|
| 1696 |
custom_model_state = gr.State(value=None)
|
| 1697 |
+
|
| 1698 |
+
# Hidden state to store custom model metadata (repo_id, filename, size)
|
| 1699 |
+
custom_model_metadata = gr.State(value={
|
| 1700 |
+
"repo_id": None,
|
| 1701 |
+
"filename": None,
|
| 1702 |
+
"size_mb": 0,
|
| 1703 |
+
})
|
| 1704 |
|
| 1705 |
# Model info section (dynamic)
|
| 1706 |
with gr.Group():
|
|
|
|
| 1755 |
)
|
| 1756 |
|
| 1757 |
# Function to update settings when model changes
|
| 1758 |
+
def update_settings_on_model_change(model_key, thread_config, custom_threads, custom_metadata=None):
|
| 1759 |
"""Update all Advanced Settings when model selection changes."""
|
| 1760 |
# Calculate n_threads based on preset
|
| 1761 |
thread_preset_map = {
|
|
|
|
| 1765 |
}
|
| 1766 |
n_threads = thread_preset_map.get(thread_config, 2)
|
| 1767 |
|
| 1768 |
+
info_text, temp_str, top_p_val, top_k_val = get_model_info(model_key, n_threads=n_threads, custom_metadata=custom_metadata)
|
| 1769 |
temperature = float(temp_str) if temp_str else 0.6
|
| 1770 |
return temperature, top_p_val, top_k_val, info_text
|
| 1771 |
|