vsp-demo / src /vsp /app /1st_gradio.py
pquiggles's picture
text
dce75da
import os
# Running the 'ls' command using Python's os module to list files in the current directory
print(os.listdir('/home/user/app'))
import gradio as gr
import nest_asyncio
# Apply nest_asyncio to allow nested event loops
nest_asyncio.apply()
from vsp.app.main import VspDataEnrichment
# Import your custom modules
from vsp.app.scrapers.linkedin_downloader import LinkedinDownloader
async def process_profile(profile_linkedin):
downloader = LinkedinDownloader()
enricher = VspDataEnrichment()
profile = await downloader.fetch_linkedin_data(linkedin_url=profile_linkedin)
enriched_profile = await enricher.process_linkedin_profile(profile=profile)
return enriched_profile
async def analyze_profile(profile_linkedin):
enriched_profile = await process_profile(profile_linkedin)
# Generate output from enriched_profile
education_outputs = []
work_experience_outputs = []
# Process classified educations
for idx, edu in enumerate(enriched_profile.classified_educations, 1):
school = edu.education.school_name
degree = edu.education.degree
year = edu.education.end.year if edu.education.end else "N/A"
classification = edu.classification.output.value
education_outputs.append(
f"### Education {idx}\n"
f"**School:** {school}\n\n"
f"**Degree:** {degree}\n\n"
f"**Year:** {year}\n\n"
f"**Classification:** {classification}\n"
)
# Add total years of full-time work experience
total_experience_years = enriched_profile.full_time_work_experience_years
experience_by_secondary = enriched_profile.full_time_work_experience_by_secondary
experience_output = f"### Total Full-Time Work Experience: {total_experience_years} years\n\n"
if experience_by_secondary:
experience_output += "### Work Experience by Secondary Job Type:\n"
for secondary_job_type, years in experience_by_secondary.items():
experience_output += f"- {secondary_job_type.value}: {years} years\n"
# Process classified work experiences
for idx, exp in enumerate(enriched_profile.classified_work_experiences, 1):
company = exp.position.company_name
start_year = exp.position.start.year if exp.position.start else "N/A"
end_year = exp.position.end.year if (exp.position.end and exp.position.end.year) else "Present"
time_range = f"{start_year} - {end_year}"
title = exp.position.title
primary_job_type = exp.work_experience_classification.primary_job_type.value
secondary_job_type = exp.work_experience_classification.secondary_job_type.value
work_exp_str = (
f"### Work Experience {idx}\n"
f"**Company:** {company}\n\n"
f"**Time Range:** {time_range}\n\n"
f"**Title:** {title}\n\n"
f"**Primary Job Type:** {primary_job_type}\n\n"
f"**Secondary Job Type:** {secondary_job_type}\n\n"
)
# Investing focus
if exp.investing_focus_asset_class_classification:
asset_class = exp.investing_focus_asset_class_classification.investing_focus_asset_class.value
sector = (
exp.investing_focus_sector_classification.investing_focus_sector.value
if exp.investing_focus_sector_classification
else "N/A"
)
work_exp_str += f"**Investing Focus (Asset Class):** {asset_class}\n\n"
work_exp_str += f"**Investing Focus (Sector):** {sector}\n\n"
# Investment banking classification
if exp.investment_banking_classification:
ib_group = exp.investment_banking_classification.investment_banking_group.value
work_exp_str += f"**Investment Banking Group:** {ib_group}\n"
work_experience_outputs.append(work_exp_str)
# Combine outputs
education_output = "\n\n".join(education_outputs)
work_experience_output = "\n\n".join(work_experience_outputs)
full_output = f"# Classified Educations\n\n{education_output}\n\n# Classified Work Experiences\n\n{experience_output}\n\n{work_experience_output}"
return full_output
def main():
# Define Gradio interface
with gr.Blocks() as demo:
gr.Markdown("# LinkedIn Profile Analyzer")
gr.Markdown("Enter a LinkedIn profile URL to analyze educational and work experiences.")
profile_linkedin = gr.Textbox(label="LinkedIn Profile URL")
analyze_button = gr.Button("Analyze")
output = gr.Markdown()
async def on_analyze_click(profile_linkedin):
if not profile_linkedin:
return "Please enter a valid LinkedIn Profile URL."
try:
result = await analyze_profile(profile_linkedin)
return result
except Exception as e:
return f"An error occurred: {str(e)}"
analyze_button.click(fn=on_analyze_click, inputs=profile_linkedin, outputs=output)
demo.launch()
if __name__ == "__main__":
main()