with gr.Column(visible=False) as landing_page:
gr.Markdown("", elem_id="land-spacer")
gr.Markdown("<h3>---Welcome to Tree Correspondents</h3>", elem_id="land-intro")
gr.Markdown("<p>Where the wisdom of the forests meets the power of journalism</p>"
"<p>You've arrived at a newsroom like any other - one where trees speak through science<br>"
"and stories. Across the world, sensors placed in the soil, trunks, and canopies of<br>"
"trees are collecting real-time environmental data."
gr.Markdown("<h3>---This tool was built for journalists.</h3>", elem_id="land-intro")
gr.Markdown("<p>Where the wisdom of the forests meets the power of journalism</p>"
"<p>You've arrived at a newsroom like any other - one where trees speak through science<br>"
"and stories. Across the world, sensors placed in the soil, trunks, and canopies of<br>"
"trees are collecting real-time environmental data."
email_input = gr.Textbox(
placeholder="What is your email?",
placeholder="What press organization do you work for?",
with gr.Row(visible=False) as error_message:
floating_message = gr.Markdown(value="<h5>Please **fill in both Email and Organization fields!</h5>", elem_id="floating-message")
with gr.Row(visible=False) as bad_email:
floating_message_2 = gr.Markdown(value="<h5>This is not a valid email format</h5>", elem_id="floating-message-2")
"Let's write stories the world needs to read.")
gr.Markdown("", elem_id="one-line-spacer")
begin_button = gr.Button("start", elem_id="start-button")
#floating_message = gr.HTML(value="", elem_id="floating-message")
with gr.Column(visible=True) as base_ui:
# Add a flexible top spacer for centering effect
gr.Markdown("", elem_id="top-spacer")
gr.Markdown("<h1 style='text-align:center;'>🌲 Tree Correspondents 🌲</h1>", elem_id="title")
# Empty space for vertical adjustment
gr.Markdown("", height=30)
# Button container for selection
gr.Markdown("Select Region")
#site_radio = gr.Radio(["Czechia/Travný", "Brazil/Viçosa", "Korea/Hongcheon"])
site_selection = gr.Dropdown(["Czechia/Travný", "Brazil/Viçosa", "Korea/Hongcheon"], label="Select Region",
value="Brazil/Viçosa", interactive=True, allow_custom_value=False,
filterable=False, container=False, elem_id="country_dropdown", scale=1)
# chain_button = gr.Button("📝 Article Generation", scale=1)
chat_button = gr.Button("🌿 Start Conversation 🌿", scale=3)
# Add a flexible bottom spacer to push elements to the center
gr.Markdown("", elem_id="bottom-spacer")
# ===========================================
# ===========================================
# 🔹 CHAT UI (Initially Hidden)
# ===========================================
# ===========================================
with gr.Column(visible=False) as chat_ui:
gr.Markdown("## 🌲 Tree Correspondents / 🌿 **In Conversation**"
selected_region = gr.Markdown("Select Region")
# site_selection = gr.Dropdown(["Czechia/Travný", "Brazil/Viçosa", "Korea/Hongcheon"], label="Select Region",
# value="Brazil/Viçosa", interactive=True, allow_custom_value=False,
# filterable=False, container=False, elem_id="country_dropdown")
general_instruction = gr.Textbox(label="Journalist Role", interactive=True, visible=False, value=parameters['general_instruction'], lines=3)
refine_state = gr.State(True)
user_input = gr.Textbox(label="Enter your message", interactive=True, lines=4)
send_button = gr.Button("Send")
reset_button = gr.Button("Reset Chat")
conversation_box = gr.Chatbot(label="Tree Chat", elem_id="tree_chatbox")
# Empty space for vertical adjustment
# gr.Markdown("", elem_id="spacer")
# chat_download_btn = gr.Button("📥 Download History", variant="secondary")
# chat_file_output = gr.File(label="Download your history here")
# ===========================================
# ===========================================
# ===========================================
# ===========================================
# 🔹 Button Click Actions to Show UI
chat_button.click(show_chat_ui, outputs=[chat_ui, base_ui])
inputs=[email_input, org_input],
outputs=[error_message, bad_email, landing_page, base_ui]
# Button action: Process user input and update chatbox
chat_manager.generate_tree_response,
inputs=[general_instruction, user_input, conversation_box],
outputs=[conversation_box, user_input],
outputs=[conversation_box],
site_selection.change(handle_region_selection, inputs=site_selection, outputs=[selected_region])
#chat_download_btn.click(chat_manager.save_history, inputs=[conversation_box], outputs=[chat_file_output])
# Allow enter key submission
user_input.submit(chat_manager.generate_tree_response, [general_instruction, user_input, conversation_box],
[conversation_box, user_input])
demo.launch(server_name="0.0.0.0", server_port=PORT)