Spaces:
Sleeping
Sleeping
Download app.py from PavanShivaKumar/Cross_Cluster: direct link, hf CLI and curl.
- Browser
- Download file 2.14 kB
-
https://huggingface.co/spaces/PavanShivaKumar/Cross_Cluster/resolve/main/app.py
- Command line
-
hf download hf://spaces/PavanShivaKumar/Cross_Cluster/app.py
-
curl -L -o app.py https://huggingface.co/spaces/PavanShivaKumar/Cross_Cluster/resolve/main/app.py
2.14 kB
| import numpy as np | |
| import gradio as gr | |
| import pickle | |
| from sklearn.feature_extraction.text import TfidfVectorizer | |
| # Load the trained model (same as before) | |
| import joblib | |
| # Load the trained model (if saved using joblib) | |
| def load_model(): | |
| model = joblib.load("random_forest_model.pkl") | |
| return model | |
| # Prediction function | |
| def predict_project(fname, lname, email, role, experience, skills): | |
| # Load the model and vectorizer | |
| model = load_model() | |
| vectorizer=TfidfVectorizer() | |
| # Prepare the new employee data | |
| new_employee = { | |
| 'fname': fname, | |
| 'lname': lname, | |
| 'email': email, | |
| 'role': role, # Role can be 'Senior' or 'Intern' | |
| 'experience': experience, | |
| 'skills': skills, | |
| } | |
| # Encode the 'role' to numerical format | |
| role_mapping = {'Intern': 0, 'Senior': 1} # Map 'Intern' -> 0, 'Senior' -> 1 | |
| new_employee['role'] = role_mapping.get(new_employee['role'], -1) # Default to -1 if unknown role | |
| # Transform the skills using the same vectorizer used during training | |
| skills_vector = vectorizer.transform([new_employee['skills']]) | |
| # Combine the features (experience, role, and skills) | |
| X_new_employee = np.hstack(( | |
| np.array([[new_employee['experience']]]), # Reshape experience to 2D | |
| np.array([[new_employee['role']]]), # Reshape role to 2D | |
| skills_vector.toarray() # Convert skills vector to array | |
| )) | |
| # Predict the project ID for the new employee | |
| predicted_project = model.predict(X_new_employee)[0] | |
| return f"The predicted project ID for {new_employee['fname']} {new_employee['lname']} is {predicted_project}" | |
| # Create the Gradio interface | |
| interface = gr.Interface( | |
| fn=predict_project, | |
| inputs=[ | |
| gr.Textbox(label="First Name"), | |
| gr.Textbox(label="Last Name"), | |
| gr.Textbox(label="Email"), | |
| gr.Dropdown(choices=["Intern", "Senior"], label="Role"), | |
| gr.Slider(minimum=0, maximum=50, step=1, label="Experience (in years)"), | |
| gr.Textbox(label="Skills (comma separated)"), | |
| ], | |
| outputs="text", | |
| ) | |
| # Launch the Gradio app | |
| interface.launch() | |