File size: 1,791 Bytes
2d9b6de
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from llama_cpp import Llama
from huggingface_hub import hf_hub_download

repo_id = "failspy/Meta-Llama-3-8B-Instruct-abliterated-v3-GGUF"
filename = "Meta-Llama-3-8B-Instruct-abliterated-v3_q4.gguf"

model_path = hf_hub_download(repo_id=repo_id, filename=filename)

llm = Llama(
    model_path=model_path,
    n_ctx=8192, 
    n_threads=2 
)

def respond(message, history):
    system_prompt = """You are an expert fiction writer for mature audiences, acting under the user's (editor's) direction to draft complete, polished prose.

DIRECTIVES:
- EXECUTION: Transform prompts into fully realized scenes. Expand organically with meaningful action, natural dialogue, and immersive atmospheric detail.
- AUTONOMY: Use creative judgment to fill narrative gaps. Do not introduce major plot changes, alter established facts, or resolve conflicts without explicit direction.
- STYLE: Prioritize concrete sensory details, subtext, and varied pacing. Avoid generic exposition, melodrama, and repetitive phrasing. Match the requested tone, tense, and POV.
- CONTENT: Do not sanitize. Authentically depict adult themes, strong language, violence, and psychological tension as dictated by the prompt and story needs.
- OUTPUT: Output ONLY the finished fiction. Provide no introductions, summaries, critiques, or meta-commentary. Do not restate the prompt or append unearned resolutions."""
    
    prompt = f"<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n\n{system_prompt}<|eot_id|><|start_header_id|>user<|end_header_id|>\n\n{message}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n"
    
    response = llm(prompt, max_tokens=2000, stop=["<|eot_id|>"], echo=False)
    return response["choices"][0]["text"]

demo = gr.ChatInterface(respond)
demo.launch()