mployd-engineering commited on
Commit
040d4f9
·
verified ·
1 Parent(s): 8c1b4f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -1
app.py CHANGED
@@ -67,4 +67,50 @@ def match_cv_jd(cv_text: str, job_description_text: str):
67
  # Apply the chat template and generate tokens
68
  inputs = tokenizer.apply_chat_template(
69
  messages,
70
- add_
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  # Apply the chat template and generate tokens
68
  inputs = tokenizer.apply_chat_template(
69
  messages,
70
+ add_generation_prompt=True,
71
+ return_tensors="pt"
72
+ ).to(model.device)
73
+
74
+ # Generate the response
75
+ outputs = model.generate(
76
+ inputs,
77
+ max_new_tokens=512,
78
+ do_sample=False,
79
+ pad_token_id=tokenizer.eos_token_id
80
+ )
81
+
82
+ # Decode the generated text and clean up the prompt
83
+ generated_text = tokenizer.decode(outputs[0], skip_special_tokens=False)
84
+
85
+ # Attempt to clean the output to show only the assistant's response
86
+ assistant_response_start = generated_text.rfind("<|eot_id|>assistant\n")
87
+
88
+ if assistant_response_start != -1:
89
+ # Extract text starting after the assistant's role tag
90
+ raw_json_output = generated_text[assistant_response_start + len("<|eot_id|>assistant\n"):].strip()
91
+ else:
92
+ # Fallback to the full generated text if the marker isn't found
93
+ raw_json_output = generated_text
94
+
95
+ # Remove any trailing tokens like <|eot_id|> for cleaner output
96
+ raw_json_output = raw_json_output.replace("<|eot_id|>", "").strip()
97
+
98
+ return f"### ✅ Matching Analysis Output (Expected JSON):\n\n```json\n{raw_json_output}\n```"
99
+
100
+ except Exception as e:
101
+ return f"### ❌ Prediction Error\n\nAn error occurred during prediction: {e}. This may indicate a hardware memory issue or a timeout."
102
+
103
+ # --- Gradio Interface ---
104
+ demo = gr.Interface(
105
+ fn=match_cv_jd,
106
+ inputs=[
107
+ gr.Textbox(label="Paste CV Text", lines=10),
108
+ gr.Textbox(label="Paste Job Description Text", lines=10)
109
+ ],
110
+ outputs="markdown",
111
+ title="LlamaFactory CV-Job Matching Demo",
112
+ description=f"Interactive demo for the {LORA_MODEL_ID} model (LoRA on {BASE_MODEL_ID}). This LLM expects a system prompt and outputs structured JSON."
113
+ )
114
+
115
+ if __name__ == "__main__":
116
+ demo.launch()