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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
import gradio as gr
|
| 3 |
+
from smolagents import HfApiModel, ChatMessage
|
| 4 |
|
| 5 |
+
# Load Hugging Face API token from environment variable
|
| 6 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 7 |
+
if not HF_TOKEN:
|
| 8 |
+
raise ValueError("Please set the HF_TOKEN environment variable.")
|
| 9 |
|
| 10 |
+
# Load LLM model from Hugging Face using smolagents wrapper
|
| 11 |
+
model = HfApiModel(
|
| 12 |
+
model_id="meta-llama/Llama-3.1-8B-Instruct",
|
| 13 |
+
token=HF_TOKEN,
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
def generate_documents(user_info, job_description):
|
| 17 |
+
"""
|
| 18 |
+
Generate a tailored resume and cover letter.
|
| 19 |
+
|
| 20 |
+
Args:
|
| 21 |
+
user_info (str): User's background, education, experience, and skills.
|
| 22 |
+
job_description (str): Text of the job description.
|
| 23 |
+
|
| 24 |
+
Returns:
|
| 25 |
+
str: Resume and cover letter, separated by headers.
|
| 26 |
+
"""
|
| 27 |
+
if not user_info.strip() or not job_description.strip():
|
| 28 |
+
return "❌ Veuillez remplir tous les champs."
|
| 29 |
+
|
| 30 |
+
try:
|
| 31 |
+
prompt = (
|
| 32 |
+
"You are a helpful AI assistant that specializes in career support.\n"
|
| 33 |
+
"Generate a tailored resume and cover letter for a candidate based on the following input.\n"
|
| 34 |
+
"Write in French if the job description is in French, otherwise write in English.\n\n"
|
| 35 |
+
f"=== User Info ===\n{user_info}\n\n"
|
| 36 |
+
f"=== Job Description ===\n{job_description}\n\n"
|
| 37 |
+
"Format the output as follows:\n"
|
| 38 |
+
"=== CV / RESUME ===\n<bullet-point resume with clear sections>\n\n"
|
| 39 |
+
"=== LETTRE DE MOTIVATION / COVER LETTER ===\n<formal cover letter>\n"
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
messages = [ChatMessage(role="user", content=prompt)]
|
| 43 |
+
response = model(messages)
|
| 44 |
+
|
| 45 |
+
# Vérifier que la réponse a bien un contenu
|
| 46 |
+
if hasattr(response, 'content') and response.content:
|
| 47 |
+
return response.content
|
| 48 |
+
else:
|
| 49 |
+
return "❌ Erreur: Impossible de générer les documents. Veuillez réessayer."
|
| 50 |
+
|
| 51 |
+
except Exception as e:
|
| 52 |
+
return f"❌ Erreur lors de la génération des documents: {str(e)}"
|
| 53 |
+
|
| 54 |
+
# Créer l'interface Gradio
|
| 55 |
+
def create_interface():
|
| 56 |
+
with gr.Blocks(
|
| 57 |
+
title="🎯 Career Assistant",
|
| 58 |
+
css="""
|
| 59 |
+
.gradio-container {
|
| 60 |
+
max-width: 1200px !important;
|
| 61 |
+
}
|
| 62 |
+
"""
|
| 63 |
+
) as demo:
|
| 64 |
+
|
| 65 |
+
gr.Markdown("""
|
| 66 |
+
# 🎯 Assistant Carrière / Career Assistant
|
| 67 |
+
|
| 68 |
+
Générez un CV et une lettre de motivation personnalisés en fonction de vos informations et de l'offre d'emploi.
|
| 69 |
+
|
| 70 |
+
*Generate a tailored resume and cover letter based on your information and the job offer.*
|
| 71 |
+
""")
|
| 72 |
+
|
| 73 |
+
with gr.Row():
|
| 74 |
+
with gr.Column(scale=1):
|
| 75 |
+
user_info = gr.Textbox(
|
| 76 |
+
label="📝 Vos informations personnelles / Your personal information",
|
| 77 |
+
placeholder="""Exemple / Example:
|
| 78 |
+
- Formation: Master en Informatique
|
| 79 |
+
- Expérience: 3 ans en développement web
|
| 80 |
+
- Compétences: Python, JavaScript, React
|
| 81 |
+
- Langues: Français, Anglais""",
|
| 82 |
+
lines=8,
|
| 83 |
+
max_lines=15
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
job_description = gr.Textbox(
|
| 87 |
+
label="💼 Description du poste / Job description",
|
| 88 |
+
placeholder="Collez ici la description complète du poste / Paste the complete job description here...",
|
| 89 |
+
lines=6,
|
| 90 |
+
max_lines=10
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
generate_btn = gr.Button(
|
| 94 |
+
"🚀 Générer CV et Lettre / Generate Resume & Cover Letter",
|
| 95 |
+
variant="primary",
|
| 96 |
+
size="lg"
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
with gr.Column(scale=1):
|
| 100 |
+
output = gr.Textbox(
|
| 101 |
+
label="📄 Résultat / Result",
|
| 102 |
+
lines=20,
|
| 103 |
+
max_lines=30,
|
| 104 |
+
show_copy_button=True
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
# Event handlers
|
| 108 |
+
generate_btn.click(
|
| 109 |
+
fn=generate_documents,
|
| 110 |
+
inputs=[user_info, job_description],
|
| 111 |
+
outputs=output,
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
# Exemple pour aider les utilisateurs
|
| 115 |
+
gr.Markdown("""
|
| 116 |
+
## 💡 Conseils / Tips:
|
| 117 |
+
- Soyez précis dans vos informations personnelles / Be specific in your personal information
|
| 118 |
+
- Incluez toute la description du poste / Include the complete job description
|
| 119 |
+
- Le CV sera adapté automatiquement au poste / The resume will be automatically tailored to the position
|
| 120 |
+
""")
|
| 121 |
+
|
| 122 |
+
return demo
|
| 123 |
+
|
| 124 |
+
# Launch the Gradio app
|
| 125 |
+
if __name__ == "__main__":
|
| 126 |
+
try:
|
| 127 |
+
demo = create_interface()
|
| 128 |
+
demo.launch(
|
| 129 |
+
share=False,
|
| 130 |
+
server_name="0.0.0.0",
|
| 131 |
+
server_port=7860,
|
| 132 |
+
show_error=True
|
| 133 |
+
)
|
| 134 |
+
except Exception as e:
|
| 135 |
+
print(f"Erreur lors du lancement de l'application: {e}")
|
| 136 |
+
# Lancement simplifié en cas d'erreur
|
| 137 |
+
interface = gr.Interface(
|
| 138 |
+
fn=generate_documents,
|
| 139 |
+
inputs=[
|
| 140 |
+
gr.Textbox(label="Informations personnelles", lines=5),
|
| 141 |
+
gr.Textbox(label="Description du poste", lines=5)
|
| 142 |
+
],
|
| 143 |
+
outputs=gr.Textbox(label="CV et Lettre de motivation", lines=15),
|
| 144 |
+
title="🎯 Career Assistant",
|
| 145 |
+
description="Générez un CV et une lettre de motivation personnalisés!"
|
| 146 |
+
)
|
| 147 |
+
interface.launch()
|
requirements.txt
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
-
gradio
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
smolagents
|