Upload folder using huggingface_hub
Browse files- README.md +24 -6
- __pycache__/app.cpython-314.pyc +0 -0
- app.py +238 -0
- requirements.txt +2 -0
README.md
CHANGED
|
@@ -1,10 +1,28 @@
|
|
| 1 |
---
|
| 2 |
-
title: Huihui Qwen3.8 27B Abliterated GGUF
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
-
sdk:
|
|
|
|
|
|
|
|
|
|
| 7 |
pinned: false
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Huihui Qwen3.8 27B Abliterated GGUF
|
| 3 |
+
emoji: ⚡
|
| 4 |
+
colorFrom: indigo
|
| 5 |
+
colorTo: purple
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 6.25.0
|
| 8 |
+
python_version: '3.12'
|
| 9 |
+
app_file: app.py
|
| 10 |
pinned: false
|
| 11 |
+
short_description: Chat demo for Huihui Qwen3.8 27B Abliterated GGUF
|
| 12 |
---
|
| 13 |
|
| 14 |
+
# Huihui Qwen3.8 27B Abliterated (GGUF) Demo
|
| 15 |
+
|
| 16 |
+
Conversational chat demo running [**huihui-ai/Huihui-Qwen3.8-27B-abliterated-GGUF**](https://huggingface.co/huihui-ai/Huihui-Qwen3.8-27B-abliterated-GGUF) using `llama.cpp` on Hugging Face ZeroGPU.
|
| 17 |
+
|
| 18 |
+
## Features
|
| 19 |
+
|
| 20 |
+
- **Fast Inference**: Uses GGUF quantization with GPU offloading via `llama-cpp-python`.
|
| 21 |
+
- **ZeroGPU Acceleration**: Dynamic GPU allocation on NVIDIA GPUs.
|
| 22 |
+
- **Streaming Responses**: Real-time response streaming into a modern bubble chatbot UI.
|
| 23 |
+
- **Configurable Generation**: Customizable system prompt, temperature, top-p, top-k, repetition penalty, and max tokens.
|
| 24 |
+
- **MCP Server Ready**: Built-in Model Context Protocol server support (`mcp_server=True`).
|
| 25 |
+
|
| 26 |
+
## Notice
|
| 27 |
+
|
| 28 |
+
This model has significantly reduced safety refusal filtering. It may generate sensitive or uncensored content. You are responsible for adhering to applicable laws and policies.
|
__pycache__/app.cpython-314.pyc
ADDED
|
Binary file (10.9 kB). View file
|
|
|
app.py
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gc
|
| 3 |
+
from typing import Iterator
|
| 4 |
+
|
| 5 |
+
# If running in environment without spaces, provide a no-op fallback for spaces.GPU
|
| 6 |
+
try:
|
| 7 |
+
import spaces
|
| 8 |
+
except ImportError:
|
| 9 |
+
class spaces:
|
| 10 |
+
@staticmethod
|
| 11 |
+
def GPU(func=None, duration=None, size=None):
|
| 12 |
+
if func is None:
|
| 13 |
+
return lambda f: f
|
| 14 |
+
return func
|
| 15 |
+
|
| 16 |
+
import gradio as gr
|
| 17 |
+
from huggingface_hub import hf_hub_download
|
| 18 |
+
|
| 19 |
+
MODEL_REPO = "huihui-ai/Huihui-Qwen3.8-27B-abliterated-GGUF"
|
| 20 |
+
# Default to UD-IQ4_XS which provides great balance of speed & quality
|
| 21 |
+
MODEL_FILE = "Huihui-Qwen3.8-27B-abliterated-UD-IQ4_XS.gguf"
|
| 22 |
+
|
| 23 |
+
print(f"Ensuring model {MODEL_FILE} is available...", flush=True)
|
| 24 |
+
MODEL_PATH = hf_hub_download(
|
| 25 |
+
repo_id=MODEL_REPO,
|
| 26 |
+
filename=MODEL_FILE,
|
| 27 |
+
)
|
| 28 |
+
print(f"Model ready at: {MODEL_PATH}", flush=True)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def estimate_duration(
|
| 32 |
+
history: list[dict[str, str]],
|
| 33 |
+
system_prompt: str,
|
| 34 |
+
temperature: float,
|
| 35 |
+
top_p: float,
|
| 36 |
+
top_k: int,
|
| 37 |
+
max_tokens: int,
|
| 38 |
+
repeat_penalty: float,
|
| 39 |
+
*args,
|
| 40 |
+
**kwargs,
|
| 41 |
+
) -> int:
|
| 42 |
+
"""Reserve a realistic ZeroGPU execution window based on requested max tokens."""
|
| 43 |
+
tokens = int(max_tokens) if max_tokens else 512
|
| 44 |
+
return min(180, max(30, int(tokens / 15) + 25))
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def add_user_message(
|
| 48 |
+
message: str,
|
| 49 |
+
history: list[dict[str, str]],
|
| 50 |
+
) -> tuple[str, list[dict[str, str]]]:
|
| 51 |
+
"""Appends user message to chat history and clears input box."""
|
| 52 |
+
if not message.strip():
|
| 53 |
+
return "", history
|
| 54 |
+
return "", history + [{"role": "user", "content": message.strip()}]
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
@spaces.GPU(duration=estimate_duration)
|
| 58 |
+
def bot_response(
|
| 59 |
+
history: list[dict[str, str]],
|
| 60 |
+
system_prompt: str,
|
| 61 |
+
temperature: float,
|
| 62 |
+
top_p: float,
|
| 63 |
+
top_k: int,
|
| 64 |
+
max_tokens: int,
|
| 65 |
+
repeat_penalty: float,
|
| 66 |
+
) -> Iterator[list[dict[str, str]]]:
|
| 67 |
+
"""Streams the assistant's reply for the current conversation history.
|
| 68 |
+
|
| 69 |
+
Args:
|
| 70 |
+
history: Current conversation history including user's latest query.
|
| 71 |
+
system_prompt: System prompt defining assistant persona.
|
| 72 |
+
temperature: Sampling temperature (higher = more creative).
|
| 73 |
+
top_p: Nucleus sampling probability cutoff.
|
| 74 |
+
top_k: Top-K tokens to sample from.
|
| 75 |
+
max_tokens: Maximum new tokens to generate.
|
| 76 |
+
repeat_penalty: Penalty factor applied to repeated tokens.
|
| 77 |
+
"""
|
| 78 |
+
if not history or history[-1].get("role") != "user":
|
| 79 |
+
yield history
|
| 80 |
+
return
|
| 81 |
+
|
| 82 |
+
# Import llama_cpp inside the ZeroGPU worker so CUDA initializes in the GPU context
|
| 83 |
+
from llama_cpp import Llama
|
| 84 |
+
|
| 85 |
+
user_query = history[-1]["content"]
|
| 86 |
+
prior_history = history[:-1]
|
| 87 |
+
|
| 88 |
+
# Build chat messages sequence
|
| 89 |
+
messages = []
|
| 90 |
+
if system_prompt and system_prompt.strip():
|
| 91 |
+
messages.append({"role": "system", "content": system_prompt.strip()})
|
| 92 |
+
|
| 93 |
+
for item in prior_history[-10:]:
|
| 94 |
+
if isinstance(item, dict) and "role" in item and "content" in item:
|
| 95 |
+
if item["content"]:
|
| 96 |
+
messages.append({"role": item["role"], "content": item["content"]})
|
| 97 |
+
|
| 98 |
+
messages.append({"role": "user", "content": user_query})
|
| 99 |
+
|
| 100 |
+
# Prepare chat history with empty assistant bubble
|
| 101 |
+
active_history = history + [{"role": "assistant", "content": ""}]
|
| 102 |
+
yield active_history
|
| 103 |
+
|
| 104 |
+
print("Initializing llama.cpp model on GPU...", flush=True)
|
| 105 |
+
llm = Llama(
|
| 106 |
+
model_path=MODEL_PATH,
|
| 107 |
+
n_gpu_layers=-1,
|
| 108 |
+
n_ctx=8192,
|
| 109 |
+
n_batch=512,
|
| 110 |
+
flash_attn=True,
|
| 111 |
+
use_mmap=True,
|
| 112 |
+
verbose=False,
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
try:
|
| 116 |
+
response_stream = llm.create_chat_completion(
|
| 117 |
+
messages=messages,
|
| 118 |
+
max_tokens=int(max_tokens),
|
| 119 |
+
temperature=float(temperature),
|
| 120 |
+
top_p=float(top_p),
|
| 121 |
+
top_k=int(top_k),
|
| 122 |
+
repeat_penalty=float(repeat_penalty),
|
| 123 |
+
stream=True,
|
| 124 |
+
)
|
| 125 |
+
|
| 126 |
+
for chunk in response_stream:
|
| 127 |
+
delta = chunk.get("choices", [{}])[0].get("delta", {})
|
| 128 |
+
token = delta.get("content", "")
|
| 129 |
+
if token:
|
| 130 |
+
active_history[-1]["content"] += token
|
| 131 |
+
yield active_history
|
| 132 |
+
|
| 133 |
+
finally:
|
| 134 |
+
del llm
|
| 135 |
+
gc.collect()
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
CSS = """
|
| 139 |
+
#col-container { max-width: 1000px; margin: 0 auto; }
|
| 140 |
+
.dark .gradio-container { color: var(--body-text-color); }
|
| 141 |
+
"""
|
| 142 |
+
|
| 143 |
+
with gr.Blocks(theme=gr.themes.Citrus(), css=CSS) as demo:
|
| 144 |
+
with gr.Column(elem_id="col-container"):
|
| 145 |
+
gr.Markdown(
|
| 146 |
+
"# ⚡ Huihui Qwen3.8 27B Abliterated (GGUF)\n\n"
|
| 147 |
+
"Fast conversational chat demo for "
|
| 148 |
+
"[**huihui-ai/Huihui-Qwen3.8-27B-abliterated-GGUF**](https://huggingface.co/huihui-ai/Huihui-Qwen3.8-27B-abliterated-GGUF) "
|
| 149 |
+
"powered by **llama.cpp** on Hugging Face **ZeroGPU**.\n\n"
|
| 150 |
+
"> ⚠️ **Model Notice**: This is an uncensored / abliterated variant with reduced safety refusal filters. "
|
| 151 |
+
"Outputs may contain sensitive or unfiltered responses. Use responsibly."
|
| 152 |
+
)
|
| 153 |
+
|
| 154 |
+
chatbot = gr.Chatbot(
|
| 155 |
+
type="messages",
|
| 156 |
+
height=540,
|
| 157 |
+
layout="bubble",
|
| 158 |
+
show_copy_button=True,
|
| 159 |
+
)
|
| 160 |
+
|
| 161 |
+
with gr.Row():
|
| 162 |
+
message = gr.Textbox(
|
| 163 |
+
placeholder="Ask anything or enter a prompt...",
|
| 164 |
+
show_label=False,
|
| 165 |
+
container=False,
|
| 166 |
+
scale=5,
|
| 167 |
+
autofocus=True,
|
| 168 |
+
)
|
| 169 |
+
send = gr.Button("Send", variant="primary", scale=1)
|
| 170 |
+
|
| 171 |
+
with gr.Accordion("⚙️ Parameters & System Prompt", open=False):
|
| 172 |
+
system_prompt = gr.Textbox(
|
| 173 |
+
label="System Prompt",
|
| 174 |
+
value="You are a helpful, precise, and honest AI assistant.",
|
| 175 |
+
lines=2,
|
| 176 |
+
)
|
| 177 |
+
with gr.Row():
|
| 178 |
+
temperature = gr.Slider(0.0, 1.5, value=0.7, step=0.05, label="Temperature")
|
| 179 |
+
top_p = gr.Slider(0.1, 1.0, value=0.9, step=0.05, label="Top-P")
|
| 180 |
+
top_k = gr.Slider(1, 100, value=40, step=1, label="Top-K")
|
| 181 |
+
with gr.Row():
|
| 182 |
+
max_tokens = gr.Slider(64, 2048, value=512, step=64, label="Max Tokens")
|
| 183 |
+
repeat_penalty = gr.Slider(1.0, 1.5, value=1.1, step=0.05, label="Repetition Penalty")
|
| 184 |
+
|
| 185 |
+
with gr.Row():
|
| 186 |
+
clear = gr.ClearButton([message, chatbot], value="🗑️ Clear Chat")
|
| 187 |
+
|
| 188 |
+
gr.Examples(
|
| 189 |
+
examples=[
|
| 190 |
+
["Explain quantum computing in simple terms."],
|
| 191 |
+
["Write a fast Python script to parse and extract JSON data from nested API responses."],
|
| 192 |
+
["What are the key trade-offs between monolithic and microservice architectures?"],
|
| 193 |
+
["Compose a sci-fi short story about an AI discovering ancient human technology."],
|
| 194 |
+
],
|
| 195 |
+
inputs=[message],
|
| 196 |
+
)
|
| 197 |
+
|
| 198 |
+
event_inputs = [
|
| 199 |
+
chatbot,
|
| 200 |
+
system_prompt,
|
| 201 |
+
temperature,
|
| 202 |
+
top_p,
|
| 203 |
+
top_k,
|
| 204 |
+
max_tokens,
|
| 205 |
+
repeat_penalty,
|
| 206 |
+
]
|
| 207 |
+
|
| 208 |
+
# Submit triggers user message display first, then streams assistant response
|
| 209 |
+
message.submit(
|
| 210 |
+
add_user_message,
|
| 211 |
+
inputs=[message, chatbot],
|
| 212 |
+
outputs=[message, chatbot],
|
| 213 |
+
queue=False,
|
| 214 |
+
).then(
|
| 215 |
+
bot_response,
|
| 216 |
+
inputs=event_inputs,
|
| 217 |
+
outputs=chatbot,
|
| 218 |
+
api_name="chat",
|
| 219 |
+
)
|
| 220 |
+
|
| 221 |
+
send.click(
|
| 222 |
+
add_user_message,
|
| 223 |
+
inputs=[message, chatbot],
|
| 224 |
+
outputs=[message, chatbot],
|
| 225 |
+
queue=False,
|
| 226 |
+
).then(
|
| 227 |
+
bot_response,
|
| 228 |
+
inputs=event_inputs,
|
| 229 |
+
outputs=chatbot,
|
| 230 |
+
api_name="chat",
|
| 231 |
+
)
|
| 232 |
+
|
| 233 |
+
clear.click(lambda: [], outputs=chatbot, queue=False)
|
| 234 |
+
|
| 235 |
+
demo.queue(default_concurrency_limit=1)
|
| 236 |
+
|
| 237 |
+
if __name__ == "__main__":
|
| 238 |
+
demo.launch(mcp_server=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
--extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cu124
|
| 2 |
+
llama-cpp-python>=0.3.35
|