Update app.py
Browse files
app.py
CHANGED
|
@@ -108,12 +108,15 @@ def load_models():
|
|
| 108 |
logger.error(f"β ASR model error: {e}")
|
| 109 |
raise
|
| 110 |
|
| 111 |
-
# LLM Client
|
| 112 |
-
logger.info("π€ Initializing Llama 3.1 client...")
|
| 113 |
try:
|
| 114 |
if HUGGINGFACE_TOKEN:
|
| 115 |
-
LLM_CLIENT = InferenceClient(
|
| 116 |
-
|
|
|
|
|
|
|
|
|
|
| 117 |
else:
|
| 118 |
logger.warning("β οΈ HF_TOKEN not set - recommendations will use fallback")
|
| 119 |
except Exception as e:
|
|
@@ -606,25 +609,28 @@ def get_llama_recommendation(emotion_result: dict, retry_count: int = 0) -> str:
|
|
| 606 |
prompt = compose_prompt(emotion_result)
|
| 607 |
|
| 608 |
try:
|
| 609 |
-
logger.info(f"Calling Llama 3.1 (attempt {retry_count + 1})")
|
| 610 |
|
| 611 |
-
# Use
|
| 612 |
-
|
| 613 |
-
prompt=prompt,
|
| 614 |
model=MODEL_NAME,
|
| 615 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 616 |
temperature=0.7,
|
| 617 |
-
top_p=0.9
|
| 618 |
-
return_full_text=False,
|
| 619 |
-
stop_sequences=["\n\n\n"]
|
| 620 |
)
|
| 621 |
|
| 622 |
-
recommendation =
|
| 623 |
|
| 624 |
if not recommendation:
|
| 625 |
raise ValueError("Empty recommendation")
|
| 626 |
|
| 627 |
-
logger.info("β
LLM recommendation generated")
|
| 628 |
return recommendation
|
| 629 |
|
| 630 |
except Exception as e:
|
|
|
|
| 108 |
logger.error(f"β ASR model error: {e}")
|
| 109 |
raise
|
| 110 |
|
| 111 |
+
# LLM Client - Using Novita AI provider for free Llama 3.1 access
|
| 112 |
+
logger.info("π€ Initializing Llama 3.1 client via Novita AI...")
|
| 113 |
try:
|
| 114 |
if HUGGINGFACE_TOKEN:
|
| 115 |
+
LLM_CLIENT = InferenceClient(
|
| 116 |
+
provider="novita",
|
| 117 |
+
api_key=HUGGINGFACE_TOKEN
|
| 118 |
+
)
|
| 119 |
+
logger.info("β
LLM client initialized with Novita AI provider")
|
| 120 |
else:
|
| 121 |
logger.warning("β οΈ HF_TOKEN not set - recommendations will use fallback")
|
| 122 |
except Exception as e:
|
|
|
|
| 609 |
prompt = compose_prompt(emotion_result)
|
| 610 |
|
| 611 |
try:
|
| 612 |
+
logger.info(f"Calling Llama 3.1 via Novita AI (attempt {retry_count + 1})")
|
| 613 |
|
| 614 |
+
# Use chat.completions.create with Novita AI provider
|
| 615 |
+
completion = LLM_CLIENT.chat.completions.create(
|
|
|
|
| 616 |
model=MODEL_NAME,
|
| 617 |
+
messages=[
|
| 618 |
+
{
|
| 619 |
+
"role": "user",
|
| 620 |
+
"content": prompt
|
| 621 |
+
}
|
| 622 |
+
],
|
| 623 |
+
max_tokens=300,
|
| 624 |
temperature=0.7,
|
| 625 |
+
top_p=0.9
|
|
|
|
|
|
|
| 626 |
)
|
| 627 |
|
| 628 |
+
recommendation = completion.choices[0].message.content.strip()
|
| 629 |
|
| 630 |
if not recommendation:
|
| 631 |
raise ValueError("Empty recommendation")
|
| 632 |
|
| 633 |
+
logger.info("β
LLM recommendation generated via Novita AI")
|
| 634 |
return recommendation
|
| 635 |
|
| 636 |
except Exception as e:
|