Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,20 +1,21 @@
|
|
|
|
1 |
import os
|
2 |
-
from transformers import pipeline
|
3 |
|
4 |
-
#
|
5 |
-
os.environ['
|
6 |
-
os.
|
7 |
-
os.environ['HF_DATASETS_CACHE'] = '/tmp/cache'
|
8 |
-
os.environ['HUGGINGFACE_HUB_CACHE'] = '/tmp/cache'
|
9 |
|
10 |
-
#
|
11 |
-
|
12 |
-
"
|
13 |
-
|
14 |
-
|
15 |
)
|
16 |
|
17 |
-
def generate_text(prompt,
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
1 |
+
from llama_cpp import Llama
|
2 |
import os
|
|
|
3 |
|
4 |
+
# Configure cache
|
5 |
+
os.environ['GGUF_CACHE'] = '/tmp/gguf_cache'
|
6 |
+
os.makedirs('/tmp/gguf_cache', exist_ok=True)
|
|
|
|
|
7 |
|
8 |
+
# Load GGUF model
|
9 |
+
llm = Llama(
|
10 |
+
model_path="ninja-v1-nsfw-rp.gguf",
|
11 |
+
n_ctx=2048, # Context window
|
12 |
+
n_threads=4 # CPU threads
|
13 |
)
|
14 |
|
15 |
+
def generate_text(prompt, max_tokens=560):
|
16 |
+
output = llm.create_chat_completion(
|
17 |
+
messages=[{"role": "user", "content": prompt}],
|
18 |
+
max_tokens=max_tokens,
|
19 |
+
temperature=0.7
|
20 |
+
)
|
21 |
+
return output['choices'][0]['message']['content']
|