JustNikunj commited on
Commit
cdae2d2
Β·
verified Β·
1 Parent(s): 6384095

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -14
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(token=HUGGINGFACE_TOKEN)
116
- logger.info("βœ… LLM client initialized")
 
 
 
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 text_generation method (more compatible across versions)
612
- response = LLM_CLIENT.text_generation(
613
- prompt=prompt,
614
  model=MODEL_NAME,
615
- max_new_tokens=300,
 
 
 
 
 
 
616
  temperature=0.7,
617
- top_p=0.9,
618
- return_full_text=False,
619
- stop_sequences=["\n\n\n"]
620
  )
621
 
622
- recommendation = response.strip()
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: