Spaces:
Running
Running
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,127 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import os
|
| 3 |
-
from openai import OpenAI
|
| 4 |
-
import PyPDF2
|
| 5 |
-
from docx import Document
|
| 6 |
-
|
| 7 |
-
# ==========================================
|
| 8 |
-
# 1. CORE ENGINE (UPDATED)
|
| 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 "Error reading file."
|
| 28 |
-
return text
|
| 29 |
-
|
| 30 |
-
def transcribe_audio(audio_path):
|
| 31 |
-
if audio_path is None: return ""
|
| 32 |
-
try:
|
| 33 |
-
client = get_client()
|
| 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 |
-
|
| 43 |
-
combined_input = f"User Request: {user_text}\nVoice Input: {voice_content}\nDocument Content: {file_content}"
|
| 44 |
-
|
| 45 |
-
# SYSTEM RULES UPDATED FOR LANGUAGE AND LINKS
|
| 46 |
-
system_rules = f"""
|
| 47 |
-
{system_role}
|
| 48 |
-
CRITICAL RULES:
|
| 49 |
-
1. LANGUAGE: You MUST identify the language of the user input and respond EXCLUSIVELY in that same language.
|
| 50 |
-
2. LINKS: Provide 5-10 active, clickable links to relevant resources, companies, or guides.
|
| 51 |
-
3. STRUCTURE: Use bold headings (###) for clarity.
|
| 52 |
-
"""
|
| 53 |
-
|
| 54 |
-
client = get_client()
|
| 55 |
-
models_to_try = ["llama-3.3-70b-versatile", "llama-3.1-8b-instant"]
|
| 56 |
-
|
| 57 |
-
for model_name in models_to_try:
|
| 58 |
-
try:
|
| 59 |
-
response = client.chat.completions.create(
|
| 60 |
-
model=model_name,
|
| 61 |
-
messages=[{"role": "system", "content": system_rules}, {"role": "user", "content": combined_input}],
|
| 62 |
-
stream=True, temperature=0.7
|
| 63 |
-
)
|
| 64 |
-
for chunk in response:
|
| 65 |
-
if chunk.choices[0].delta.content:
|
| 66 |
-
yield chunk.choices[0].delta.content
|
| 67 |
-
return
|
| 68 |
-
except: continue
|
| 69 |
-
yield "### β οΈ Error\nService busy. Please try again."
|
| 70 |
-
|
| 71 |
-
# ==========================================
|
| 72 |
-
# 2. PROMPTS (UPDATED)
|
| 73 |
-
# ==========================================
|
| 74 |
-
NEXUS_PROMPT = "You are a Technical CV Auditor. Analyze the CV (up to 6 pages) thoroughly for strengths/weaknesses and provide a skill matrix with clickable learning links."
|
| 75 |
-
ZEN_PROMPT = "You are a Motivational Strategist. Provide 7 distinct, detailed stories of famous leaders (e.g., Steve Jobs, Elon Musk, Jack Ma, Oprah, etc.) who failed significantly before finding massive success. Focus on the 'failure-to-success' journey. Use user's language."
|
| 76 |
-
ORBIT_PROMPT = "You are a Career Strategist. Create a detailed 6-month step-by-step roadmap for the user's career goal. Include specific tasks, learning milestones, and provide 10 clickable links for resources per month."
|
| 77 |
-
PATH_PROMPT = "You are a Hiring Expert. Analyze the user's CV, identify perfectly matching companies, and provide a step-by-step guide on how to apply (with career page links)."
|
| 78 |
-
|
| 79 |
-
# ==========================================
|
| 80 |
-
# 3. UI (PRESERVED AS PER YOUR ORIGINAL CODE)
|
| 81 |
-
# ==========================================
|
| 82 |
-
custom_css = """
|
| 83 |
-
footer {display: none !important;}
|
| 84 |
-
body { margin: 0; padding: 0; }
|
| 85 |
-
.gradio-container { background: linear-gradient(135deg, #0a0a2e 0%, #1a1a4b 25%, #4b0082 50%, #800080 75%, #ff007f 100%) !important; background-attachment: fixed !important; min-height: 100vh !important; }
|
| 86 |
-
.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; }
|
| 87 |
-
.shimmer-title { font-size: 4rem; font-weight: 900; color: #ffffff; text-shadow: 0 0 10px #ff007f, 0 0 40px #00f2fe; }
|
| 88 |
-
.new-tagline { font-size: 1.1rem; color: #00f2fe; font-weight: bold; }
|
| 89 |
-
.gr-button-primary { background: linear-gradient(90deg, #00f2fe 0%, #ff007f 100%) !important; }
|
| 90 |
-
"""
|
| 91 |
-
|
| 92 |
-
with gr.Blocks(css=custom_css) as demo:
|
| 93 |
-
gr.HTML("<div style='text-align: center;'><h1 class='shimmer-title'>AURAPATH AI</h1><p class='new-tagline'>β ENGINEERING YOUR DESTINY β</p></div>")
|
| 94 |
-
|
| 95 |
-
with gr.Tabs():
|
| 96 |
-
with gr.Tab("π Nexus"):
|
| 97 |
-
with gr.Column(elem_classes="glass-panel"):
|
| 98 |
-
f1 = gr.File(label="Upload CV (Accepts 5-6 pages)")
|
| 99 |
-
t1 = gr.Textbox(label="TARGET GOAL")
|
| 100 |
-
a1 = gr.Audio(label="VOICE SCAN", type="filepath")
|
| 101 |
-
btn1 = gr.Button("INITIATE DEEP AUDIT", variant="primary")
|
| 102 |
-
out1 = gr.Markdown()
|
| 103 |
-
btn1.click(stream_llm, [gr.State(NEXUS_PROMPT), t1, a1, f1], out1)
|
| 104 |
-
|
| 105 |
-
with gr.Tab("π§ Zen"):
|
| 106 |
-
with gr.Column(elem_classes="glass-panel"):
|
| 107 |
-
a2 = gr.Audio(label="VOICE LOG", type="filepath")
|
| 108 |
-
btn2 = gr.Button("ACTIVATE ZEN POWER", variant="primary")
|
| 109 |
-
out2 = gr.Markdown()
|
| 110 |
-
btn2.click(stream_llm, [gr.State(ZEN_PROMPT), t1, a2, f1], out2)
|
| 111 |
-
|
| 112 |
-
with gr.Tab("π
Orbit"):
|
| 113 |
-
with gr.Column(elem_classes="glass-panel"):
|
| 114 |
-
a3 = gr.Audio(label="VOICE COMMAND", type="filepath")
|
| 115 |
-
btn3 = gr.Button("LAUNCH MASTER PLAN", variant="primary")
|
| 116 |
-
out3 = gr.Markdown()
|
| 117 |
-
btn3.click(stream_llm, [gr.State(ORBIT_PROMPT), t1, a3, f1], out3)
|
| 118 |
-
|
| 119 |
-
with gr.Tab("π― Pathfinder"):
|
| 120 |
-
with gr.Column(elem_classes="glass-panel"):
|
| 121 |
-
a_p = gr.Audio(label="VOICE COMMAND", type="filepath")
|
| 122 |
-
btn_p = gr.Button("FIND MY INDUSTRY MATCH", variant="primary")
|
| 123 |
-
out_p = gr.Markdown()
|
| 124 |
-
btn_p.click(stream_llm, [gr.State(PATH_PROMPT), t1, a_p, f1], out_p)
|
| 125 |
-
|
| 126 |
-
if __name__ == "__main__":
|
| 127 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|