import gradio as gr from gradio.components import ChatMessage # Initialize prompt and system template init_prompt = """ Hello, I am ClimateQ&A, a conversational assistant designed to help you understand climate change and biodiversity loss. I will answer your questions by **sifting through the IPCC and IPBES scientific reports**. ❓ How to use - **Language**: You can ask me your questions in any language. - **Audience**: You can specify your audience (children, general public, experts) to get a more adapted answer. - **Sources**: You can choose to search in the IPCC or IPBES reports, or both. - **Relevant content sources**: You can choose to search for figures, papers, or graphs that can be relevant for your question. ⚠️ Limitations *Please note that the AI is not perfect and may sometimes give irrelevant answers. If you are not satisfied with the answer, please ask a more specific question or report your feedback to help us improve the system.* 🛈 Information Please note that we log your questions for meta-analysis purposes, so avoid sharing any sensitive or personal information. What do you want to learn ? """ # init_prompt_poc = """ # Bonjour, je suis ClimateQ&A, un assistant conversationnel conçu pour vous aider à comprendre le changement climatique et la perte de biodiversité. Je réponds à vos questions en **parcourant les rapports scientifiques du GIEC et de l'IPBES, le PCAET de Paris, le Plan Biodiversité 2018-2024, et les rapports Acclimaterra de la Région Nouvelle-Aquitaine**. # ❓ Mode d'emploi # - **Language** : Vous pouvez me poser vos questions dans n'importe quelle langue. # - **Audience** : Vous pouvez préciser votre public (enfants, grand public, experts) pour obtenir une réponse plus adaptée. # - **Sources** : Vous pouvez choisir de chercher dans les rapports du GIEC ou de l'IPBES, et dans les sources POC pour les documents locaux (PCAET, Plan Biodiversité, Acclimaterra). # - **Relevant content sources** : Vous pouvez choisir de rechercher des images, des papiers scientifiques ou des graphiques qui peuvent être pertinents pour votre question. # ⚠️ Limitations # *Veuillez noter que l'IA n'est pas parfaite et peut parfois donner des réponses non pertinentes. Si vous n'êtes pas satisfait de la réponse, veuillez poser une question plus précise ou nous faire part de vos commentaires pour nous aider à améliorer le système.* # 🛈 Informations # Veuillez noter que nous enregistrons vos questions à des fins de méta-analyse, évitez donc de partager toute information sensible ou personnelle. # Que voulez-vous apprendre ? # """ init_prompt_poc = """ Hello, I am ClimateQ&A, a conversational assistant designed to help you understand climate change and biodiversity loss. I will answer your questions by **sifting through the IPCC and IPBES scientific reports, the Paris Climate Action Plan (PCAET), the Biodiversity Plan 2018-2024, and the Acclimaterra reports from the Nouvelle-Aquitaine Region**. ❓ How to use - **Language**: You can ask me your questions in any language. - **Audience**: You can specify your audience (children, general public, experts) to get a more adapted answer. - **Sources**: You can choose to search in the IPCC or IPBES reports, or both. - **Relevant content sources**: You can choose to search for figures, papers, or graphs that can be relevant for your question. ⚠️ Limitations *Please note that the AI is not perfect and may sometimes give irrelevant answers. If you are not satisfied with the answer, please ask a more specific question or report your feedback to help us improve the system.* 🛈 Information Please note that we log your questions for meta-analysis purposes, so avoid sharing any sensitive or personal information. What do you want to learn ? """ # UI Layout Components def create_chat_interface(tab): init_prompt_message = init_prompt_poc if tab == "France - Local Q&A" else init_prompt chatbot = gr.Chatbot( value=[ChatMessage(role="assistant", content=init_prompt_message)], type="messages", show_copy_button=True, show_label=False, elem_id="chatbot", layout="panel", avatar_images=(None, "https://i.ibb.co/YNyd5W2/logo4.png"), max_height="80vh", height="100vh" ) with gr.Accordion("Click here for follow up questions examples", elem_id="follow-up-examples",open = False): follow_up_examples_hidden = gr.Textbox(visible=False, elem_id="follow-up-hidden") follow_up_examples = gr.Examples(examples=["What evidence do we have of climate change ?"], label="", inputs= [follow_up_examples_hidden], elem_id="follow-up-button", run_on_click=False) with gr.Row(elem_id="input-message"): textbox = gr.Textbox( placeholder="Ask me anything here!", show_label=False, scale=12, lines=1, interactive=True, elem_id=f"input-textbox" ) config_button = gr.Button("", elem_id="config-button") return chatbot, textbox, config_button, follow_up_examples, follow_up_examples_hidden