sid22669 commited on
Commit
7132f90
·
verified ·
1 Parent(s): 838833a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -28
app.py CHANGED
@@ -8,10 +8,9 @@ import uuid
8
  from datetime import datetime
9
  from docx import Document
10
  import tempfile
11
- print("NotLoaded")
12
  # Load model and vectorizer
13
  classifier_model = joblib.load('resume_classifier')
14
- print("NotLoaded")
15
  resume_vectorizer = joblib.load('resume_vectorizer')
16
 
17
 
@@ -41,7 +40,6 @@ def read_file(file_path):
41
  except Exception as e:
42
  return f"Error reading Word file with textract: {str(e)}"
43
 
44
-
45
  else:
46
  return "Unsupported file type."
47
 
@@ -54,7 +52,7 @@ def clean_resume(text):
54
 
55
 
56
  def log_or_update(serial_id, timestamp, resume_text, model_prediction, corrected_prediction):
57
- log_file = "corrections_log.csv"
58
  resume_text_short = resume_text[:500] # Truncate for privacy/log size
59
 
60
  new_row = {
@@ -85,33 +83,20 @@ uploaded_file = st.file_uploader(
85
  type=["pdf", "txt", "doc", "docx"]
86
  )
87
 
88
- print("Somethinguploaded")
89
-
90
  if uploaded_file:
91
- # Ensure /tmp directory exists
92
- upload_dir = "/tmp/uploads"
93
- os.makedirs(upload_dir, exist_ok=True)
94
-
95
- # Save the uploaded file to /tmp
96
- file_path = os.path.join(upload_dir, uploaded_file.name)
97
- with open(file_path, "wb") as f:
98
- f.write(uploaded_file.getbuffer())
99
 
100
- # Handle session state tracking
101
  if (
102
  "uploaded_file_name" not in st.session_state
103
  or st.session_state.uploaded_file_name != uploaded_file.name
104
  ):
105
  st.session_state.uploaded_file_name = uploaded_file.name
106
  st.session_state.serial_id = str(uuid.uuid4())
107
- st.session_state.corrected_prediction = None # Reset correction state
108
-
109
- st.success(f"File uploaded and saved to: {file_path}")
110
-
111
- # Save uploaded file to temp and extract text (same as your code)
112
- with tempfile.NamedTemporaryFile(delete=False, suffix=os.path.splitext(uploaded_file.name)[1]) as temp_file:
113
- temp_file.write(uploaded_file.read())
114
- temp_path = temp_file.name
115
 
116
  extracted_text = read_file(temp_path)
117
  os.remove(temp_path)
@@ -130,15 +115,15 @@ if uploaded_file:
130
  corrected_prediction = prediction
131
 
132
  if feedback == "No":
133
- # Use session state to keep corrected prediction during session
134
- corrected_prediction = st.text_input("Please provide the correct role:",
135
- value=st.session_state.get("corrected_prediction", ""),
136
- key="correction_input")
 
137
  st.session_state.corrected_prediction = corrected_prediction
138
  else:
139
  st.session_state.corrected_prediction = prediction
140
 
141
- # Log/update only if user made a choice (Yes or No + correction if No)
142
  if (feedback == "Yes") or (feedback == "No" and corrected_prediction):
143
  now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
144
  log_or_update(
 
8
  from datetime import datetime
9
  from docx import Document
10
  import tempfile
11
+
12
  # Load model and vectorizer
13
  classifier_model = joblib.load('resume_classifier')
 
14
  resume_vectorizer = joblib.load('resume_vectorizer')
15
 
16
 
 
40
  except Exception as e:
41
  return f"Error reading Word file with textract: {str(e)}"
42
 
 
43
  else:
44
  return "Unsupported file type."
45
 
 
52
 
53
 
54
  def log_or_update(serial_id, timestamp, resume_text, model_prediction, corrected_prediction):
55
+ log_file = "/tmp/corrections_log.csv"
56
  resume_text_short = resume_text[:500] # Truncate for privacy/log size
57
 
58
  new_row = {
 
83
  type=["pdf", "txt", "doc", "docx"]
84
  )
85
 
 
 
86
  if uploaded_file:
87
+ # Save uploaded file to a temp file in /tmp
88
+ with tempfile.NamedTemporaryFile(delete=False, dir="/tmp", suffix=os.path.splitext(uploaded_file.name)[1]) as temp_file:
89
+ temp_file.write(uploaded_file.read())
90
+ temp_path = temp_file.name
 
 
 
 
91
 
92
+ # Track upload session
93
  if (
94
  "uploaded_file_name" not in st.session_state
95
  or st.session_state.uploaded_file_name != uploaded_file.name
96
  ):
97
  st.session_state.uploaded_file_name = uploaded_file.name
98
  st.session_state.serial_id = str(uuid.uuid4())
99
+ st.session_state.corrected_prediction = None
 
 
 
 
 
 
 
100
 
101
  extracted_text = read_file(temp_path)
102
  os.remove(temp_path)
 
115
  corrected_prediction = prediction
116
 
117
  if feedback == "No":
118
+ corrected_prediction = st.text_input(
119
+ "Please provide the correct role:",
120
+ value=st.session_state.get("corrected_prediction", ""),
121
+ key="correction_input"
122
+ )
123
  st.session_state.corrected_prediction = corrected_prediction
124
  else:
125
  st.session_state.corrected_prediction = prediction
126
 
 
127
  if (feedback == "Yes") or (feedback == "No" and corrected_prediction):
128
  now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
129
  log_or_update(