The code: import streamlit as st from gradioclient import Client import os Set page…
- User
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 = """
footer {visibility: hidden;}
"""
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...", )
code# 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." ) - Assistant