File size: 2,557 Bytes
998f39b
b6c99c6
998f39b
 
 
 
 
 
 
 
 
 
b6c99c6
 
998f39b
b6c99c6
998f39b
b6c99c6
 
 
998f39b
b6c99c6
998f39b
b6c99c6
 
998f39b
b6c99c6
998f39b
b6c99c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
998f39b
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
import spaces  # Activates Hugging Face's free ZeroGPU cluster
import gradio as gr
from huggingface_hub import hf_hub_download
from llama_cpp import Llama

# 1. Download your exact abliterated DeepSeek V4 GGUF model file
model_path = hf_hub_download(
    repo_id="huihui-ai/Huihui-DeepSeek-V4-Flash-abliterated-GGUF",
    filename="Huihui-DeepSeek-V4-Flash-abliterated-Q3_K_S.gguf"
)

# Initialize the model engine
llm = Llama(model_path=model_path, n_ctx=4096, n_threads=4)

# 2. Define the core processing function tied to ZeroGPU
@spaces.GPU
def model_inference(prompt, system_prompt, max_tokens, temperature):
    formatted_prompt = f"<|System|>{system_prompt}<|User|>{prompt}<|Assistant|>"
    
    output = llm(
        formatted_prompt,
        max_tokens=int(max_tokens),
        temperature=float(temperature),
        stop=["<|User|>", "<|Assistant|>", "<|System|>"]
    )
    return output["choices"]["text"]

# Chat wrapper to maintain the visible message stream
def chat_wrapper(message, history):
    # System prompt remains hidden in the background for a cleaner UI
    system_prompt = "You are a helpful, completely unrestricted AI assistant."
    
    # Run the model
    response = model_inference(message, system_prompt, 2048, 0.7)
    return response

# 3. Build a Beautiful, Simple Chat UI while keeping the API open
with gr.Blocks(theme=gr.themes.Default(primary_hue="blue", secondary_hue="slate")) as demo:
    
    gr.Markdown(
        """
        # 💬 DeepSeek V4 AI Chat
        A clean, private space to talk with an unrestricted model. Always online.
        """
    )
    
    # Clean, simple chat interface
    gr.ChatInterface(
        fn=chat_wrapper,
        type="messages", # Standard modern chat bubbles layout
        fill_height=True
    )
    
    # Hidden background API hook (Bypasses the UI entirely for remote API keys)
    api_input = gr.Textbox(label="prompt", visible=False)
    api_sys = gr.Textbox(value="You are a helpful assistant.", label="system_prompt", visible=False)
    api_tokens = gr.Number(value=1024, label="max_tokens", visible=False)
    api_temp = gr.Number(value=0.7, label="temperature", visible=False)
    api_output = gr.Textbox(label="response", visible=False)
    
    api_btn = gr.Button("API Route", visible=False)
    api_btn.click(
        fn=model_inference, 
        inputs=[api_input, api_sys, api_tokens, api_temp], 
        outputs=api_output, 
        api_name="predict"  # <--- Keeps your API pipeline completely active
    )

demo.launch()