Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,139 +1,116 @@
|
|
| 1 |
-
import
|
| 2 |
-
|
| 3 |
-
import
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
current_question = st.session_state['current_question']
|
| 118 |
-
if current_question < st.session_state['total_questions']:
|
| 119 |
-
st.write(f"Question {current_question + 1}: {st.session_state['questions'][current_question]}")
|
| 120 |
-
|
| 121 |
-
if not st.session_state['question_answered']:
|
| 122 |
-
answer = st.text_area("Your Answer:", key=f"answer_{current_question}")
|
| 123 |
-
if st.button("Submit Answer"):
|
| 124 |
-
if answer:
|
| 125 |
-
st.session_state['answers'].append(answer)
|
| 126 |
-
score, feedback = evaluate_answer(st.session_state['questions'][current_question], answer)
|
| 127 |
-
st.session_state['scores'].append(score)
|
| 128 |
-
st.session_state['feedback'].append(feedback)
|
| 129 |
-
st.session_state['question_answered'] = True
|
| 130 |
-
st.write(f"Score: {score}")
|
| 131 |
-
st.write(f"Feedback: {feedback}")
|
| 132 |
-
|
| 133 |
-
if st.session_state['question_answered']:
|
| 134 |
-
if st.button("Next Question"):
|
| 135 |
-
st.session_state['current_question'] += 1
|
| 136 |
-
st.session_state['question_answered'] = False
|
| 137 |
-
else:
|
| 138 |
-
st.write("Interview Complete! Generating Report...")
|
| 139 |
-
generate_report()
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import logging
|
| 3 |
+
from linkedin_jobs_scraper import LinkedinScraper
|
| 4 |
+
from linkedin_jobs_scraper.events import Events, EventData, EventMetrics
|
| 5 |
+
from linkedin_jobs_scraper.query import Query, QueryOptions, QueryFilters
|
| 6 |
+
from linkedin_jobs_scraper.filters import RelevanceFilters, TimeFilters, OnSiteOrRemoteFilters
|
| 7 |
+
import pandas as pd
|
| 8 |
+
|
| 9 |
+
# Configure logging
|
| 10 |
+
logging.basicConfig(filename="job_scraper.log", level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
|
| 11 |
+
|
| 12 |
+
# Initialize job data storage
|
| 13 |
+
job_data = []
|
| 14 |
+
|
| 15 |
+
# Event Handlers
|
| 16 |
+
def on_data(data: EventData):
|
| 17 |
+
job_data.append({
|
| 18 |
+
'Date Posted': data.date,
|
| 19 |
+
'Title': data.title,
|
| 20 |
+
'Company': data.company,
|
| 21 |
+
'Location': data.location,
|
| 22 |
+
'Job Link': data.link,
|
| 23 |
+
'Description Length': len(data.description),
|
| 24 |
+
'Description': data.description,
|
| 25 |
+
})
|
| 26 |
+
|
| 27 |
+
def on_end():
|
| 28 |
+
logging.info("[ON_END] Scraping completed.")
|
| 29 |
+
|
| 30 |
+
# Scraper function
|
| 31 |
+
def scrape_jobs(query, locations, time_filter):
|
| 32 |
+
global job_data
|
| 33 |
+
try:
|
| 34 |
+
job_data = []
|
| 35 |
+
|
| 36 |
+
scraper = LinkedinScraper(
|
| 37 |
+
chrome_executable_path=None,
|
| 38 |
+
chrome_binary_location=None,
|
| 39 |
+
chrome_options=None,
|
| 40 |
+
headless=True,
|
| 41 |
+
max_workers=5,
|
| 42 |
+
slow_mo=0.8,
|
| 43 |
+
page_load_timeout=100,
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
scraper.on(Events.DATA, on_data)
|
| 47 |
+
scraper.on(Events.END, on_end)
|
| 48 |
+
|
| 49 |
+
if time_filter == "From Past Month":
|
| 50 |
+
time_filter = TimeFilters.MONTH
|
| 51 |
+
elif time_filter == "From Last 24 Hours":
|
| 52 |
+
time_filter = TimeFilters.DAY
|
| 53 |
+
else:
|
| 54 |
+
time_filter = TimeFilters.MONTH
|
| 55 |
+
|
| 56 |
+
queries = [
|
| 57 |
+
Query(
|
| 58 |
+
query=query,
|
| 59 |
+
options=QueryOptions(
|
| 60 |
+
locations=locations.split(','),
|
| 61 |
+
apply_link=True,
|
| 62 |
+
skip_promoted_jobs=False,
|
| 63 |
+
page_offset=0,
|
| 64 |
+
limit=100,
|
| 65 |
+
filters=QueryFilters(
|
| 66 |
+
# relevance=RelevanceFilters.RECENT,
|
| 67 |
+
time=time_filter,
|
| 68 |
+
),
|
| 69 |
+
),
|
| 70 |
+
),
|
| 71 |
+
]
|
| 72 |
+
|
| 73 |
+
scraper.run(queries)
|
| 74 |
+
|
| 75 |
+
if job_data:
|
| 76 |
+
df = pd.DataFrame(job_data)
|
| 77 |
+
message = f"Jobs ({len(job_data)}) data successfully scraped."
|
| 78 |
+
logging.info(message)
|
| 79 |
+
return df, message
|
| 80 |
+
else:
|
| 81 |
+
logging.warning("No job data found.")
|
| 82 |
+
return pd.DataFrame(), 'No jobs found.'
|
| 83 |
+
|
| 84 |
+
except Exception as e:
|
| 85 |
+
# Handle specific exceptions and log detailed information
|
| 86 |
+
logging.error(f"An error occurred during scraping: {e}", exc_info=True)
|
| 87 |
+
message = f"An error occurred during scraping: {e}. Please check the logs for more details."
|
| 88 |
+
return None, message
|
| 89 |
+
|
| 90 |
+
def gradio_interface(query, locations, time_filter):
|
| 91 |
+
df, message = scrape_jobs(query, locations, time_filter)
|
| 92 |
+
return df, message
|
| 93 |
+
|
| 94 |
+
# App Layout
|
| 95 |
+
iface = gr.Interface(
|
| 96 |
+
fn=gradio_interface,
|
| 97 |
+
inputs=[
|
| 98 |
+
gr.Textbox(label="Job Query", placeholder="e.g., Data Scientist", value="Blockchain developers"),
|
| 99 |
+
gr.Textbox(label="Locations (comma-separated)", placeholder="e.g., United States, India", value="United States, United Kingdom, India"),
|
| 100 |
+
gr.Dropdown(
|
| 101 |
+
label="Time Filter",
|
| 102 |
+
choices=["From Past Month", "From Last 24 Hours"],
|
| 103 |
+
value="From Last 24 Hours", # Default option
|
| 104 |
+
type="value",
|
| 105 |
+
),
|
| 106 |
+
],
|
| 107 |
+
outputs=[
|
| 108 |
+
gr.Dataframe(label="Job Results", headers=['Date','Company', 'ApplyLink'], interactive=True),
|
| 109 |
+
gr.Textbox(label="Message"),
|
| 110 |
+
],
|
| 111 |
+
title="Job Scraper",
|
| 112 |
+
description="Enter a job query and locations to scrape job postings and display the results in a table.",
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
if __name__ == "__main__":
|
| 116 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|