mployd-engineering commited on
Commit
54fd365
·
verified ·
1 Parent(s): 9c46a12

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -6
app.py CHANGED
@@ -15,19 +15,36 @@ except Exception as e:
15
  raise # Re-raise the exception to stop the space from running with a broken app
16
 
17
  # 3. Define the Prediction Function
 
18
  def match_cv_jd(cv_text: str, job_description_text: str):
19
  """
20
  Tokenizes the inputs, runs the model, and returns the prediction/score.
21
  """
22
- # *** REMOVE THIS CHECK (if not model or not tokenizer) ***
23
- # if not model or not tokenizer:
24
- # return "Model loading failed. Check logs for details."
25
-
26
  try:
27
- # ... the rest of the prediction logic ...
 
 
 
 
 
 
 
 
28
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  except Exception as e:
30
- # Keep the try/except INSIDE the function to catch runtime errors
31
  return f"An error occurred during prediction: {e}"
32
 
33
  # ... rest of the Gradio code ...
 
15
  raise # Re-raise the exception to stop the space from running with a broken app
16
 
17
  # 3. Define the Prediction Function
18
+ # app.py (around line 22)
19
  def match_cv_jd(cv_text: str, job_description_text: str):
20
  """
21
  Tokenizes the inputs, runs the model, and returns the prediction/score.
22
  """
 
 
 
 
23
  try:
24
+ # ⬅️ THIS BLOCK MUST BE INDENTED
25
+ # 1. Prepare the input for the matching task
26
+ inputs = tokenizer(
27
+ cv_text,
28
+ job_description_text,
29
+ return_tensors="pt",
30
+ padding=True,
31
+ truncation=True
32
+ )
33
 
34
+ # 2. Get model output (logits)
35
+ with torch.no_grad():
36
+ outputs = model(**inputs)
37
+
38
+ # 3. Process the output
39
+ probabilities = torch.softmax(outputs.logits, dim=1).tolist()[0]
40
+ predicted_index = torch.argmax(outputs.logits, dim=1).item()
41
+ prediction = model.config.id2label[predicted_index]
42
+ score = max(probabilities) * 100
43
+
44
+ return f"Prediction: **{prediction}**\nConfidence Score: **{score:.2f}%**"
45
+
46
  except Exception as e:
47
+ # ⬅️ The 'except' block is correctly indented relative to the 'try'
48
  return f"An error occurred during prediction: {e}"
49
 
50
  # ... rest of the Gradio code ...