engrharis commited on
Commit
178d933
·
verified ·
1 Parent(s): adce2c2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -19
app.py CHANGED
@@ -18,24 +18,39 @@ platforms = {
18
  # App Title
19
  st.title("Job Search Portal")
20
 
21
- # User Inputs
22
  st.subheader("Search for Jobs in Pakistan")
23
- selected_city = st.selectbox("Select your city:", cities)
24
  job_keyword = st.text_input("Enter job title or keywords:")
25
- selected_platform = st.selectbox("Choose the job platform:", list(platforms.keys()))
26
-
27
- # Search Button
28
- if st.button("Search Jobs"):
29
- if not job_keyword.strip():
30
- st.warning("Please enter a job title or keyword.")
31
- else:
32
- # Construct the URL for the selected platform
33
- base_url = platforms[selected_platform]
34
- search_url = base_url.format(job=job_keyword.replace(" ", "+"), city=selected_city)
35
-
36
- # Open the link in a new tab using `webbrowser` module
37
- import webbrowser
38
- webbrowser.open_new_tab(search_url)
39
-
40
- # Optionally, show a success message
41
- st.success(f"Searching jobs on {selected_platform} for '{job_keyword}' in {selected_city}.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  # App Title
19
  st.title("Job Search Portal")
20
 
21
+ # User Inputs (with empty initial selection)
22
  st.subheader("Search for Jobs in Pakistan")
23
+ selected_city = st.selectbox("Select your city:", [""] + cities) # Add empty string
24
  job_keyword = st.text_input("Enter job title or keywords:")
25
+ selected_platform = st.selectbox("Choose the job platform:", [""] + list(platforms.keys())) # Add empty string
26
+
27
+ # Initialize button state
28
+ button_state = "Search Jobs"
29
+
30
+ # Check if all inputs are selected
31
+ if selected_city == "" or job_keyword.strip() == "" or selected_platform == "":
32
+ st.warning("Please select a city, enter a job keyword, and choose a platform.")
33
+ else:
34
+ if st.button(button_state):
35
+ if button_state == "Search Jobs":
36
+ # Construct the URL
37
+ base_url = platforms[selected_platform]
38
+ search_url = base_url.format(job=job_keyword.replace(" ", "+"), city=selected_city)
39
+
40
+ # Change button state
41
+ button_state = "See Jobs"
42
+ st.experimental_rerun() # Force a rerun to update the button
43
+
44
+ elif button_state == "See Jobs":
45
+ # Open the link in a new tab
46
+ base_url = platforms[selected_platform]
47
+ search_url = base_url.format(job=job_keyword.replace(" ", "+"), city=selected_city)
48
+ st.markdown(f'<a href="{search_url}" target="_blank">Open Jobs in New Tab</a>', unsafe_allow_html=True)
49
+
50
+ # Reset button state for new searches.
51
+ button_state = "Search Jobs"
52
+ st.experimental_rerun()
53
+
54
+ # This is a very important line that prevents the session from being saved after the button is clicked.
55
+ if 'button_state' not in st.session_state:
56
+ st.session_state['button_state'] = "Search Jobs"