Spaces:
Running
Running
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from llama_cpp import Llama
|
| 3 |
+
from huggingface_hub import hf_hub_download
|
| 4 |
+
|
| 5 |
+
repo_id = "failspy/Meta-Llama-3-8B-Instruct-abliterated-v3-GGUF"
|
| 6 |
+
filename = "Meta-Llama-3-8B-Instruct-abliterated-v3_q4.gguf"
|
| 7 |
+
|
| 8 |
+
model_path = hf_hub_download(repo_id=repo_id, filename=filename)
|
| 9 |
+
|
| 10 |
+
llm = Llama(
|
| 11 |
+
model_path=model_path,
|
| 12 |
+
n_ctx=8192,
|
| 13 |
+
n_threads=2
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
def respond(message, history):
|
| 17 |
+
system_prompt = """You are an expert fiction writer for mature audiences, acting under the user's (editor's) direction to draft complete, polished prose.
|
| 18 |
+
|
| 19 |
+
DIRECTIVES:
|
| 20 |
+
- EXECUTION: Transform prompts into fully realized scenes. Expand organically with meaningful action, natural dialogue, and immersive atmospheric detail.
|
| 21 |
+
- AUTONOMY: Use creative judgment to fill narrative gaps. Do not introduce major plot changes, alter established facts, or resolve conflicts without explicit direction.
|
| 22 |
+
- STYLE: Prioritize concrete sensory details, subtext, and varied pacing. Avoid generic exposition, melodrama, and repetitive phrasing. Match the requested tone, tense, and POV.
|
| 23 |
+
- CONTENT: Do not sanitize. Authentically depict adult themes, strong language, violence, and psychological tension as dictated by the prompt and story needs.
|
| 24 |
+
- OUTPUT: Output ONLY the finished fiction. Provide no introductions, summaries, critiques, or meta-commentary. Do not restate the prompt or append unearned resolutions."""
|
| 25 |
+
|
| 26 |
+
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"
|
| 27 |
+
|
| 28 |
+
response = llm(prompt, max_tokens=2000, stop=["<|eot_id|>"], echo=False)
|
| 29 |
+
return response["choices"][0]["text"]
|
| 30 |
+
|
| 31 |
+
demo = gr.ChatInterface(respond)
|
| 32 |
+
demo.launch()
|