Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,45 +3,41 @@ from llama_cpp import Llama
|
|
| 3 |
from huggingface_hub import hf_hub_download
|
| 4 |
import os
|
| 5 |
|
| 6 |
-
# 1. Config -
|
| 7 |
REPO_ID = "erdemozkan/YOLO-7B-Qwen-Coder"
|
| 8 |
GGUF_FILE = "YOLO-7B-Qwen-q4.gguf"
|
| 9 |
|
| 10 |
print(f"π YOLO CODER: Pulling {GGUF_FILE}...")
|
| 11 |
|
| 12 |
try:
|
| 13 |
-
# This downloads the model to the local container
|
| 14 |
model_path = hf_hub_download(repo_id=REPO_ID, filename=GGUF_FILE)
|
| 15 |
-
print(f"β
Model
|
| 16 |
except Exception as e:
|
| 17 |
print(f"β Download failed: {e}")
|
| 18 |
model_path = None
|
| 19 |
|
| 20 |
# 2. Engine Initialization
|
| 21 |
-
# n_threads=2: Do NOT exceed 2 on the HF Free tier
|
| 22 |
if model_path:
|
| 23 |
llm = Llama(
|
| 24 |
model_path=model_path,
|
| 25 |
n_ctx=1024,
|
| 26 |
-
n_threads=2,
|
| 27 |
verbose=False
|
| 28 |
)
|
| 29 |
else:
|
| 30 |
llm = None
|
| 31 |
|
| 32 |
def yoco_heal(broken_code):
|
| 33 |
-
if not llm: return "β Engine Offline. Model
|
| 34 |
if not broken_code.strip(): return "β οΈ Paste code."
|
| 35 |
|
| 36 |
-
# Persona prompt for Qwen-Coder
|
| 37 |
prompt = f"<|im_start|>system\nYou are YOLO CODER. Fix the code perfectly.<|im_end|>\n<|im_start|>user\n{broken_code}<|im_end|>\n<|im_start|>assistant\n"
|
| 38 |
|
| 39 |
response = llm(prompt, max_tokens=1024, stop=["<|im_end|>"], echo=False)
|
| 40 |
return response["choices"][0]["text"].strip()
|
| 41 |
|
| 42 |
-
# 3. UI
|
| 43 |
css = ".gradio-container {background:#000; color:#ffff00; font-family:monospace;} #header {text-align:center; text-shadow: 0 0 10px #ffff00;}"
|
| 44 |
-
|
| 45 |
with gr.Blocks(css=css) as demo:
|
| 46 |
gr.Markdown("# YOLO CODER [DOCKER CPU]", elem_id="header")
|
| 47 |
with gr.Row():
|
|
@@ -51,4 +47,5 @@ with gr.Blocks(css=css) as demo:
|
|
| 51 |
btn.click(fn=yoco_heal, inputs=in_code, outputs=out_code)
|
| 52 |
|
| 53 |
if __name__ == "__main__":
|
|
|
|
| 54 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 3 |
from huggingface_hub import hf_hub_download
|
| 4 |
import os
|
| 5 |
|
| 6 |
+
# 1. Config - Verified Filename
|
| 7 |
REPO_ID = "erdemozkan/YOLO-7B-Qwen-Coder"
|
| 8 |
GGUF_FILE = "YOLO-7B-Qwen-q4.gguf"
|
| 9 |
|
| 10 |
print(f"π YOLO CODER: Pulling {GGUF_FILE}...")
|
| 11 |
|
| 12 |
try:
|
|
|
|
| 13 |
model_path = hf_hub_download(repo_id=REPO_ID, filename=GGUF_FILE)
|
| 14 |
+
print(f"β
Model found: {model_path}")
|
| 15 |
except Exception as e:
|
| 16 |
print(f"β Download failed: {e}")
|
| 17 |
model_path = None
|
| 18 |
|
| 19 |
# 2. Engine Initialization
|
|
|
|
| 20 |
if model_path:
|
| 21 |
llm = Llama(
|
| 22 |
model_path=model_path,
|
| 23 |
n_ctx=1024,
|
| 24 |
+
n_threads=2, # Optimized for HF Free Tier
|
| 25 |
verbose=False
|
| 26 |
)
|
| 27 |
else:
|
| 28 |
llm = None
|
| 29 |
|
| 30 |
def yoco_heal(broken_code):
|
| 31 |
+
if not llm: return "β Engine Offline. Model file not found."
|
| 32 |
if not broken_code.strip(): return "β οΈ Paste code."
|
| 33 |
|
|
|
|
| 34 |
prompt = f"<|im_start|>system\nYou are YOLO CODER. Fix the code perfectly.<|im_end|>\n<|im_start|>user\n{broken_code}<|im_end|>\n<|im_start|>assistant\n"
|
| 35 |
|
| 36 |
response = llm(prompt, max_tokens=1024, stop=["<|im_end|>"], echo=False)
|
| 37 |
return response["choices"][0]["text"].strip()
|
| 38 |
|
| 39 |
+
# 3. UI logic
|
| 40 |
css = ".gradio-container {background:#000; color:#ffff00; font-family:monospace;} #header {text-align:center; text-shadow: 0 0 10px #ffff00;}"
|
|
|
|
| 41 |
with gr.Blocks(css=css) as demo:
|
| 42 |
gr.Markdown("# YOLO CODER [DOCKER CPU]", elem_id="header")
|
| 43 |
with gr.Row():
|
|
|
|
| 47 |
btn.click(fn=yoco_heal, inputs=in_code, outputs=out_code)
|
| 48 |
|
| 49 |
if __name__ == "__main__":
|
| 50 |
+
# REQUIRED: Port 7860 for Docker on HF
|
| 51 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|