Update app.py
Browse files
app.py
CHANGED
|
@@ -3,13 +3,18 @@ from llama_cpp import Llama
|
|
| 3 |
from typing import Generator
|
| 4 |
import os
|
| 5 |
|
| 6 |
-
# Initialize
|
| 7 |
-
model_path = "
|
| 8 |
-
llm = Llama(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
def generate_astrology_prediction(prompt: str) -> Generator[str, None, None]:
|
| 11 |
"""
|
| 12 |
-
Generates astrology-based fortune-telling predictions using AstroSage-8B-
|
| 13 |
"""
|
| 14 |
system_prompt = (
|
| 15 |
"You are an expert astrologer, specializing in fortune-telling. Given a user prompt "
|
|
@@ -18,9 +23,9 @@ def generate_astrology_prediction(prompt: str) -> Generator[str, None, None]:
|
|
| 18 |
"Use bullet points for key predictions and keep responses engaging and concise. "
|
| 19 |
"Despite being trained on astronomy, adapt your knowledge to provide astrology-like insights."
|
| 20 |
)
|
| 21 |
-
full_prompt = f"<|SYSTEM|> {system_prompt}
|
| 22 |
|
| 23 |
-
# Stream output
|
| 24 |
for output in llm(full_prompt, max_tokens=1000, temperature=0.7, top_p=0.9, stream=True):
|
| 25 |
content = output["choices"][0]["text"]
|
| 26 |
if content:
|
|
|
|
| 3 |
from typing import Generator
|
| 4 |
import os
|
| 5 |
|
| 6 |
+
# Initialize model
|
| 7 |
+
model_path = "AstroSage-8B-BF16.gguf" # Downloaded from AstroMLab/AstroSage-8B-GGUF
|
| 8 |
+
llm = Llama.from_pretrained(
|
| 9 |
+
repo_id="AstroMLab/AstroSage-8B-GGUF",
|
| 10 |
+
filename=model_path,
|
| 11 |
+
n_ctx=2048, # Context length for prompts
|
| 12 |
+
n_threads=2 # Use 2 CPU cores
|
| 13 |
+
)
|
| 14 |
|
| 15 |
def generate_astrology_prediction(prompt: str) -> Generator[str, None, None]:
|
| 16 |
"""
|
| 17 |
+
Generates astrology-based fortune-telling predictions using AstroSage-8B-BF16.gguf with streaming.
|
| 18 |
"""
|
| 19 |
system_prompt = (
|
| 20 |
"You are an expert astrologer, specializing in fortune-telling. Given a user prompt "
|
|
|
|
| 23 |
"Use bullet points for key predictions and keep responses engaging and concise. "
|
| 24 |
"Despite being trained on astronomy, adapt your knowledge to provide astrology-like insights."
|
| 25 |
)
|
| 26 |
+
full_prompt = f"<|SYSTEM|> {system_prompt}\n<|USER|> {prompt}\n<|ASSISTANT|>"
|
| 27 |
|
| 28 |
+
# Stream output
|
| 29 |
for output in llm(full_prompt, max_tokens=1000, temperature=0.7, top_p=0.9, stream=True):
|
| 30 |
content = output["choices"][0]["text"]
|
| 31 |
if content:
|