Spaces:
Sleeping
Sleeping
updated organization of the printed output and added rerun with a max of 2 attempts.
Browse files- app.py +33 -21
- resume_template.py +5 -5
app.py
CHANGED
@@ -62,16 +62,26 @@ def extract_resume_fields(full_text, model):
|
|
62 |
input_variables=["resume"],
|
63 |
partial_variables={"response_template": parser.get_format_instructions()},
|
64 |
)
|
65 |
-
# Invoke the language model and process the resume
|
66 |
-
# formatted_input = prompt_template.format_prompt(resume=full_text)
|
67 |
llm = llm_dict.get(model, ChatOpenAI(temperature=0, model=model))
|
68 |
-
|
69 |
-
# output = llm.invoke(formatted_input.to_string())
|
70 |
chain = prompt_template | llm | parser
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
# try:
|
76 |
# parsed_output = parser.parse(output.content)
|
77 |
# json_output = parsed_output.json()
|
@@ -91,26 +101,28 @@ def extract_resume_fields(full_text, model):
|
|
91 |
def display_extracted_fields(obj, section_title=None, indent=0):
|
92 |
if section_title:
|
93 |
st.subheader(section_title)
|
94 |
-
|
95 |
for field_name, field_value in obj:
|
96 |
-
if
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
|
|
|
|
|
|
105 |
else:
|
106 |
-
st.write(" " * indent + field_name
|
107 |
|
108 |
|
109 |
st.title("Resume Parser")
|
110 |
|
111 |
llm_dict = {
|
112 |
-
"
|
113 |
-
"
|
114 |
}
|
115 |
|
116 |
selected_model = st.selectbox("Select a model", list(llm_dict.keys()))
|
|
|
62 |
input_variables=["resume"],
|
63 |
partial_variables={"response_template": parser.get_format_instructions()},
|
64 |
)
|
|
|
|
|
65 |
llm = llm_dict.get(model, ChatOpenAI(temperature=0, model=model))
|
66 |
+
|
|
|
67 |
chain = prompt_template | llm | parser
|
68 |
+
max_attempts = 2
|
69 |
+
attempt = 1
|
70 |
+
|
71 |
+
while attempt <= max_attempts:
|
72 |
+
try:
|
73 |
+
output = chain.invoke(full_text)
|
74 |
+
print(output)
|
75 |
+
return output
|
76 |
+
except ValidationError as e:
|
77 |
+
if attempt == max_attempts:
|
78 |
+
raise e
|
79 |
+
else:
|
80 |
+
print(f"Validation error occurred. Retrying (attempt {attempt + 1}/{max_attempts})...")
|
81 |
+
attempt += 1
|
82 |
+
|
83 |
+
return None
|
84 |
+
|
85 |
# try:
|
86 |
# parsed_output = parser.parse(output.content)
|
87 |
# json_output = parsed_output.json()
|
|
|
101 |
def display_extracted_fields(obj, section_title=None, indent=0):
|
102 |
if section_title:
|
103 |
st.subheader(section_title)
|
|
|
104 |
for field_name, field_value in obj:
|
105 |
+
if field_name in ["personal_details", "education", "work_experience", "projects", "skills", "certifications", "publications", "awards", "additional_sections"]:
|
106 |
+
st.write(" " * indent + f"**{field_name.replace('_', ' ').title()}**:")
|
107 |
+
if isinstance(field_value, BaseModel):
|
108 |
+
display_extracted_fields(field_value, None, indent + 1)
|
109 |
+
elif isinstance(field_value, list):
|
110 |
+
for item in field_value:
|
111 |
+
if isinstance(item, BaseModel):
|
112 |
+
display_extracted_fields(item, None, indent + 1)
|
113 |
+
else:
|
114 |
+
st.write(" " * (indent + 1) + "- " + str(item))
|
115 |
+
else:
|
116 |
+
st.write(" " * (indent + 1) + str(field_value))
|
117 |
else:
|
118 |
+
st.write(" " * indent + f"{field_name.replace('_', ' ').title()}: " + str(field_value))
|
119 |
|
120 |
|
121 |
st.title("Resume Parser")
|
122 |
|
123 |
llm_dict = {
|
124 |
+
"GPT 3.5 turbo": ChatOpenAI(temperature=0, model_name="gpt-3.5-turbo"),
|
125 |
+
"Anthropic Sonnet": ChatAnthropic(model_name="claude-3-sonnet-20240229"),
|
126 |
}
|
127 |
|
128 |
selected_model = st.selectbox("Select a model", list(llm_dict.keys()))
|
resume_template.py
CHANGED
@@ -32,10 +32,10 @@ class Project(BaseModel):
|
|
32 |
technologies: Optional[str] = None
|
33 |
role: Optional[str] = None
|
34 |
|
35 |
-
class Certification(BaseModel):
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
|
40 |
class Publication(BaseModel):
|
41 |
title: Optional[str] = None
|
@@ -64,7 +64,7 @@ class Resume(BaseModel):
|
|
64 |
work_experience: List[WorkExperience] = []
|
65 |
projects: List[Project] = []
|
66 |
skills: List[str] = []
|
67 |
-
certifications: List[
|
68 |
publications: List[Publication] = []
|
69 |
awards: List[Award] = []
|
70 |
additional_sections: Optional[AdditionalSections] = None
|
|
|
32 |
technologies: Optional[str] = None
|
33 |
role: Optional[str] = None
|
34 |
|
35 |
+
# class Certification(BaseModel):
|
36 |
+
# title: Optional[str] = None
|
37 |
+
# certifying_body: Optional[str] = None
|
38 |
+
# date: Optional[str] = None
|
39 |
|
40 |
class Publication(BaseModel):
|
41 |
title: Optional[str] = None
|
|
|
64 |
work_experience: List[WorkExperience] = []
|
65 |
projects: List[Project] = []
|
66 |
skills: List[str] = []
|
67 |
+
certifications: List[str] = []
|
68 |
publications: List[Publication] = []
|
69 |
awards: List[Award] = []
|
70 |
additional_sections: Optional[AdditionalSections] = None
|