bkbilal09 commited on
Commit
569a29c
·
verified ·
1 Parent(s): 291c723

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -16
app.py CHANGED
@@ -5,7 +5,7 @@ import PyPDF2
5
  import docx
6
 
7
  # ==========================================
8
- # 1. CORE ENGINE (WITH AUTO-FALLBACK)
9
  # ==========================================
10
  def get_client():
11
  api_key = os.environ.get("GROQ_API_KEY")
@@ -46,20 +46,20 @@ def stream_llm(system_role, user_text, audio_path=None, file_path=None):
46
  if file_path:
47
  content = extract_text(file_path)
48
  if len(content) > 30000:
49
- yield "### ⚠️ Limit Exceeded\nYour CV is too large. Please upload a file smaller than 30,000 characters."
50
  return
51
  file_context = f"\n[CV Content]:\n{content}"
52
 
53
  combined_input = f"User Target: {user_text}\nVoice: {voice_content}\n{file_context}".strip()
54
 
55
- # Model List for Fallback (If one fails, try next)
56
- models = ["llama-3.3-70b-versatile", "llama3-70b-8192", "mixtral-8x7b-32768"]
57
 
58
  success = False
59
  for model_name in models:
60
  try:
61
  client = get_client()
62
- detail_cmd = "\n\nSTRICT: Respond ONLY in user's language. Provide massive detail, salary ranges, and 5-10 clickable links."
63
 
64
  response = client.chat.completions.create(
65
  model=model_name,
@@ -75,23 +75,20 @@ def stream_llm(system_role, user_text, audio_path=None, file_path=None):
75
  partial_text += chunk.choices[0].delta.content
76
  yield partial_text
77
  success = True
78
- break # If successful, stop trying other models
79
  except Exception as e:
80
- if "429" in str(e): # If rate limit, try next model
81
- continue
82
- else:
83
- yield f"### ⚠️ Error\n{str(e)}"
84
- return
85
 
86
  if not success:
87
- yield "### ⚠️ Rate Limit Alert\nAll available models are currently at their daily limit. Please try again in a few minutes or check your Groq Dashboard."
88
 
89
  # ==========================================
90
- # 2. PROMPTS & UI (REMAIN UNCHANGED)
91
  # ==========================================
92
- NEXUS_PROMPT = "Analyze Dream Company: Define roles/benefits. Extract CV. Provide Strengths, Weaknesses, Skill Matrix."
93
- ZEN_PROMPT = "Motivational Strategist. Examples: Edison, Sanders, J.K. Rowling, Steve Jobs, Jack Ma. Failure is growth. Massive length."
94
- ORBIT_PROMPT = "Career Architect. Dream company + SALARY. 6-month roadmap (1-2, 3-4, 5-6) with links."
95
  PATH_PROMPT = "Industry Scout. Identify 5-10 industries/companies for this CV. Provide SALARY, direct links, and hiring strategy."
96
 
97
  custom_css = """
 
5
  import docx
6
 
7
  # ==========================================
8
+ # 1. CORE ENGINE (FIXED MODELS LIST)
9
  # ==========================================
10
  def get_client():
11
  api_key = os.environ.get("GROQ_API_KEY")
 
46
  if file_path:
47
  content = extract_text(file_path)
48
  if len(content) > 30000:
49
+ yield "### ⚠️ Limit Exceeded\nYour CV is too large."
50
  return
51
  file_context = f"\n[CV Content]:\n{content}"
52
 
53
  combined_input = f"User Target: {user_text}\nVoice: {voice_content}\n{file_context}".strip()
54
 
55
+ # UPDATED MODELS: Removed decommissioned 'llama3-70b-8192'
56
+ models = ["llama-3.3-70b-versatile", "llama-3.1-70b-versatile", "mixtral-8x7b-32768"]
57
 
58
  success = False
59
  for model_name in models:
60
  try:
61
  client = get_client()
62
+ detail_cmd = "\n\nSTRICT: Respond ONLY in user's language. Exhaustive detail, salary ranges, and 10 clickable links."
63
 
64
  response = client.chat.completions.create(
65
  model=model_name,
 
75
  partial_text += chunk.choices[0].delta.content
76
  yield partial_text
77
  success = True
78
+ break
79
  except Exception as e:
80
+ # Try next model if rate limit or model error
81
+ continue
 
 
 
82
 
83
  if not success:
84
+ yield "### ⚠️ Service Temporarily Busy\nAll high-end models are at capacity. Please refresh in 1 minute."
85
 
86
  # ==========================================
87
+ # 2. PROMPTS & UI (AS PER YOUR REQUIREMENTS)
88
  # ==========================================
89
+ NEXUS_PROMPT = "Analyze Dream Company: Roles/Benefits. Extract CV. Strengths, Weaknesses, Skill Matrix."
90
+ ZEN_PROMPT = "Motivational Strategist. Use examples: Edison, Sanders, J.K. Rowling, Steve Jobs, Jack Ma. Massive length."
91
+ ORBIT_PROMPT = "Career Architect. Dream company + SALARY. 6-month roadmap with links."
92
  PATH_PROMPT = "Industry Scout. Identify 5-10 industries/companies for this CV. Provide SALARY, direct links, and hiring strategy."
93
 
94
  custom_css = """