""" For HF, the interface should be called app.py """ import json import random import concurrent.futures import streamlit as st from backend import paired_critique from utils.process_doc import parse_docx, parse_pdf from utils.gpt import test_api_key, gpt_stream_response_chat_history from utils.format import extract_json, generate_markdown_report st.set_page_config(layout="wide") with st.sidebar: COHERE_API_KEY = st.text_input( "Cohere API Key Entry", value="", placeholder="Enter your Free Tier Cohere API Key", ) if "state" not in st.session_state: st.session_state.state = {"successful_report_flag": True, "paired_report": {}} STATE = st.session_state.state # Weird Hugging Face display issue, padding fixes it st.markdown("\n") st.markdown("\n") st.markdown("\n") cv_upload_box = st.file_uploader( "CV Upload Box", help="Upload your CV in .docx or .pdf form. This CV will be parsed, and used to analyse against the given job post.", type=["docx", "pdf"], accept_multiple_files=False, ) job_posting_upload_box = st.text_area( "Job Description Upload Box", value="""Job description As a Data Scientist at Meta, you will shape the future of people-facing and business-facing products we build across our entire family of applications (Facebook, Instagram, Messenger, WhatsApp, Oculus). By applying your technical skills, analytical mindset, and product intuition to one of the richest data sets in the world, you will help define the experiences we build for billions of people and hundreds of millions of businesses around the world. You will collaborate on a wide array of product and business problems with a diverse set of cross-functional partners across Product, Engineering, Research, Data Engineering, Marketing, Sales, Finance and others. You will use data and analysis to identify and solve product development’s biggest challenges. You will influence product strategy and investment decisions with data, be focused on impact, and collaborate with other teams. By joining Meta, you will become part of a world-class analytics community dedicated to skill development and career growth in analytics and beyond.Product leadership: You will use data to shape product development, quantify new opportunities, identify upcoming challenges, and ensure the products we build bring value to people, businesses, and Meta. You will help your partner teams prioritize what to build, set goals, and understand their product’s ecosystem.Analytics: You will guide teams using data and insights. You will focus on developing hypotheses and employ a diverse toolkit of rigorous analytical approaches, different methodologies, frameworks, and technical approaches to test them.Communication and influence: You won’t simply present data, but tell data-driven stories. You will convince and influence your partners using clear insights and recommendations. You will build credibility through structure and clarity, and be a trusted strategic partner. Data Scientist, Product Analytics Responsibilities: Work with large and complex data sets to solve a wide array of challenging problems using different analytical and statistical approaches. Apply technical expertise with quantitative analysis, experimentation, data mining, and the presentation of data to develop strategies for our products that serve billions of people and hundreds of millions of businesses. Identify and measure success of product efforts through goal setting, forecasting, and monitoring of key product metrics to understand trends. Define, understand, and test opportunities and levers to improve the product, and drive roadmaps through your insights and recommendations. Partner with Product, Engineering, and cross-functional teams to inform, influence, support, and execute product strategy and investment decisions. Minimum Qualifications: A minimum of 6 years of work experience in analytics (minimum of 4 years with a Ph.D.). Bachelor's degree in Mathematics, Statistics, a relevant technical field, or equivalent practical experience. Experience with data querying languages (e.g. SQL), scripting languages (e.g. Python), and/or statistical/mathematical software (e.g. R). Preferred Qualifications: Masters or Ph.D. Degree in a quantitative field. About Meta: Meta builds technologies that help people connect, find communities, and grow businesses. When Facebook launched in 2004, it changed the way people connect. Apps like Messenger, Instagram and WhatsApp further empowered billions around the world. Now, Meta is moving beyond 2D screens toward immersive experiences like augmented and virtual reality to help build the next evolution in social technology. People who choose to build their careers by building with us at Meta help shape a future that will take us beyond what digital connection makes possible today—beyond the constraints of screens, the limits of distance, and even the rules of physics. Individual compensation is determined by skills, qualifications, experience, and location. Compensation details listed in this posting reflect the base hourly rate, monthly rate, or annual salary only, and do not include bonus, equity or sales incentives, if applicable. In addition to base compensation, Meta offers benefits. Learn more about benefits at Meta.""", placeholder="Copy and Paste a job post you are interested in. Make sure to include the full post! More information is better.", help="In this box, please dump text content for a job description you are interested in. This could easily be setup to work directly with a webpage (we'd simply need to scrape said page) however I do not want to do that on HF spaces.", ) if cv_upload_box and job_posting_upload_box != "": STATE["job_posting"] = job_posting_upload_box cv_filetype = cv_upload_box.name.split(".")[-1] cv_file_contents = cv_upload_box.getvalue() STATE["cv"] = ( parse_docx(cv_file_contents) if cv_filetype == "docx" else parse_pdf(cv_file_contents) ) cv_critique, practice_interview, general_cv_critique = st.tabs( ["Role Specific CV Critique", "Practice Interview", "General CV Critique"] ) with cv_critique: produce_report = st.button("Produce Suitability Report") if produce_report: # Make 3 calls in parallel with concurrent.futures.ThreadPoolExecutor() as executor: future1 = executor.submit( paired_critique, STATE["cv"], STATE["job_posting"], "basic", COHERE_API_KEY, ) future2 = executor.submit( paired_critique, STATE["cv"], STATE["job_posting"], "general", COHERE_API_KEY, ) future3 = executor.submit( paired_critique, STATE["cv"], STATE["job_posting"], "specific", COHERE_API_KEY, ) basic_details_out = future1.result() general_details_out = future2.result() specific_details_out = future3.result() # merge the outputs resultsDict = {} for jsonText in [ basic_details_out, general_details_out, specific_details_out, ]: valid_json_flag, output_report_json = extract_json(jsonText) if not valid_json_flag: STATE["successful_report_flag"] = False resultsDict.update(output_report_json) STATE["paired_report"] = resultsDict if STATE["successful_report_flag"] and STATE["paired_report"]: paired_report = STATE["paired_report"] name = paired_report.get("personName", "MissingPersonName") job_title = paired_report.get("jobTitle", "MissingTitle") company_name = paired_report.get("companyName", "MissingCompany") with cv_critique: st.markdown(generate_markdown_report(STATE["paired_report"])) st.download_button( label="Download Report JSON", data=json.dumps(STATE["paired_report"], indent=4), file_name=f"{name}_{job_title}_{company_name}.json", mime="application/json", use_container_width=True, ) # Streaming Chatbot !!! with practice_interview: initial_questions = [ "What do you think is the biggest reason you're unsuitable for the role?", "Why are you interested in this role specifically?", "What do you know about the company?", ] if "messages" not in st.session_state: st.session_state["messages"] = [ {"role": "assistant", "message": random.choice(initial_questions)} ] # Populate the chat with historic messages for msg in st.session_state.messages: st.chat_message(msg["role"]).write(msg["message"]) if prompt := st.chat_input(): st.session_state.messages.append({"role": "user", "message": prompt}) st.chat_message("user").write(prompt) assistant_message = st.chat_message("assistant") response = assistant_message.write_stream( gpt_stream_response_chat_history( st.session_state.messages, background_info={ "cv": STATE["cv"], "job_posting": STATE["job_posting"], }, api_key=COHERE_API_KEY, ) ) st.session_state.messages.append({"role": "assistant", "message": response})