Update app.py
Browse files
app.py
CHANGED
|
@@ -21,38 +21,6 @@ def extract_text_from_pdf(file):
|
|
| 21 |
st.error(f"Erreur lors de l'extraction du texte : {str(e)}")
|
| 22 |
return None
|
| 23 |
|
| 24 |
-
# Formatage des résultats de l'analyse pour un affichage clair
|
| 25 |
-
def format_analysis_result(analysis_data, referential):
|
| 26 |
-
"""
|
| 27 |
-
Formate les résultats de l'analyse pour un affichage clair et structuré.
|
| 28 |
-
"""
|
| 29 |
-
formatted_result = f"### Analyse du CV ({referential})\n\n"
|
| 30 |
-
|
| 31 |
-
# Exigences remplies
|
| 32 |
-
formatted_result += "#### Exigences remplies\n\n"
|
| 33 |
-
for item in analysis_data.get('fulfilled', []):
|
| 34 |
-
formatted_result += (
|
| 35 |
-
f"- **{item['category']}**\n"
|
| 36 |
-
f" - **Exigence** : {item['requirement']}\n"
|
| 37 |
-
f" - **Résultat** : {item['result']}\n\n"
|
| 38 |
-
)
|
| 39 |
-
|
| 40 |
-
# Lacunes ou non-conformités
|
| 41 |
-
formatted_result += "#### Lacunes ou non-conformités\n\n"
|
| 42 |
-
for item in analysis_data.get('gaps', []):
|
| 43 |
-
formatted_result += (
|
| 44 |
-
f"- **{item['category']}**\n"
|
| 45 |
-
f" - **Exigence** : {item['requirement']}\n"
|
| 46 |
-
f" - **Résultat** : {item['result']}\n\n"
|
| 47 |
-
)
|
| 48 |
-
|
| 49 |
-
# Recommandations
|
| 50 |
-
formatted_result += "#### Recommandations\n\n"
|
| 51 |
-
for rec in analysis_data.get('recommendations', []):
|
| 52 |
-
formatted_result += f"- **{rec['category']}** : {rec['recommendation']}\n\n"
|
| 53 |
-
|
| 54 |
-
return formatted_result
|
| 55 |
-
|
| 56 |
# Analyse du CV avec les exigences du référentiel et Groq
|
| 57 |
def analyze_cv_with_groq(cv_text, referential):
|
| 58 |
"""
|
|
@@ -90,13 +58,13 @@ def analyze_cv_with_groq(cv_text, referential):
|
|
| 90 |
{cv_text}
|
| 91 |
|
| 92 |
Fournissez une analyse détaillée en identifiant :
|
| 93 |
-
1. Les exigences remplies.
|
| 94 |
-
2. Les lacunes ou non-conformités.
|
| 95 |
-
3. Des recommandations pour combler les lacunes.
|
| 96 |
"""
|
| 97 |
|
| 98 |
try:
|
| 99 |
-
response = groq.generate(prompt, max_tokens=
|
| 100 |
analysis_data = parse_groq_response(response) # Fonction fictive pour parser la réponse
|
| 101 |
return format_analysis_result(analysis_data, referential)
|
| 102 |
except Exception as e:
|
|
@@ -111,23 +79,75 @@ def parse_groq_response(response):
|
|
| 111 |
# Simulation de parsing (vous pouvez adapter selon votre API Groq)
|
| 112 |
return {
|
| 113 |
"fulfilled": [
|
| 114 |
-
{
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
],
|
| 117 |
"gaps": [
|
| 118 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
],
|
| 120 |
"recommendations": [
|
| 121 |
-
{
|
|
|
|
|
|
|
|
|
|
| 122 |
]
|
| 123 |
}
|
| 124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
# Interface utilisateur Streamlit
|
| 126 |
def main():
|
| 127 |
st.title("Analyse de CV selon les référentiels GFSI")
|
| 128 |
st.markdown("""
|
| 129 |
-
Cette application
|
| 130 |
-
Téléchargez un CV
|
| 131 |
""")
|
| 132 |
|
| 133 |
# Entrée clé API
|
|
@@ -143,7 +163,7 @@ def main():
|
|
| 143 |
# Extraire le texte du CV
|
| 144 |
cv_text = extract_text_from_pdf(uploaded_file)
|
| 145 |
if cv_text:
|
| 146 |
-
st.markdown("
|
| 147 |
analysis = analyze_cv_with_groq(cv_text, referential)
|
| 148 |
if analysis:
|
| 149 |
st.markdown(analysis, unsafe_allow_html=True)
|
|
@@ -152,3 +172,4 @@ def main():
|
|
| 152 |
|
| 153 |
if __name__ == "__main__":
|
| 154 |
main()
|
|
|
|
|
|
| 21 |
st.error(f"Erreur lors de l'extraction du texte : {str(e)}")
|
| 22 |
return None
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
# Analyse du CV avec les exigences du référentiel et Groq
|
| 25 |
def analyze_cv_with_groq(cv_text, referential):
|
| 26 |
"""
|
|
|
|
| 58 |
{cv_text}
|
| 59 |
|
| 60 |
Fournissez une analyse détaillée en identifiant :
|
| 61 |
+
1. Les exigences remplies (avec justification).
|
| 62 |
+
2. Les lacunes ou non-conformités (avec explication détaillée).
|
| 63 |
+
3. Des recommandations pour combler les lacunes, adaptées au profil.
|
| 64 |
"""
|
| 65 |
|
| 66 |
try:
|
| 67 |
+
response = groq.generate(prompt, max_tokens=2000, temperature=0.5, use_cot=True)
|
| 68 |
analysis_data = parse_groq_response(response) # Fonction fictive pour parser la réponse
|
| 69 |
return format_analysis_result(analysis_data, referential)
|
| 70 |
except Exception as e:
|
|
|
|
| 79 |
# Simulation de parsing (vous pouvez adapter selon votre API Groq)
|
| 80 |
return {
|
| 81 |
"fulfilled": [
|
| 82 |
+
{
|
| 83 |
+
"category": "Éducation",
|
| 84 |
+
"requirement": "Diplôme en sciences alimentaires ou biosciences",
|
| 85 |
+
"result": "Master en food industries quality, ce qui dépasse les exigences."
|
| 86 |
+
},
|
| 87 |
+
{
|
| 88 |
+
"category": "Expérience professionnelle",
|
| 89 |
+
"requirement": "Minimum de 3 ans d'expérience",
|
| 90 |
+
"result": "Plus de 5 ans d'expérience couvrant qualité, sécurité alimentaire et R&D."
|
| 91 |
+
}
|
| 92 |
],
|
| 93 |
"gaps": [
|
| 94 |
+
{
|
| 95 |
+
"category": "Formation Lead Auditor",
|
| 96 |
+
"requirement": "Cours de Lead Auditor (40 heures minimum)",
|
| 97 |
+
"result": "Cours suivi : Lead Auditor IFS Global Markets Food v2, mais durée insuffisante."
|
| 98 |
+
}
|
| 99 |
],
|
| 100 |
"recommendations": [
|
| 101 |
+
{
|
| 102 |
+
"category": "Formation complémentaire",
|
| 103 |
+
"recommendation": "Compléter un cours de Lead Auditor reconnu (IFS ou IRCA) répondant à la durée minimale de 40 heures."
|
| 104 |
+
}
|
| 105 |
]
|
| 106 |
}
|
| 107 |
|
| 108 |
+
# Formatage des résultats de l'analyse
|
| 109 |
+
def format_analysis_result(analysis_data, referential):
|
| 110 |
+
"""
|
| 111 |
+
Formate les résultats de l'analyse pour un affichage clair et structuré avec différenciation par couleur.
|
| 112 |
+
"""
|
| 113 |
+
formatted_result = f"<h3 style='text-align: center;'>Analyse du CV ({referential})</h3><hr>"
|
| 114 |
+
|
| 115 |
+
# Exigences remplies
|
| 116 |
+
formatted_result += "<h4 style='color: green;'>Exigences remplies</h4><ul>"
|
| 117 |
+
for item in analysis_data.get('fulfilled', []):
|
| 118 |
+
formatted_result += (
|
| 119 |
+
f"<li><strong>{item['category']}</strong><br>"
|
| 120 |
+
f"<span style='color: blue;'>Exigence :</span> {item['requirement']}<br>"
|
| 121 |
+
f"<span style='color: green;'>Résultat :</span> {item['result']}</li><br>"
|
| 122 |
+
)
|
| 123 |
+
formatted_result += "</ul>"
|
| 124 |
+
|
| 125 |
+
# Lacunes ou non-conformités
|
| 126 |
+
formatted_result += "<h4 style='color: red;'>Lacunes ou non-conformités</h4><ul>"
|
| 127 |
+
for item in analysis_data.get('gaps', []):
|
| 128 |
+
formatted_result += (
|
| 129 |
+
f"<li><strong>{item['category']}</strong><br>"
|
| 130 |
+
f"<span style='color: blue;'>Exigence :</span> {item['requirement']}<br>"
|
| 131 |
+
f"<span style='color: red;'>Résultat :</span> {item['result']}</li><br>"
|
| 132 |
+
)
|
| 133 |
+
formatted_result += "</ul>"
|
| 134 |
+
|
| 135 |
+
# Recommandations
|
| 136 |
+
formatted_result += "<h4 style='color: orange;'>Recommandations</h4><ul>"
|
| 137 |
+
for rec in analysis_data.get('recommendations', []):
|
| 138 |
+
formatted_result += (
|
| 139 |
+
f"<li><strong>{rec['category']}</strong>: {rec['recommendation']}</li><br>"
|
| 140 |
+
)
|
| 141 |
+
formatted_result += "</ul>"
|
| 142 |
+
|
| 143 |
+
return formatted_result
|
| 144 |
+
|
| 145 |
# Interface utilisateur Streamlit
|
| 146 |
def main():
|
| 147 |
st.title("Analyse de CV selon les référentiels GFSI")
|
| 148 |
st.markdown("""
|
| 149 |
+
Cette application évalue un CV selon les référentiels GFSI (BRCGS, FSSC 22000, et IFS).
|
| 150 |
+
Téléchargez un CV, sélectionnez un référentiel, et obtenez une analyse détaillée.
|
| 151 |
""")
|
| 152 |
|
| 153 |
# Entrée clé API
|
|
|
|
| 163 |
# Extraire le texte du CV
|
| 164 |
cv_text = extract_text_from_pdf(uploaded_file)
|
| 165 |
if cv_text:
|
| 166 |
+
st.markdown("<h3>Résultat de l'analyse</h3>", unsafe_allow_html=True)
|
| 167 |
analysis = analyze_cv_with_groq(cv_text, referential)
|
| 168 |
if analysis:
|
| 169 |
st.markdown(analysis, unsafe_allow_html=True)
|
|
|
|
| 172 |
|
| 173 |
if __name__ == "__main__":
|
| 174 |
main()
|
| 175 |
+
|