Spaces:
Build error
Build error
Hashim commited on
Commit ·
998f39b
1
Parent(s): 9420bdd
Add application file and dependencies
Browse files- app.py +34 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import spaces # Activates Hugging Face's free ZeroGPU
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from huggingface_hub import hf_hub_download
|
| 5 |
+
from llama_cpp import Llama
|
| 6 |
+
|
| 7 |
+
# 1. Download your exact abliterated DeepSeek V4 GGUF model file
|
| 8 |
+
model_path = hf_hub_download(
|
| 9 |
+
repo_id="huihui-ai/Huihui-DeepSeek-V4-Flash-abliterated-GGUF",
|
| 10 |
+
filename="Huihui-DeepSeek-V4-Flash-abliterated-Q3_K_S.gguf"
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
# Initialize the model engine in memory
|
| 14 |
+
llm = Llama(model_path=model_path, n_ctx=4096)
|
| 15 |
+
|
| 16 |
+
# 2. Define the raw prediction function using the Cloud GPU
|
| 17 |
+
@spaces.GPU
|
| 18 |
+
def run_api(prompt, max_tokens=1024):
|
| 19 |
+
output = llm(
|
| 20 |
+
f"<|User|>{prompt}<|Assistant|>",
|
| 21 |
+
max_tokens=int(max_tokens),
|
| 22 |
+
stop=["<|User|>", "<|Assistant|>"]
|
| 23 |
+
)
|
| 24 |
+
return output["choices"][0]["text"]
|
| 25 |
+
|
| 26 |
+
# 3. Create the API routing endpoint (Bypassing visual elements)
|
| 27 |
+
demo = gr.Interface(
|
| 28 |
+
fn=run_api,
|
| 29 |
+
inputs=[gr.Textbox(label="prompt"), gr.Number(value=1024, label="max_tokens")],
|
| 30 |
+
outputs=gr.Textbox(label="response"),
|
| 31 |
+
api_name="predict" # <--- This creates the raw web API endpoint
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
llama-cpp-python
|
| 2 |
+
huggingface_hub
|