Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,32 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
from openai import OpenAI
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# ==========================================
|
| 6 |
-
#
|
| 7 |
# ==========================================
|
| 8 |
def get_client():
|
| 9 |
api_key = os.environ.get("GROQ_API_KEY")
|
| 10 |
return OpenAI(api_key=api_key, base_url="https://api.groq.com/openai/v1")
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
def transcribe_audio(audio_path):
|
| 13 |
if audio_path is None: return ""
|
| 14 |
try:
|
|
@@ -16,157 +34,74 @@ def transcribe_audio(audio_path):
|
|
| 16 |
with open(audio_path, "rb") as audio_file:
|
| 17 |
transcript = client.audio.transcriptions.create(model="whisper-large-v3", file=audio_file)
|
| 18 |
return transcript.text
|
| 19 |
-
except
|
| 20 |
|
| 21 |
-
def stream_llm(system_role, user_text, audio_path
|
| 22 |
-
voice_content = transcribe_audio(audio_path)
|
| 23 |
-
|
|
|
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
if not combined_input and not file_path:
|
| 28 |
-
yield "### ⚠️ Attention Required\nPlease upload your CV in the Nexus tab or state your query."
|
| 29 |
-
return
|
| 30 |
-
|
| 31 |
-
# LIST OF MODELS TO PREVENT 429 ERRORS[cite: 1, 3]
|
| 32 |
-
models_to_try = ["llama-3.3-70b-versatile", "llama-3.1-8b-instant"]
|
| 33 |
|
| 34 |
-
# UNIVERSAL LANGUAGE MIRRORING GUARD[cite: 1]
|
| 35 |
-
detail_cmd = """
|
| 36 |
-
\n\nCRITICAL SYSTEM RULES:
|
| 37 |
-
1. STRICT LANGUAGE MATCH: Identify the input language (English, Urdu, or Roman-Urdu) and respond ONLY in that exact language. NO SWITCHING.
|
| 38 |
-
2. HIGH-QUALITY VOICE: Professional, human, and empathetic tone.
|
| 39 |
-
3. EXTREME DETAIL: Structure with bold headings (###).
|
| 40 |
-
4. CLICKABLE RESOURCES: Include 5-10 specific clickable links.
|
| 41 |
-
"""
|
| 42 |
-
|
| 43 |
client = get_client()
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
],
|
| 54 |
-
stream=True,
|
| 55 |
-
temperature=0.75
|
| 56 |
-
)
|
| 57 |
-
|
| 58 |
-
partial_text = ""
|
| 59 |
-
for chunk in response:
|
| 60 |
-
if chunk.choices[0].delta.content is not None:
|
| 61 |
-
partial_text += chunk.choices[0].delta.content
|
| 62 |
-
yield partial_text
|
| 63 |
-
success = True
|
| 64 |
-
break
|
| 65 |
-
except Exception as e:
|
| 66 |
-
if "429" in str(e): # Switch to next model if rate limit reached[cite: 3]
|
| 67 |
-
continue
|
| 68 |
-
else:
|
| 69 |
-
yield f"### ⚠️ Connection Error\n{str(e)}"
|
| 70 |
-
return
|
| 71 |
-
|
| 72 |
-
if not success:
|
| 73 |
-
yield "### ⚠️ Servers Overloaded\nPlease try again in a few minutes."
|
| 74 |
|
| 75 |
# ==========================================
|
| 76 |
-
#
|
| 77 |
# ==========================================
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
ZEN_PROMPT = """You are a Master Motivational Strategist.
|
| 83 |
-
STRICT LIMITATION: Your ONLY role is to encourage and motivate. Do not perform any other task.
|
| 84 |
-
CORE MESSAGE: Remind the user that failure is natural.
|
| 85 |
-
MANDATORY EXAMPLES: Always include real-life examples of leaders like Steve Jobs, Elon Musk, and Jack Ma. Respond ONLY in user's input language."""
|
| 86 |
-
|
| 87 |
-
ORBIT_PROMPT = """You are a Lead Hiring Strategist. Create a 6-Month Roadmap (Month 1-2: Skill Gaps, Month 3-4: Projects, Month 5: Branding, Month 6: Applications). Respond ONLY in user's input language."""
|
| 88 |
-
|
| 89 |
-
# PATHFINDER: STRICT LANGUAGE REINFORCEMENT[cite: 1, 3]
|
| 90 |
-
PATH_PROMPT = """You are a Global Market Scout.
|
| 91 |
-
STRICT RULE: Detect the user's language and respond EXCLUSIVELY in that language. If the user asks in English, respond in English. If they use Roman-Urdu, respond in Roman-Urdu.
|
| 92 |
-
TASK: Identify Industry and Companies where the user fits perfectly based on their skills."""
|
| 93 |
|
| 94 |
# ==========================================
|
| 95 |
-
#
|
| 96 |
# ==========================================
|
| 97 |
-
|
| 98 |
-
footer {display: none !important;}
|
| 99 |
-
body { margin: 0; padding: 0; }
|
| 100 |
-
.gradio-container {
|
| 101 |
-
background: linear-gradient(135deg, #0a0a2e 0%, #1a1a4b 25%, #4b0082 50%, #800080 75%, #ff007f 100%) !important;
|
| 102 |
-
background-attachment: fixed !important;
|
| 103 |
-
background-size: cover !important;
|
| 104 |
-
min-height: 100vh !important;
|
| 105 |
-
}
|
| 106 |
-
.glass-panel { background: rgba(10, 10, 30, 0.88) !important; backdrop-filter: blur(25px); border: 1px solid rgba(0, 242, 254, 0.3); border-radius: 20px; padding: 25px; height: fit-content; }
|
| 107 |
-
.shimmer-title {
|
| 108 |
-
font-size: 4rem; font-weight: 900; color: #ffffff; text-transform: uppercase;
|
| 109 |
-
text-shadow: 0 0 10px #ff007f, 0 0 20px #ff007f, 0 0 40px #00f2fe;
|
| 110 |
-
animation: pulse-glow 2s ease-in-out infinite alternate; letter-spacing: 5px; margin-bottom: 0px;
|
| 111 |
-
}
|
| 112 |
-
@keyframes pulse-glow {
|
| 113 |
-
from { text-shadow: 0 0 10px #ff007f, 0 0 20px #ff007f, 0 0 40px #00f2fe; transform: scale(1); }
|
| 114 |
-
to { text-shadow: 0 0 20px #00f2fe, 0 0 40px #ff007f, 0 0 60px #00f2fe; transform: scale(1.02); }
|
| 115 |
-
}
|
| 116 |
-
.new-tagline { font-size: 1.1rem; color: #00f2fe; font-weight: bold; letter-spacing: 8px; text-transform: uppercase; margin-top: -10px; opacity: 0.9; }
|
| 117 |
-
.gr-button-primary { background: linear-gradient(90deg, #00f2fe 0%, #ff007f 100%) !important; border: none !important; font-weight: bold !important; }
|
| 118 |
-
input, textarea { background: rgba(0, 0, 0, 0.7) !important; color: white !important; border: 1px solid #00f2fe !important; }
|
| 119 |
-
"""
|
| 120 |
-
|
| 121 |
-
with gr.Blocks(css=custom_css) as demo:
|
| 122 |
-
gr.HTML("""
|
| 123 |
-
<div style="text-align: center; padding: 30px 10px;">
|
| 124 |
-
<h1 class="shimmer-title">AURAPATH AI</h1>
|
| 125 |
-
<p class="new-tagline">◈ ENGINEERING YOUR DESTINY ◈</p>
|
| 126 |
-
</div>
|
| 127 |
-
""")
|
| 128 |
-
|
| 129 |
with gr.Tabs():
|
| 130 |
-
with gr.Tab("
|
| 131 |
with gr.Row():
|
| 132 |
-
with gr.Column(
|
| 133 |
f1 = gr.File(label="Upload CV / Portfolio")
|
| 134 |
-
t1 = gr.Textbox(label="TARGET GOAL", placeholder="e.g. AI Developer..."
|
| 135 |
-
a1 = gr.Audio(label="VOICE SCAN",
|
| 136 |
-
btn1 = gr.Button("INITIATE DEEP AUDIT"
|
| 137 |
-
with gr.Column(
|
| 138 |
-
out1 = gr.Markdown("
|
| 139 |
btn1.click(stream_llm, [gr.State(NEXUS_PROMPT), t1, a1, f1], out1)
|
| 140 |
|
| 141 |
-
with gr.Tab("
|
| 142 |
with gr.Row():
|
| 143 |
-
with gr.Column(
|
| 144 |
-
gr.
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
out2 = gr.Markdown("### 🔥 High-Intensity Vision Protocol")
|
| 149 |
-
btn2.click(stream_llm, [gr.State(ZEN_PROMPT), t1, a2, f1], out2)
|
| 150 |
|
| 151 |
-
with gr.Tab("
|
| 152 |
with gr.Row():
|
| 153 |
-
with gr.Column(
|
| 154 |
-
gr.
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
out3 = gr.Markdown("### 🛣️ 6-Month Strategic Execution Roadmap")
|
| 159 |
-
btn3.click(stream_llm, [gr.State(ORBIT_PROMPT), t1, a3, f1], out3)
|
| 160 |
|
| 161 |
-
with gr.Tab("
|
| 162 |
with gr.Row():
|
| 163 |
-
with gr.Column(
|
| 164 |
-
gr.
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
out_p = gr.Markdown("### 🏢 Skill-Based Industry & Company Match")
|
| 169 |
-
btn_p.click(stream_llm, [gr.State(PATH_PROMPT), t1, a_p, f1], out_p)
|
| 170 |
|
| 171 |
if __name__ == "__main__":
|
| 172 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
from openai import OpenAI
|
| 4 |
+
import PyPDF2
|
| 5 |
+
from docx import Document
|
| 6 |
|
| 7 |
# ==========================================
|
| 8 |
+
# CORE LOGIC (Updated functionality)
|
| 9 |
# ==========================================
|
| 10 |
def get_client():
|
| 11 |
api_key = os.environ.get("GROQ_API_KEY")
|
| 12 |
return OpenAI(api_key=api_key, base_url="https://api.groq.com/openai/v1")
|
| 13 |
|
| 14 |
+
def extract_text(file_path):
|
| 15 |
+
if not file_path: return ""
|
| 16 |
+
text = ""
|
| 17 |
+
try:
|
| 18 |
+
if file_path.endswith('.pdf'):
|
| 19 |
+
with open(file_path, 'rb') as f:
|
| 20 |
+
reader = PyPDF2.PdfReader(f)
|
| 21 |
+
for page in reader.pages:
|
| 22 |
+
content = page.extract_text()
|
| 23 |
+
if content: text += content + "\n"
|
| 24 |
+
elif file_path.endswith('.docx'):
|
| 25 |
+
doc = Document(file_path)
|
| 26 |
+
for para in doc.paragraphs: text += para.text + "\n"
|
| 27 |
+
except: return "Could not parse file."
|
| 28 |
+
return text
|
| 29 |
+
|
| 30 |
def transcribe_audio(audio_path):
|
| 31 |
if audio_path is None: return ""
|
| 32 |
try:
|
|
|
|
| 34 |
with open(audio_path, "rb") as audio_file:
|
| 35 |
transcript = client.audio.transcriptions.create(model="whisper-large-v3", file=audio_file)
|
| 36 |
return transcript.text
|
| 37 |
+
except: return ""
|
| 38 |
|
| 39 |
+
def stream_llm(system_role, user_text, audio_path, file_path):
|
| 40 |
+
voice_content = transcribe_audio(audio_path)
|
| 41 |
+
file_content = extract_text(file_path)
|
| 42 |
+
combined_input = f"User Request: {user_text}\nVoice: {voice_content}\nDocument: {file_content}"
|
| 43 |
|
| 44 |
+
# Updated System Rules
|
| 45 |
+
full_prompt = f"{system_role}\n\nRULES: 1. Respond in the exact language of user input. 2. Include 5-10 clickable links. 3. Use bold headings."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
client = get_client()
|
| 48 |
+
try:
|
| 49 |
+
stream = client.chat.completions.create(
|
| 50 |
+
model="llama-3.3-70b-versatile",
|
| 51 |
+
messages=[{"role": "system", "content": full_prompt}, {"role": "user", "content": combined_input}],
|
| 52 |
+
stream=True
|
| 53 |
+
)
|
| 54 |
+
for chunk in stream:
|
| 55 |
+
if chunk.choices[0].delta.content: yield chunk.choices[0].delta.content
|
| 56 |
+
except Exception as e: yield f"Error: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
# ==========================================
|
| 59 |
+
# PROMPTS
|
| 60 |
# ==========================================
|
| 61 |
+
NEXUS_PROMPT = "You are a CV Auditor. Analyze the CV (up to 6 pages), provide a skill matrix, and actionable feedback with 5-10 clickable links."
|
| 62 |
+
ZEN_PROMPT = "You are a Mentor. Provide 7 distinct success stories of leaders who failed before succeeding. Focus on their journey. Include links."
|
| 63 |
+
ORBIT_PROMPT = "You are a Career Strategist. Provide a detailed 6-month roadmap with weekly milestones and 10 clickable learning resources."
|
| 64 |
+
PATH_PROMPT = "You are a Hiring Expert. Recommend companies based on skills, and provide a clear step-by-step application guide with links."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
# ==========================================
|
| 67 |
+
# UI (Matching your Sidebar Layout)
|
| 68 |
# ==========================================
|
| 69 |
+
with gr.Blocks() as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
with gr.Tabs():
|
| 71 |
+
with gr.Tab("Nexus"):
|
| 72 |
with gr.Row():
|
| 73 |
+
with gr.Column(scale=1):
|
| 74 |
f1 = gr.File(label="Upload CV / Portfolio")
|
| 75 |
+
t1 = gr.Textbox(label="TARGET GOAL", placeholder="e.g. AI Developer...")
|
| 76 |
+
a1 = gr.Audio(label="VOICE SCAN", type="filepath")
|
| 77 |
+
btn1 = gr.Button("INITIATE DEEP AUDIT")
|
| 78 |
+
with gr.Column(scale=2):
|
| 79 |
+
out1 = gr.Markdown(label="Technical Audit & Skill Matrix")
|
| 80 |
btn1.click(stream_llm, [gr.State(NEXUS_PROMPT), t1, a1, f1], out1)
|
| 81 |
|
| 82 |
+
with gr.Tab("Zen"):
|
| 83 |
with gr.Row():
|
| 84 |
+
with gr.Column(scale=1):
|
| 85 |
+
btn2 = gr.Button("GET MOTIVATED")
|
| 86 |
+
with gr.Column(scale=2):
|
| 87 |
+
out2 = gr.Markdown()
|
| 88 |
+
btn2.click(stream_llm, [gr.State(ZEN_PROMPT), t1, a1, f1], out2)
|
|
|
|
|
|
|
| 89 |
|
| 90 |
+
with gr.Tab("Orbit"):
|
| 91 |
with gr.Row():
|
| 92 |
+
with gr.Column(scale=1):
|
| 93 |
+
btn3 = gr.Button("CREATE ROADMAP")
|
| 94 |
+
with gr.Column(scale=2):
|
| 95 |
+
out3 = gr.Markdown()
|
| 96 |
+
btn3.click(stream_llm, [gr.State(ORBIT_PROMPT), t1, a1, f1], out3)
|
|
|
|
|
|
|
| 97 |
|
| 98 |
+
with gr.Tab("Pathfinder"):
|
| 99 |
with gr.Row():
|
| 100 |
+
with gr.Column(scale=1):
|
| 101 |
+
btn4 = gr.Button("FIND MY MATCH")
|
| 102 |
+
with gr.Column(scale=2):
|
| 103 |
+
out4 = gr.Markdown()
|
| 104 |
+
btn4.click(stream_llm, [gr.State(PATH_PROMPT), t1, a1, f1], out4)
|
|
|
|
|
|
|
| 105 |
|
| 106 |
if __name__ == "__main__":
|
| 107 |
demo.launch()
|