CoolFace
Apppublic

mustfa-i7/NextStepAI

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
app.py83 linesDownload Raw Back to root
1import gradio as gr2import requests3import os4from docx import Document5 6def generate_advice(field, skills):7    groq_api_key = os.environ.get("groq_practice")8    if not groq_api_key:9        return "❌ Error: GROQ_API_KEY not found in environment variables."10 11    prompt = f"""12You are a professional career advisor and AI mentor.13A user wants to become a "{field}" and currently knows these skills:14{skills}15Provide detailed advice covering:161. What is this field about?172. The current and future scope of this field.183. How can the user leverage AI tools to get ahead? Name specific AI tools or models relevant, Detail on how to use these AI.194. List the required skills and subskills for this field, categorizing them as:20   - Required (must-have)21   - Good to have (nice-to-have)22   Provide detailed explanations for each skill and subskill.235. How to prepare for interviews and get hired in this field.246. What to expect from the job and career growth.25Format your response clearly with headings and bullet points for readability.26Be encouraging and motivational.27"""28 29    response = requests.post(30        "https://api.groq.com/openai/v1/chat/completions",31        headers={32            "Authorization": f"Bearer {groq_api_key}",33            "Content-Type": "application/json",34        },35        json={36            "model": "llama3-70b-8192",37            "messages": [{"role": "user", "content": prompt}],38            "temperature": 0.739        }40    )41 42    if response.status_code != 200:43        return f"❌ API Error: {response.status_code}\n{response.text}"44 45    try:46        return response.json()["choices"][0]["message"]["content"]47    except Exception as e:48        return f"❌ Parsing Error: {str(e)}\nResponse: {response.text}"49 50def create_docx(text):51    path = "/tmp/advice.docx"52    doc = Document()53    doc.add_heading("🚀 AI Career Advice", level=1)54    doc.add_paragraph(text)55    doc.save(path)56    return path57 58def on_generate(field, skills):59    return generate_advice(field, skills)60 61def on_download(advice_text):62    if not advice_text:63        return None64    return create_docx(advice_text)65 66with gr.Blocks() as app:67    gr.Markdown("# 🚀 AI Career Mentor")68    gr.Markdown("Enter your target field and your current skills to get detailed career guidance.")69 70    field_input = gr.Textbox(label="🎯 Target Field / Job Role", placeholder="e.g. Data Scientist")71    skills_input = gr.Textbox(label="🛠️ Skills You Currently Have", placeholder="e.g. Python, SQL, Statistics")72 73    advice_output = gr.Textbox(label="💡 Career Advice", lines=25, interactive=False)74 75    generate_btn = gr.Button("Get Advice")76    download_btn = gr.Button("Download Advice as DOCX")77    download_file = gr.File(label="Download File")78 79    generate_btn.click(fn=on_generate, inputs=[field_input, skills_input], outputs=advice_output)80    download_btn.click(fn=on_download, inputs=advice_output, outputs=download_file)81 82app.launch()83