Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,7 @@ import PyPDF2
|
|
| 5 |
import docx
|
| 6 |
|
| 7 |
# ==========================================
|
| 8 |
-
# 1. CORE ENGINE (
|
| 9 |
# ==========================================
|
| 10 |
def get_client():
|
| 11 |
api_key = os.environ.get("GROQ_API_KEY")
|
|
@@ -27,7 +27,7 @@ def extract_text(file_path):
|
|
| 27 |
else:
|
| 28 |
with open(file_path, "r", encoding="utf-8", errors="ignore") as f:
|
| 29 |
text = f.read()
|
| 30 |
-
except Exception: return "Error."
|
| 31 |
return text
|
| 32 |
|
| 33 |
def transcribe_audio(audio_path):
|
|
@@ -44,27 +44,24 @@ def stream_llm(system_role, user_text, audio_path=None, file_path=None):
|
|
| 44 |
file_context = ""
|
| 45 |
if file_path:
|
| 46 |
content = extract_text(file_path)
|
| 47 |
-
|
| 48 |
-
file_context = f"\n[CV Data]:\n{content[:100000]}"
|
| 49 |
|
| 50 |
-
|
|
|
|
| 51 |
|
| 52 |
-
#
|
| 53 |
models = ["llama-3.3-70b-versatile", "llama-3.1-8b-instant"]
|
| 54 |
|
| 55 |
success = False
|
| 56 |
for model_name in models:
|
| 57 |
try:
|
| 58 |
client = get_client()
|
| 59 |
-
# LANGUAGE LOCKDOWN & INSTANT RESPONSE COMMANDS
|
| 60 |
-
detail_cmd = "\n\nCRITICAL: 1. You MUST respond in the EXACT language used by the user. If input is Roman-Urdu, respond ONLY in Roman-Urdu. 2. START STREAMING INSTANTLY. 3. Be extremely long and detailed."
|
| 61 |
-
|
| 62 |
response = client.chat.completions.create(
|
| 63 |
model=model_name,
|
| 64 |
-
messages=[{"role": "system", "content": system_role
|
| 65 |
stream=True,
|
| 66 |
-
temperature=0.
|
| 67 |
-
max_tokens=
|
| 68 |
)
|
| 69 |
|
| 70 |
partial_text = ""
|
|
@@ -77,71 +74,72 @@ def stream_llm(system_role, user_text, audio_path=None, file_path=None):
|
|
| 77 |
except Exception: continue
|
| 78 |
|
| 79 |
if not success:
|
| 80 |
-
yield "### β οΈ
|
| 81 |
|
| 82 |
# ==========================================
|
| 83 |
-
# 2. PROMPTS (
|
| 84 |
# ==========================================
|
| 85 |
-
NEXUS_PROMPT = "
|
| 86 |
-
ZEN_PROMPT = "
|
| 87 |
-
ORBIT_PROMPT = "
|
| 88 |
-
PATH_PROMPT = "
|
| 89 |
|
| 90 |
# ==========================================
|
| 91 |
-
# 3. UI DESIGN (
|
| 92 |
# ==========================================
|
| 93 |
custom_css = """
|
| 94 |
footer {display: none !important;}
|
| 95 |
-
.gradio-container { background: #
|
| 96 |
-
.glass-panel { background: rgba(
|
| 97 |
-
|
| 98 |
-
.
|
| 99 |
-
|
| 100 |
-
.
|
| 101 |
-
input, textarea { background: #101030 !important; color: #ffffff !important; border: 2px solid #00f2fe !important; font-size: 1.1rem !important; }
|
| 102 |
-
.gr-button-primary { background: linear-gradient(90deg, #ff007f, #800080) !important; border: none !important; font-size: 1.1rem !important; font-weight: bold !important; cursor: pointer; }
|
| 103 |
-
.gr-tabs { border-bottom: 2px solid #ff007f !important; }
|
| 104 |
"""
|
| 105 |
|
| 106 |
with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
|
| 107 |
-
gr.HTML("<h1 class='shimmer-title'>AURAPATH AI</h1><p class='new-tagline'>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
with gr.Tabs():
|
| 109 |
with gr.Tab("π Nexus"):
|
| 110 |
with gr.Row():
|
| 111 |
with gr.Column(elem_classes="glass-panel", scale=1):
|
| 112 |
-
f1 = gr.File(label="Upload CV
|
| 113 |
-
t1 = gr.Textbox(label="
|
| 114 |
-
a1 = gr.Audio(label="
|
| 115 |
btn1 = gr.Button("INITIATE DEEP AUDIT", variant="primary")
|
| 116 |
with gr.Column(elem_classes="glass-panel", scale=1.5):
|
| 117 |
-
out1 = gr.Markdown("###
|
| 118 |
btn1.click(stream_llm, [gr.State(NEXUS_PROMPT), t1, a1, f1], out1)
|
| 119 |
|
| 120 |
with gr.Tab("π§ Zen"):
|
| 121 |
with gr.Row():
|
| 122 |
with gr.Column(elem_classes="glass-panel", scale=1):
|
| 123 |
-
a2 = gr.Audio(label="
|
| 124 |
btn2 = gr.Button("ACTIVATE ZEN POWER", variant="primary")
|
| 125 |
with gr.Column(elem_classes="glass-panel", scale=1.5):
|
| 126 |
-
out2 = gr.Markdown("###
|
| 127 |
btn2.click(stream_llm, [gr.State(ZEN_PROMPT), t1, a2, f1], out2)
|
| 128 |
|
| 129 |
with gr.Tab("π
Orbit"):
|
| 130 |
with gr.Row():
|
| 131 |
with gr.Column(elem_classes="glass-panel", scale=1):
|
| 132 |
-
a3 = gr.Audio(label="
|
| 133 |
btn3 = gr.Button("LAUNCH MASTER PLAN", variant="primary")
|
| 134 |
with gr.Column(elem_classes="glass-panel", scale=1.5):
|
| 135 |
-
out3 = gr.Markdown("###
|
| 136 |
btn3.click(stream_llm, [gr.State(ORBIT_PROMPT), t1, a3, f1], out3)
|
| 137 |
|
| 138 |
with gr.Tab("π― Pathfinder"):
|
| 139 |
with gr.Row():
|
| 140 |
with gr.Column(elem_classes="glass-panel", scale=1):
|
| 141 |
-
a_p = gr.Audio(label="
|
| 142 |
btn_p = gr.Button("FIND MY INDUSTRY MATCH", variant="primary")
|
| 143 |
with gr.Column(elem_classes="glass-panel", scale=1.5):
|
| 144 |
-
out_p = gr.Markdown("###
|
| 145 |
btn_p.click(stream_llm, [gr.State(PATH_PROMPT), t1, a_p, f1], out_p)
|
| 146 |
|
| 147 |
if __name__ == "__main__":
|
|
|
|
| 5 |
import docx
|
| 6 |
|
| 7 |
# ==========================================
|
| 8 |
+
# 1. CORE ENGINE (SPEED & LANGUAGE GUARD)
|
| 9 |
# ==========================================
|
| 10 |
def get_client():
|
| 11 |
api_key = os.environ.get("GROQ_API_KEY")
|
|
|
|
| 27 |
else:
|
| 28 |
with open(file_path, "r", encoding="utf-8", errors="ignore") as f:
|
| 29 |
text = f.read()
|
| 30 |
+
except Exception: return "Error reading file."
|
| 31 |
return text
|
| 32 |
|
| 33 |
def transcribe_audio(audio_path):
|
|
|
|
| 44 |
file_context = ""
|
| 45 |
if file_path:
|
| 46 |
content = extract_text(file_path)
|
| 47 |
+
file_context = f"\n[CV Content]:\n{content[:50000]}"
|
|
|
|
| 48 |
|
| 49 |
+
# Language Guard: Ensuring AI mirrors the user's language choice
|
| 50 |
+
combined_input = f"Strict Rule: Respond in the EXACT same language as the user input.\nUser Text: {user_text}\nVoice: {voice_content}\n{file_context}".strip()
|
| 51 |
|
| 52 |
+
# Using Llama 3.3 for high accuracy and Llama 3.1 8b for lightning speed
|
| 53 |
models = ["llama-3.3-70b-versatile", "llama-3.1-8b-instant"]
|
| 54 |
|
| 55 |
success = False
|
| 56 |
for model_name in models:
|
| 57 |
try:
|
| 58 |
client = get_client()
|
|
|
|
|
|
|
|
|
|
| 59 |
response = client.chat.completions.create(
|
| 60 |
model=model_name,
|
| 61 |
+
messages=[{"role": "system", "content": system_role}, {"role": "user", "content": combined_input}],
|
| 62 |
stream=True,
|
| 63 |
+
temperature=0.5,
|
| 64 |
+
max_tokens=4000
|
| 65 |
)
|
| 66 |
|
| 67 |
partial_text = ""
|
|
|
|
| 74 |
except Exception: continue
|
| 75 |
|
| 76 |
if not success:
|
| 77 |
+
yield "### β οΈ Re-connecting... Please click the button again."
|
| 78 |
|
| 79 |
# ==========================================
|
| 80 |
+
# 2. PROMPTS (FIXED LOGIC FOR ORBIT & PATH)
|
| 81 |
# ==========================================
|
| 82 |
+
NEXUS_PROMPT = "Nexus Bot: 1. Define Dream Company/Job & Benefits. 2. Summary of User's CV. 3. Strengths, Weaknesses, and Skill Matrix based on CV."
|
| 83 |
+
ZEN_PROMPT = "Zen Bot: Purely motivate the user. Use success stories of Jack Ma/Steve Jobs. Tell them to keep working hard. No other tasks."
|
| 84 |
+
ORBIT_PROMPT = "Orbit Bot: 1. Define Dream Job/Company & Benefits/Salary. 2. 6-Month Roadmap (1-2, 3-4, 5-6) with clickable links to resources to fix weaknesses."
|
| 85 |
+
PATH_PROMPT = "Pathfinder Bot: 1. Identify 5-10 Companies/Industries suitable for the user's specific CV. 2. Provide direct Career Links and Apply Strategy."
|
| 86 |
|
| 87 |
# ==========================================
|
| 88 |
+
# 3. UI DESIGN (ORIGINAL BACKGROUND RESTORED)
|
| 89 |
# ==========================================
|
| 90 |
custom_css = """
|
| 91 |
footer {display: none !important;}
|
| 92 |
+
.gradio-container { background: linear-gradient(135deg, #0a0a2e 0%, #1a1a4b 25%, #4b0082 50%, #800080 75%, #ff007f 100%) !important; background-attachment: fixed !important;}
|
| 93 |
+
.glass-panel { background: rgba(10, 10, 30, 0.85) !important; backdrop-filter: blur(20px); border: 2px solid #ff007f; border-radius: 20px; padding: 25px; color: white !important; }
|
| 94 |
+
.shimmer-title { font-size: 3.5rem; font-weight: 900; color: white; text-shadow: 0 0 20px #ff007f; text-align: center; margin-bottom: 0px; }
|
| 95 |
+
.new-tagline { font-size: 1rem; color: #00f2fe; text-align: center; letter-spacing: 5px; margin-bottom: 20px; }
|
| 96 |
+
input, textarea { background: #1a1a4b !important; color: white !important; border: 1px solid #ff007f !important; }
|
| 97 |
+
.gr-button-primary { background: linear-gradient(90deg, #ff007f, #800080) !important; border: none !important; }
|
|
|
|
|
|
|
|
|
|
| 98 |
"""
|
| 99 |
|
| 100 |
with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
|
| 101 |
+
gr.HTML("<h1 class='shimmer-title'>AURAPATH AI</h1><p class='new-tagline'>ENGINEERING YOUR DESTINY</p>")
|
| 102 |
+
|
| 103 |
+
# State management for input persistence across tabs
|
| 104 |
+
target_goal = gr.State("")
|
| 105 |
+
|
| 106 |
with gr.Tabs():
|
| 107 |
with gr.Tab("π Nexus"):
|
| 108 |
with gr.Row():
|
| 109 |
with gr.Column(elem_classes="glass-panel", scale=1):
|
| 110 |
+
f1 = gr.File(label="Upload CV")
|
| 111 |
+
t1 = gr.Textbox(label="Target Goal (Company/Job)", lines=3)
|
| 112 |
+
a1 = gr.Audio(label="Voice Scan", sources=["microphone"], type="filepath")
|
| 113 |
btn1 = gr.Button("INITIATE DEEP AUDIT", variant="primary")
|
| 114 |
with gr.Column(elem_classes="glass-panel", scale=1.5):
|
| 115 |
+
out1 = gr.Markdown("### Technical Audit Results")
|
| 116 |
btn1.click(stream_llm, [gr.State(NEXUS_PROMPT), t1, a1, f1], out1)
|
| 117 |
|
| 118 |
with gr.Tab("π§ Zen"):
|
| 119 |
with gr.Row():
|
| 120 |
with gr.Column(elem_classes="glass-panel", scale=1):
|
| 121 |
+
a2 = gr.Audio(label="Voice Log", sources=["microphone"], type="filepath")
|
| 122 |
btn2 = gr.Button("ACTIVATE ZEN POWER", variant="primary")
|
| 123 |
with gr.Column(elem_classes="glass-panel", scale=1.5):
|
| 124 |
+
out2 = gr.Markdown("### Vision Protocol")
|
| 125 |
btn2.click(stream_llm, [gr.State(ZEN_PROMPT), t1, a2, f1], out2)
|
| 126 |
|
| 127 |
with gr.Tab("π
Orbit"):
|
| 128 |
with gr.Row():
|
| 129 |
with gr.Column(elem_classes="glass-panel", scale=1):
|
| 130 |
+
a3 = gr.Audio(label="Voice Command", sources=["microphone"], type="filepath")
|
| 131 |
btn3 = gr.Button("LAUNCH MASTER PLAN", variant="primary")
|
| 132 |
with gr.Column(elem_classes="glass-panel", scale=1.5):
|
| 133 |
+
out3 = gr.Markdown("### Strategic Roadmap")
|
| 134 |
btn3.click(stream_llm, [gr.State(ORBIT_PROMPT), t1, a3, f1], out3)
|
| 135 |
|
| 136 |
with gr.Tab("π― Pathfinder"):
|
| 137 |
with gr.Row():
|
| 138 |
with gr.Column(elem_classes="glass-panel", scale=1):
|
| 139 |
+
a_p = gr.Audio(label="Voice Command", sources=["microphone"], type="filepath")
|
| 140 |
btn_p = gr.Button("FIND MY INDUSTRY MATCH", variant="primary")
|
| 141 |
with gr.Column(elem_classes="glass-panel", scale=1.5):
|
| 142 |
+
out_p = gr.Markdown("### Company & Industry Scout")
|
| 143 |
btn_p.click(stream_llm, [gr.State(PATH_PROMPT), t1, a_p, f1], out_p)
|
| 144 |
|
| 145 |
if __name__ == "__main__":
|