Spaces:
Runtime error
Runtime error
| import google.generativeai as genai | |
| genai.configure(api_key="AIzaSyCdIOCNM7NmCeu5TS30TxZx6ldN4gSDoTI") | |
| def call_ai_api(prompt): | |
| # Set up the model | |
| generation_config = { | |
| "temperature": 1, | |
| "top_p": 0.95, | |
| "max_output_tokens": 5000000, | |
| } | |
| model = genai.GenerativeModel(model_name="gemini-1.5-pro-latest", | |
| generation_config=generation_config) | |
| response = model.generate_content(prompt) | |
| return response.text | |
| def generer_prompt_seo(titre_article, mot_cle_principal, ton_cible, mots_cles_associes): | |
| mots_cles_lexicaux = mots_cles_associes | |
| prompt = f""" | |
| CONTEXTE: | |
| Veuillez écrire un article de 1500 - 2000 mots. N'hésitez pas à prendre votre temps pour réfléchir à votre réponse j'ai besoin d'un long article. | |
| Vous êtes un rédacteur SEO chargé de composer un article de blog optimisé pour le SEO sur le sujet suivant. | |
| Voici les informations et directives à suivre : | |
| Titre de l'article : {titre_article} | |
| Mot-clé principal : {mot_cle_principal} | |
| Ton et/ou public cible : {ton_cible} | |
| Mots-clés lexicaux à inclure : {mots_cles_lexicaux} | |
| INSTRUCTIONS: | |
| NOMBRE DE MOTS : 1000 à 1500 | |
| ### Règles de rédaction : | |
| N'hésitez pas à prendre votre temps pour réfléchir à votre réponse j'ai besoin d'un long article. | |
| 1. Structure de l'article avec des titres hiérarchisés. | |
| 2. Optimisation du mot-clé principal (densité d'environ 1,5%, utilisation dans le titre SEO, méta description, et répartition uniforme). | |
| 3. Inclusion de sous-titres et de mots-clés LSI pour enrichir le contenu sans bourrage de mots-clés. | |
| 4. Titres et méta descriptions attractifs avec appels à l'action. | |
| 5. Ton informatif et engageant, avec une variété de vocabulaire. | |
| 6. Introduction et conclusion engageantes avec le mot-clé principal. | |
| 7. Section FAQ avec trois questions/réponses courtes. | |
| 8. Au moins un lien externe vers une source crédible. | |
| N'hésitez pas à prendre votre temps pour réfléchir à votre réponse j'ai besoin d'un long article. | |
| Assurez que l'article soit lisible, bien structuré et visuellement attrayant. | |
| """ | |
| return prompt | |
| def generate_seo_prompt(article_title, main_keyword, target_tone, associated_keywords): | |
| lexical_keywords = associated_keywords | |
| prompt = f""" | |
| CONTEXT: | |
| Please write an article of 1500 - 2000 words. Feel free to take your time to think about your response, I need a long article. | |
| You are an SEO writer tasked with composing an SEO-optimized blog article on the following topic. | |
| Here are the information and guidelines to follow: | |
| Article title: {article_title} | |
| Main keyword: {main_keyword} | |
| Target tone and/or audience: {target_tone} | |
| Lexical keywords to include: {lexical_keywords} | |
| INSTRUCTIONS: | |
| WORD COUNT: 1000 to 1500 | |
| ### Writing rules: | |
| Feel free to take your time to think about your response, I need a long article. | |
| 1. Structure the article with hierarchical headings. | |
| 2. Optimize the main keyword (density of about 1.5%, use in the SEO title, meta description, and evenly distributed). | |
| 3. Include subheadings and LSI keywords to enrich the content without keyword stuffing. | |
| 4. Attractive titles and meta descriptions with calls to action. | |
| 5. Informative and engaging tone, with a variety of vocabulary. | |
| 6. Engaging introduction and conclusion with the main keyword. | |
| 7. FAQ section with three short questions/answers. | |
| 8. At least one external link to a credible source. | |
| Feel free to take your time to think about your response, I need a long article. | |
| Ensure that the article is readable, well-structured, and visually appealing. | |
| """ | |
| return prompt | |
| def create_pipeline_fr(titre_article, mot_cle_principal, ton_cible): | |
| # Initial AI API call | |
| mots_cles_champ_lexical=generer_mots(titre_article,mot_cle_principal) | |
| pp=generer_prompt_seo(titre_article, mot_cle_principal, ton_cible, mots_cles_champ_lexical) | |
| rep = call_ai_api(pp) | |
| # Second AI API call with additional elaboration request | |
| prompt2 = f"D'après le prompt {pp}, j'ai eu le résultat suivant : {rep}. Élaborer plus que ça." | |
| rep2 = call_ai_api(prompt2) | |
| # Third AI API call with further instructions | |
| prompt3 = (f"D'après le prompt {pp}, j'ai eu le résultat suivant : {rep}. Élaborer plus que ça. {rep2} " | |
| "Le texte est toujours beaucoup trop court. Aussi, il n'y a aucune gestion des titres, le premier est un H2, " | |
| "et les sous-titres sont balisés comme des paragraphes. Concernant le lien tout à la fin, il faudrait qu'il soit intégré au texte. " | |
| "Dernier point, la meta description ne doit pas apparaître quand on demande un article.") | |
| rep3 = call_ai_api(prompt3) | |
| # Fourth AI API call to fix title issues and meta description | |
| prompt4 = ("Fix ça : Mauvaise gestion des titres, le premier titre doit être un H1. Le mot-clé principal n'est pas assez utilisé, il faut une densité de 1,5%. " | |
| "Le titre ne doit contenir une majuscule que sur le premier mot de la phrase, pas sur les autres. " | |
| "La meta description ne doit pas être rédigée. " + rep3) | |
| rep4 = call_ai_api(prompt4) | |
| # Fifth AI API call to fix keyword density and internal link | |
| prompt5 = (f"Fix ça - Le mot-clé principal : {mot_cle_principal} n'est pas assez utilisé, il faut une densité de 1,5% environ. " | |
| "Ajoute un lien à l'intérieur d'un texte, et rends le FAQ après la conclusion. et n'ajoute pas de remarque a la fin je veux que dans la sortie que du texte " + rep4) | |
| rep5 = call_ai_api(prompt5) | |
| # Sixth AI API call to ensure the text length | |
| prompt6 = ("Trop court, seulement j'aurai besoin de 1500 mots minimum attendu. " | |
| "Laisse la même structure de texte, ajoute juste du contenu. " + rep5) | |
| rep6 = call_ai_api(prompt6) | |
| return rep6 | |
| def create_pipeline(article_title, main_keyword, target_tone): | |
| # Initial AI API call | |
| lexical_field_keywords=generate_words(article_title, main_keyword) | |
| pp = generate_seo_prompt(article_title, main_keyword, target_tone, lexical_field_keywords) | |
| rep = call_ai_api(pp) | |
| # Second AI API call with additional elaboration request | |
| prompt2 = f"Based on the prompt {pp}, I got the following result: {rep}. Elaborate further." | |
| rep2 = call_ai_api(prompt2) | |
| # Third AI API call with further instructions | |
| prompt3 = (f"Based on the prompt {pp}, I got the following result: {rep}. Elaborate further. {rep2} " | |
| "The text is still way too short. Also, there is no title management, the first title is an H2, " | |
| "and the subtitles are marked as paragraphs. Regarding the link at the end, it should be integrated into the text. " | |
| "Lastly, the meta description should not appear when requesting an article.") | |
| rep3 = call_ai_api(prompt3) | |
| # Fourth AI API call to fix title issues and meta description | |
| prompt4 = ("Fix this: Poor title management, the first title must be an H1. The main keyword is not used enough, it should have a density of 1.5%. " | |
| "The title should only have a capital letter on the first word of the sentence, not on the others. " | |
| "The meta description should not be written. " + rep3) | |
| rep4 = call_ai_api(prompt4) | |
| # Fifth AI API call to fix keyword density and internal link | |
| prompt5 = (f"Fix this - The main keyword: {main_keyword} is not used enough, it should have a density of about 1.5%. " | |
| "Add a link inside the text, and place the FAQ after the conclusion. " + rep4) | |
| rep5 = call_ai_api(prompt5) | |
| # Sixth AI API call to ensure the text length | |
| prompt6 = ("Too short, I need a minimum of 1500 words expected. " | |
| "Keep the same text structure, just add more content. " + rep5) | |
| rep6 = call_ai_api(prompt6) | |
| return rep6 | |
| def generer_mots(titre_article,mot_cle_principal): | |
| words=call_ai_api("Generes moi des mots-clés similaires a partir de ca ( SEULEMENT DES MOTS OU GROUPE DE MOTS séparés par virgules ) :"+titre_article+" et "+mot_cle_principal) | |
| return words | |
| def generate_words(article_title, main_keyword): | |
| words = call_ai_api("Generate similar keywords from these (ONLY WORDS OR GROUPS OF WORDS separated by commas): " + article_title + " and " + main_keyword) | |
| return words | |