Download app.py from Kaihnn/tests: direct link, hf CLI and curl.
- Browser
- Download file 1.77 kB
-
https://huggingface.co/spaces/Kaihnn/tests/resolve/main/app.py
- Command line
-
hf download hf://spaces/Kaihnn/tests/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Kaihnn/tests/resolve/main/app.py
1.77 kB
| import gradio as gr | |
| import os | |
| from huggingface_hub import InferenceClient | |
| # Définir l'outil HuggingFace pour la génération de texte | |
| hf_token = os.environ.get("HF_TOKEN") | |
| if not hf_token: | |
| raise RuntimeError("Clé API HuggingFace manquante (variable d'environnement HF_TOKEN).") | |
| client = InferenceClient(token=hf_token) | |
| # Fonction IA pour générer un post LinkedIn via smolagent | |
| def generer_post_linkedin(theme): | |
| completion = client.chat.completions.create( | |
| model="deepseek-ai/DeepSeek-V3-0324", | |
| messages=[ | |
| { | |
| "role": "system", | |
| "content": ( | |
| "Tu es un expert en posts LinkedIn. " | |
| "Tes réponses sont inspirantes, et en français " | |
| "Tes réponses contiennent des smileys. Presque au point de remplacer la poncturation" | |
| "C'est à chaque fois un exemple de la vie de tout les jours, qui peut être appliqué dans la vie professionnelle. " | |
| "Il y a une touche hautaine, mais ça se veut inspirant. " | |
| "Il faut utiliser des néologismes." | |
| ) | |
| }, | |
| { | |
| "role": "user", | |
| "content": "Generate a linkedin post for the following theme: " + theme | |
| } | |
| ], | |
| ) | |
| return completion.choices[0].message.content | |
| # Interface Gradio | |
| with gr.Blocks() as demo: | |
| gr.Markdown("## Générateur de post LinkedIn (IA)") | |
| theme_input = gr.Textbox(label="Entrez un thème ou une phrase") | |
| bouton_post = gr.Button("Générer le post LinkedIn") | |
| post_output = gr.Textbox(label="Post LinkedIn généré") | |
| bouton_post.click(generer_post_linkedin, inputs=theme_input, outputs=post_output) | |
| demo.launch(share=True) |