Switch to ZeroGPU with llama-cpp for GGUF model
Browse filesFiles changed (3)
- README.md+5
- app.py+54-87
- requirements.txt+2
7 unmodified lines89101112137 unmodified linesapp_file: app.pypinned: falselicense: apache-2.0---# Qwen3.5-9B Uncensored API Interface7 unmodified lines891011121314151617187 unmodified linesapp_file: app.pypinned: falselicense: apache-2.0tags:- qwen- uncensored- llama-cpp- zerogpu---# Qwen3.5-9B Uncensored API Interface
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253541 unmodified line56575859606162636465666768697071727374757677787980818283848586878889909192939414 unmodified lines10911011111211311411511611711811912012112212312412512612712812913010 unmodified lines14114214314414514642 unmodified lines18919019119219319419519610 unmodified lines2072082092102112122132141 unmodified line21621721821922022122222322422536 unmodified lines26226326426526626726810 unmodified lines27928028128228328428515 unmodified lines301302303304305306307import gradio as grfrom huggingface_hub import InferenceClientMODEL_ID = "HauhauCS/Qwen3.5-9B-Uncensored-HauhauCS-Aggressive"client = InferenceClient()DEFAULT_PARAMS = {"temperature": 0.7,"top_p": 0.8,"top_k": 20,"max_tokens": 2048,}def generate_response(message: str,history: list,system_prompt: str = "",temperature: float = 0.7,top_p: float = 0.8,top_k: int = 20,max_tokens: int = 2048,) -> str:messages = []if system_prompt.strip():messages.append({"role": "system", "content": system_prompt})for user_msg, assistant_msg in history:if user_msg:messages.append({"role": "user", "content": user_msg})if assistant_msg:messages.append({"role": "assistant", "content": assistant_msg})messages.append({"role": "user", "content": message})try:response = client.chat_completion(model=MODEL_ID,messages=messages,temperature=temperature,top_p=top_p,max_tokens=max_tokens,)return response.choices[0].message.contentexcept Exception as e:return f"Error: {str(e)}"def generate_stream(message: str,history: list,system_prompt: str = "",1 unmodified linetop_p: float = 0.8,top_k: int = 20,max_tokens: int = 2048,):messages = []if system_prompt.strip():messages.append({"role": "system", "content": system_prompt})for user_msg, assistant_msg in history:if user_msg:messages.append({"role": "user", "content": user_msg})if assistant_msg:messages.append({"role": "assistant", "content": assistant_msg})messages.append({"role": "user", "content": message})try:stream = client.chat_completion(model=MODEL_ID,messages=messages,temperature=temperature,top_p=top_p,max_tokens=max_tokens,stream=True,)partial_message = ""for chunk in stream:if chunk.choices[0].delta.content:partial_message += chunk.choices[0].delta.contentyield partial_messageexcept Exception as e:yield f"Error: {str(e)}"def api_generate(prompt: str,system_prompt: str = "",14 unmodified linesReturns:Dictionary with 'response' key containing generated text"""messages = []if system_prompt.strip():messages.append({"role": "system", "content": system_prompt})messages.append({"role": "user", "content": prompt})try:response = client.chat_completion(model=MODEL_ID,messages=messages,temperature=temperature,top_p=top_p,max_tokens=max_tokens,)return {"response": response.choices[0].message.content, "status": "success"}except Exception as e:return {"response": None, "status": "error", "error": str(e)}10 unmodified lines- Fully uncensored (0/465 refusals)- Multimodal capable (text, image, video)- Supports 201 languagesUse the chat interface below or access via API."""42 unmodified lines)max_tokens = gr.Slider(minimum=64,maximum=8192,value=2048,step=64,label="Max Tokens",)10 unmodified linesmessage = history[-1][0]history_without_last = history[:-1]response = ""for partial in generate_stream(message,history_without_last,system_prompt,1 unmodified linetop_p,top_k,max_tokens):response = partialhistory[-1][1] = responseyield historymsg.submit(user_submit,36 unmodified linessystem_prompt="You are a helpful assistant",temperature=0.7,top_p=0.8,max_tokens=2048,api_name="/api_generate")print(result)10 unmodified lines"You are a helpful assistant",0.7,0.8,2048]}'```15 unmodified lineswith gr.Row():api_temp = gr.Slider(0.0, 2.0, 0.7, step=0.1, label="Temperature")api_top_p = gr.Slider(0.0, 1.0, 0.8, step=0.05, label="Top P")api_max_tokens = gr.Slider(64, 8192, 2048, step=64, label="Max Tokens")api_submit = gr.Button("Generate", variant="primary")with gr.Column():12345678910111213141516171819202122232425262728293031323334353637383940414243441 unmodified line464748495051525354555657585960616263646566676814 unmodified lines8384858687888990919293949596979810 unmodified lines10911011111211311411542 unmodified lines15815916016116216316416510 unmodified lines1761771781791801811821 unmodified line18418518618718818919019119236 unmodified lines22923023123223323423510 unmodified lines24624724824925025125215 unmodified lines268269270271272273274import gradio as grimport spacesfrom huggingface_hub import hf_hub_downloadfrom llama_cpp import LlamaMODEL_REPO = "HauhauCS/Qwen3.5-9B-Uncensored-HauhauCS-Aggressive"MODEL_FILE = "Qwen3.5-9B-Uncensored-HauhauCS-Aggressive-Q4_K_M.gguf"llm = Nonedef load_model():global llmif llm is None:model_path = hf_hub_download(repo_id=MODEL_REPO, filename=MODEL_FILE)llm = Llama(model_path=model_path,n_ctx=8192,n_gpu_layers=-1,verbose=False,)return llmdef format_messages(message: str, history: list, system_prompt: str = "") -> str:formatted = ""if system_prompt.strip():formatted += f"<|im_start|>system\n{system_prompt}<|im_end|>\n"for user_msg, assistant_msg in history:if user_msg:formatted += f"<|im_start|>user\n{user_msg}<|im_end|>\n"if assistant_msg:formatted += f"<|im_start|>assistant\n{assistant_msg}<|im_end|>\n"formatted += f"<|im_start|>user\n{message}<|im_end|>\n<|im_start|>assistant\n"return formatted@spaces.GPUdef generate_response(message: str,history: list,system_prompt: str = "",1 unmodified linetop_p: float = 0.8,top_k: int = 20,max_tokens: int = 2048,) -> str:model = load_model()prompt = format_messages(message, history, system_prompt)output = model(prompt,max_tokens=max_tokens,temperature=temperature,top_p=top_p,top_k=top_k,stop=["<|im_end|>", "<|im_start|>"],)return output["choices"][0]["text"].strip()@spaces.GPUdef api_generate(prompt: str,system_prompt: str = "",14 unmodified linesReturns:Dictionary with 'response' key containing generated text"""try:response = generate_response(message=prompt,history=[],system_prompt=system_prompt,temperature=temperature,top_p=top_p,max_tokens=max_tokens,)return {"response": response, "status": "success"}except Exception as e:return {"response": None, "status": "error", "error": str(e)}10 unmodified lines- Fully uncensored (0/465 refusals)- Multimodal capable (text, image, video)- Supports 201 languages- Running on ZeroGPU with Q4_K_M quantizationUse the chat interface below or access via API."""42 unmodified lines)max_tokens = gr.Slider(minimum=64,maximum=4096,value=1024,step=64,label="Max Tokens",)10 unmodified linesmessage = history[-1][0]history_without_last = history[:-1]response = generate_response(message,history_without_last,system_prompt,1 unmodified linetop_p,top_k,max_tokens)history[-1][1] = responsereturn historymsg.submit(user_submit,36 unmodified linessystem_prompt="You are a helpful assistant",temperature=0.7,top_p=0.8,max_tokens=1024,api_name="/api_generate")print(result)10 unmodified lines"You are a helpful assistant",0.7,0.8,1024]}'```15 unmodified lineswith gr.Row():api_temp = gr.Slider(0.0, 2.0, 0.7, step=0.1, label="Temperature")api_top_p = gr.Slider(0.0, 1.0, 0.8, step=0.05, label="Top P")api_max_tokens = gr.Slider(64, 4096, 1024, step=64, label="Max Tokens")api_submit = gr.Button("Generate", variant="primary")with gr.Column():
12gradio>=4.0.0huggingface_hub>=0.20.01234gradio>=4.0.0huggingface_hub>=0.20.0llama-cpp-pythonspaces
README.md+5
app.py+54-87
requirements.txt+2