The code:


import streamlit as st
from gradio_client import Client
import os

# Set page configuration to 'wide' and restore default menu and footer
st.set_page_config(
    page_title="LLM Chat Application",
    layout="wide",  # Sets the interface to wide mode
    initial_sidebar_state="auto"
)

# Constants
HISTORY_FILE = 'history.txt'
MODEL_CLIENT_NAME = 'yuntian-deng/ChatGPT4'  # Replace with your actual model identifier

# Function to load history from the file
def load_history():
    if os.path.exists(HISTORY_FILE):
        with open(HISTORY_FILE, 'r', encoding='utf-8') as f:
            return f.read()
    return ""

# Function to save history to the file
def save_history(history):
    with open(HISTORY_FILE, 'w', encoding='utf-8') as f:
        f.write(history)

# Initialize session state for history
if 'history' not in st.session_state:
    st.session_state.history = load_history()

# Optionally, you can hide the footer if desired, but we'll keep the settings wheel visible
# If you wish to hide the footer, uncomment the following CSS
# hide_footer = """
#             <style>
#             footer {visibility: hidden;}
#             </style>
#             """
# st.markdown(hide_footer, unsafe_allow_html=True)

# Create a form for input
with st.form("chat_form", clear_on_submit=False):
    # Editable text area for chat history and input
    history_input = st.text_area(
        "Chat History & Input",
        value=st.session_state.history,
        height=400,
        key='history_input',
        placeholder="Start chatting...",
    )
    
    # Generate Response button
    generate = st.form_submit_button("Generate Response")
    
    # Sliders for Temperature and Top-P sampling
    col1, col2 = st.columns(2)
    with col1:
        temperature = st.slider(
            "Temperature",
            min_value=0.0,
            max_value=5.0,
            value=1.0,
            step=0.1,
            help="Controls the randomness of the model's output. Higher values like 1.0 make the output more random, while lower values like 0.2 make it more focused and deterministic."
        )
    with col2:
        top_p = st.slider(
            "Top-P Sampling",
            min_value=0.0,
            max_value=1.0,
            value=1.0,
            step=0.05,
            help="Nucleus sampling: the model considers the smallest set of tokens with a cumulative probability above this value."
        )

# Handle manual edits to the chat history
if history_input != st.session_state.history:
    st.session_state.history = history_input
    save_history(history_input)

# Handle form submission
if generate:
    try:
        # Initialize the client
        client = Client(MODEL_CLIENT_NAME)

        # Prepare inputs - assuming the model expects the full history as a single string
        prompt = st.session_state.history

        # Call the model to get a response
        result = client.predict(
            inputs=prompt,
            top_p=top_p,
            temperature=temperature,
            chat_counter=0,
            chatbot=[],
            api_name='/predict'
        )
        # Adjust based on actual API response structure
        output = result[0][0][1].strip()

        # Append model response to history
        # Ensure there's a newline before appending
        if not st.session_state.history.endswith('\n'):
            st.session_state.history += f"\n{output}"
        else:
            st.session_state.history += f"{output}"

        # Save the updated history to the file
        save_history(st.session_state.history)

        # Update the text area to reflect the new history
        # This ensures that the UI displays the latest conversation
        st.session_state.history_input = st.session_state.history

        st.success("LLM response generated and appended to history.")

    except Exception as e:
        st.error(f"Error communicating with the model: {e}")
Yields the error:


Error communicating with the model: st.session_state.history_input cannot be modified after the widget with key history_input is instantiated.
I want you to add a new "send message" box, and refresh (or recreate) the history box after every generation. In fact, you should reload dynamically the whole page every time, storing the top-p and temperature in a config file.