File size: 1,529 Bytes
52b58aa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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)