Spaces:
Paused
Paused
Create App.py
Browse files
App.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from huggingface_hub import hf_hub_download
|
| 3 |
+
from llama_cpp import Llama
|
| 4 |
+
|
| 5 |
+
# 1. Download file GGUF dari repo lu ke mesin Space
|
| 6 |
+
# Ganti dengan repo_id lu dan NAMA FILE gguf-nya yang bener
|
| 7 |
+
repo_id = "Daffaadityp/AxonAI-MX4-2.0-GGUF" # Ganti kalau reponya beda
|
| 8 |
+
nama_file_gguf = "AxonAI-MX4-2.0-Q4_K_M.gguf" # Sesuaikan sama nama file lu
|
| 9 |
+
|
| 10 |
+
print("Downloading model...")
|
| 11 |
+
model_path = hf_hub_download(repo_id=repo_id, filename=nama_file_gguf)
|
| 12 |
+
|
| 13 |
+
# 2. Load model GGUF ke memori CPU
|
| 14 |
+
print("Loading model to CPU...")
|
| 15 |
+
llm = Llama(
|
| 16 |
+
model_path=model_path,
|
| 17 |
+
n_ctx=2048, # Kapasitas ingatan konteks (bisa dikecilin misal 1024 kalau berat)
|
| 18 |
+
n_threads=2 # Disesuaikan sama CPU Basic yang dapet 2 vCPU
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
# 3. Fungsi buat generate jawaban
|
| 22 |
+
def prediksi(prompt):
|
| 23 |
+
# Format prompt bisa disesuaikan sama chat template model lu
|
| 24 |
+
hasil = llm(
|
| 25 |
+
f"User: {prompt}\nAxonAI:", # Contoh simple prompt formatting
|
| 26 |
+
max_tokens=150,
|
| 27 |
+
stop=["User:", "\n\n"],
|
| 28 |
+
echo=False
|
| 29 |
+
)
|
| 30 |
+
return hasil['choices'][0]['text'].strip()
|
| 31 |
+
|
| 32 |
+
# 4. Bikin UI Gradio biar API-nya kebuka
|
| 33 |
+
iface = gr.Interface(fn=prediksi, inputs="text", outputs="text")
|
| 34 |
+
iface.launch()
|