Spaces:
Sleeping
Sleeping
Upload app.py
Browse files31 unmodified lines323334353637389 unmodified lines4274284294304314324331 unmodified line43543643743843944044144244344444544644720 unmodified lines46846947047147247316 unmodified lines49049149249349449511 unmodified lines50750850951051151251331 unmodified lines# Initialisation du client LLMclient = InferenceClient(model=LLM_MODEL, token=HF_TOKEN)print(f"🚀 Chargement des données depuis le Hub HF ({DATASET_REPO})...")try:ds = load_dataset(DATASET_REPO, split="train")389 unmodified linesdef on_export_pdf(results_state, query_state, keywords_state, context_state, synthesis_state):"""Déclenché au clic sur le bouton export — appelle le LLM dédié et génère le PDF."""if not results_state:return None, gr.update(visible=False)path = generate_pdf_report(combined_query=query_state,keywords=keywords_state,1 unmodified linellm_context=context_state[:4000],synthesis=synthesis_state)return path, gr.update(visible=True)def results_html_error(msg):return f"<div style='color: red; padding: 20px; border: 1px solid red; border-radius: 8px;'>{msg}</div>"# ---------------------------------------------------------------------------# INTERFACE GRADIO# ---------------------------------------------------------------------------20 unmodified linesplaceholder="Ex: J'aime l'informatique, le contact client...",lines=3)file_input = gr.File(label="Ou uploadez votre CV (PDF)", file_types=[".pdf"])with gr.Column(scale=2):16 unmodified linesgr.Markdown("### 📋 Fiches Métiers suggérées")results_output = gr.HTML()# 1. Recherche + streaming LLMsearch_button.click(fn=search_and_chat,11 unmodified linesexport_button.click(fn=on_export_pdf,inputs=[results_state, query_state, keywords_state, context_state, synthesis_state],outputs=[pdf_output, pdf_output])if __name__ == "__main__":31 unmodified lines323334353637383940389 unmodified lines4304314324334344354361 unmodified line43843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746820 unmodified lines48949049149249349449549649749849950016 unmodified lines51751851952052152252352452552652752852911 unmodified lines54154254354454554654754854955031 unmodified lines# Initialisation du client LLMclient = InferenceClient(model=LLM_MODEL, token=HF_TOKEN)# Initialisation du client Whisper (transcription audio)whisper_client = InferenceClient("openai/whisper-large-v3", token=HF_TOKEN)print(f"🚀 Chargement des données depuis le Hub HF ({DATASET_REPO})...")try:ds = load_dataset(DATASET_REPO, split="train")389 unmodified linesdef on_export_pdf(results_state, query_state, keywords_state, context_state, synthesis_state):"""Déclenché au clic sur le bouton export — appelle le LLM dédié et génère le PDF."""if not results_state:return Nonepath = generate_pdf_report(combined_query=query_state,keywords=keywords_state,1 unmodified linellm_context=context_state[:4000],synthesis=synthesis_state)return pathdef results_html_error(msg):return f"<div style='color: red; padding: 20px; border: 1px solid red; border-radius: 8px;'>{msg}</div>"def transcribe_and_append(audio_path, existing_text):"""Transcrit l'audio via Whisper et l'ajoute au texte existant dans le Textbox."""if audio_path is None:return existing_text or ""try:with open(audio_path, "rb") as f:result = whisper_client.automatic_speech_recognition(f,generate_kwargs={"language": "french"})transcript = result.text.strip()separator = "\n" if existing_text and existing_text.strip() else ""return (existing_text or "") + separator + transcriptexcept Exception as e:print(f"❌ Erreur Whisper : {e}")return existing_text or ""# ---------------------------------------------------------------------------# INTERFACE GRADIO# ---------------------------------------------------------------------------20 unmodified linesplaceholder="Ex: J'aime l'informatique, le contact client...",lines=3)audio_input = gr.Audio(sources=["microphone"],type="filepath",label="🎤 Ou dictez votre profil")transcribe_button = gr.Button("📝 Transcrire vers le formulaire", variant="secondary")file_input = gr.File(label="Ou uploadez votre CV (PDF)", file_types=[".pdf"])with gr.Column(scale=2):16 unmodified linesgr.Markdown("### 📋 Fiches Métiers suggérées")results_output = gr.HTML()# 0. Transcription audio → Textboxtranscribe_button.click(fn=transcribe_and_append,inputs=[audio_input, query_input],outputs=[query_input])# 1. Recherche + streaming LLMsearch_button.click(fn=search_and_chat,11 unmodified linesexport_button.click(fn=on_export_pdf,inputs=[results_state, query_state, keywords_state, context_state, synthesis_state],outputs=[pdf_output, pdf_output] # path + visible).then(fn=lambda: gr.update(visible=True),outputs=[pdf_output])if __name__ == "__main__":
app.py+40-3