Spaces:
Build error
Build error
Download app.py from robcurioso/nefarious: direct link, hf CLI and curl.
- Browser
- Download file 1.53 kB
-
https://huggingface.co/spaces/robcurioso/nefarious/resolve/main/app.py
- Command line
-
hf download hf://spaces/robcurioso/nefarious/app.py
-
curl -L -o app.py https://huggingface.co/spaces/robcurioso/nefarious/resolve/main/app.py
1.53 kB
| import os | |
| import gradio as gr | |
| from llama_cpp import Llama | |
| from huggingface_hub import hf_hub_download | |
| # Configurações do modelo (Modelo DarkIdol 8B) | |
| REPO_ID = "bartowski/DarkIdol-Llama-3.1-8B-Instruct-1.2-Uncensored-GGUF" | |
| MODEL_FILE = "DarkIdol-Llama-3.1-8B-Instruct-1.2-Uncensored-Q4_K_S.gguf" | |
| print("📥 Baixando modelo...") | |
| model_path = hf_hub_download(repo_id=REPO_ID, filename=MODEL_FILE) | |
| print("🚀 Carregando IA... (Pode demorar um pouco na CPU)") | |
| # n_gpu_layers=0 porque o Space gratuito não tem GPU | |
| llm = Llama( | |
| model_path=model_path, | |
| n_ctx=2048, | |
| n_threads=8, # Otimiza para usar os núcleos da CPU do Space | |
| n_gpu_layers=0 | |
| ) | |
| def chat_response(message, history): | |
| # Formato de chat Llama 3.1 | |
| messages = [{"role": "user", "content": message}] | |
| stream = llm.create_chat_completion( | |
| messages=messages, | |
| stream=True, | |
| max_tokens=512, | |
| temperature=0.8, | |
| stop=["<|eot_id|>", "<|end_of_text|>"] | |
| ) | |
| response = "" | |
| for chunk in stream: | |
| if "content" in chunk["choices"][0]["delta"]: | |
| token = chunk["choices"][0]["delta"]["content"] | |
| response += token | |
| yield response | |
| # Criar Interface Estilizada | |
| demo = gr.ChatInterface( | |
| fn=chat_response, | |
| title="Nefarious AI Uncensored", | |
| description="IA Sem Censura - Rodando 24/7", | |
| theme="soft", | |
| examples=["Olá, quem é você?", "Escreva um conto de terror."] | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch(server_name="0.0.0.0", server_port=7860) |