jr98rh commited on
Commit
fd218db
·
verified ·
1 Parent(s): 8c9737a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -74
app.py CHANGED
@@ -1,75 +1,60 @@
1
- import streamlit as st
2
- import numpy as np
3
- import pandas as pd
4
  import joblib
5
- import pickle
6
-
7
- model = pickle.load(open("PycaretGBR.pkl", 'rb'))
8
- # model = joblib.load("lr.joblib")
9
- st.title('Developer Salary Prediction 2024')
10
- st.write("""### We need some information to predict the salary""")
11
-
12
- countries = (
13
- "Australia",
14
- "Austria",
15
- "Belgium",
16
- "Brazil",
17
- "Canada",
18
- "Czech Republic",
19
- "Denmark",
20
- "France",
21
- "Germany",
22
- "India",
23
- "Israel",
24
- "Italy",
25
- "Netherlands",
26
- "Norway",
27
- "Poland",
28
- "Russian Federation",
29
- "Spain",
30
- "Sweden",
31
- "Switzerland",
32
- "Ukraine"
33
- "United Kingdom of Great Britain and Northern Ireland",
34
- "United States of America"
35
- )
36
-
37
- education = (
38
- "Less than a Bachelors",
39
- "Bachelor’s degree",
40
- "Master’s degree",
41
- "Post grad"
42
- )
43
-
44
- employment = (
45
- "Employed, full-time",
46
- "Independent contractor, freelancer, or self-employed",
47
- "Student, part-time",
48
- "Retired",
49
- "Not employed, but looking for work",
50
- "Employed, part-time",
51
- "Student, full-time"
52
- )
53
-
54
- country = st.selectbox("Country", countries)
55
- education = st.selectbox("Education Level", education)
56
- expericence = st.slider("Years of Experience", 0, 50, 3)
57
- employment = st.selectbox("Employment Type", employment)
58
-
59
- columns = ['Country', 'EdLevel', 'YearsCodePro', 'Employment']
60
-
61
- ok = st.button("Calculate Salary")
62
- if ok:
63
- X_new_df = pd.DataFrame([[country,education,expericence,employment]],
64
- columns = ['Country', 'EdLevel', 'YearsCodePro', 'Employment'])
65
- print("##########")
66
- print("##########")
67
- print("##########")
68
- print(model)
69
- print("##########")
70
- print("##########")
71
- print("##########")
72
- salary = model.predict(X_new_df)
73
-
74
- st.subheader(f"The estimated salary is {salary[0]:.2f} $")\
75
-
 
1
+ import requests
 
 
2
  import joblib
3
+ import os
4
+ import pandas as pd
5
+ import gradio as gr
6
+
7
+ HF_TOKEN = os.getenv("HF_TOKEN")
8
+
9
+ countries = [
10
+ "United States of America", "Other", "Germany",
11
+ "United Kingdom of Great Britain and Northern Ireland",
12
+ "India", "Canada", "France", "Brazil", "Spain",
13
+ "Netherlands", "Australia", "Italy", "Poland",
14
+ "Sweden", "Russian Federation", "Switzerland", "Turkey",
15
+ "Israel", "Austria", "Norway", "Portugal", "Denmark",
16
+ "Belgium", "Finland", "Mexico", "New Zealand", "Greece",
17
+ "South Africa", "Pakistan", "Czech Republic",
18
+ "Iran, Islamic Republic of"
19
+ ]
20
+
21
+
22
+ # Hugging Face model details
23
+ #model_url = "https://huggingface.co/hassanshe7/salary_model/resolve/main/salary_model.pkl?download=true"
24
+ model_url = "https://huggingface.co/spaces/hassanshe7/Stackoverflow_salary_prediction/resolve/main/salary_model.pkl?download=true"
25
+ model_path = "salary_model.pkl"
26
+
27
+ # Download model with authentication
28
+ headers = {"Authorization": f"Bearer {HF_TOKEN}"}
29
+ response = requests.get(model_url, headers=headers)
30
+
31
+ if response.status_code == 200:
32
+ with open(model_path, "wb") as f:
33
+ f.write(response.content)
34
+ print("Model downloaded successfully.")
35
+ else:
36
+ print(f"Failed to download model: {response.text}")
37
+ exit(1)
38
+
39
+ # Load the trained model
40
+ model = joblib.load(model_path)
41
+
42
+ # Define prediction function
43
+ def predict_salary(country, education, experience, remote):
44
+ input_data = pd.DataFrame([[country, education, experience, remote]],
45
+ columns=['Country', 'EdLevel', 'YearsCodePro', 'RemoteWork'])
46
+ prediction = model.predict(input_data)[0]
47
+ return f"Estimated Salary: ${round(prediction, 2)}"
48
+
49
+ # Define Gradio app
50
+ inputs = [
51
+ gr.Dropdown(countries, label="Country"),
52
+ gr.Dropdown(["Bachelor’s degree", "Master’s degree", "Post grad", "Less than a Bachelors"], label="Education Level"),
53
+ gr.Number(label="Years of Professional Experience"),
54
+ gr.Dropdown(["Fully remote", "Hybrid", "In-office"], label="Remote Work Status")
55
+ ]
56
+
57
+ output = gr.Textbox(label="Predicted Salary")
58
+
59
+ app = gr.Interface(fn=predict_salary, inputs=inputs, outputs=output, title="Salary Prediction App")
60
+ app.launch()