Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,49 +11,70 @@ st.set_page_config(
|
|
| 11 |
initial_sidebar_state="expanded"
|
| 12 |
)
|
| 13 |
|
| 14 |
-
# Custom CSS for styling
|
| 15 |
st.markdown("""
|
| 16 |
<style>
|
| 17 |
.stApp {
|
| 18 |
-
background-image: linear-gradient(
|
| 19 |
}
|
| 20 |
.sidebar .sidebar-content {
|
| 21 |
-
background-image: linear-gradient(
|
| 22 |
color: white;
|
| 23 |
}
|
| 24 |
.stTextInput>div>div>input {
|
| 25 |
border-radius: 20px;
|
| 26 |
padding: 10px 15px;
|
|
|
|
| 27 |
}
|
| 28 |
.stButton>button {
|
| 29 |
border-radius: 20px;
|
| 30 |
padding: 10px 25px;
|
| 31 |
-
background-image: linear-gradient(to right, #
|
| 32 |
color: white;
|
| 33 |
border: none;
|
|
|
|
|
|
|
| 34 |
}
|
| 35 |
.stButton>button:hover {
|
| 36 |
-
background-image: linear-gradient(to right, #
|
|
|
|
|
|
|
| 37 |
}
|
| 38 |
.chat-container {
|
| 39 |
-
background-color: rgba(255, 255, 255, 0.
|
| 40 |
border-radius: 15px;
|
| 41 |
padding: 20px;
|
| 42 |
-
box-shadow: 0 4px
|
|
|
|
| 43 |
}
|
| 44 |
.title {
|
| 45 |
-
color: #
|
| 46 |
text-align: center;
|
| 47 |
margin-bottom: 30px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
}
|
| 49 |
</style>
|
| 50 |
""", unsafe_allow_html=True)
|
| 51 |
|
| 52 |
# Sidebar
|
| 53 |
with st.sidebar:
|
| 54 |
-
st.title("
|
| 55 |
st.markdown("""
|
| 56 |
-
### About
|
| 57 |
This is a ChatGPT-style chatbot powered by a fine-tuned LLM.
|
| 58 |
""")
|
| 59 |
|
|
@@ -65,13 +86,13 @@ with st.sidebar:
|
|
| 65 |
)
|
| 66 |
|
| 67 |
# Advanced settings
|
| 68 |
-
with st.expander("Advanced Settings"):
|
| 69 |
max_length = st.slider("Max response length", 50, 500, 100)
|
| 70 |
temperature = st.slider("Temperature", 0.1, 1.0, 0.7)
|
| 71 |
top_p = st.slider("Top-p", 0.1, 1.0, 0.9)
|
| 72 |
|
| 73 |
st.markdown("---")
|
| 74 |
-
st.markdown("Built with ❤️ using [Streamlit](https://streamlit.io/) and [Hugging Face](https://huggingface.co/)")
|
| 75 |
|
| 76 |
# Initialize chat history
|
| 77 |
if 'generated' not in st.session_state:
|
|
@@ -135,7 +156,7 @@ st.markdown("""
|
|
| 135 |
chat_container = st.container()
|
| 136 |
|
| 137 |
# Load model button
|
| 138 |
-
if st.button("Load Model"):
|
| 139 |
with st.spinner(f"Loading {model_name}..."):
|
| 140 |
st.session_state['model'], st.session_state['tokenizer'] = load_model(model_name)
|
| 141 |
st.success(f"Model {model_name} loaded successfully!")
|
|
@@ -150,17 +171,17 @@ with chat_container:
|
|
| 150 |
# User input
|
| 151 |
with st.form(key='chat_form', clear_on_submit=True):
|
| 152 |
user_input = st.text_input("You:", key='input', placeholder="Type your message here...")
|
| 153 |
-
submit_button = st.form_submit_button(label='Send')
|
| 154 |
|
| 155 |
if submit_button and user_input:
|
| 156 |
if st.session_state['model'] is None or st.session_state['tokenizer'] is None:
|
| 157 |
-
st.warning("Please load the model first!")
|
| 158 |
else:
|
| 159 |
# Add user message to chat history
|
| 160 |
st.session_state['past'].append(user_input)
|
| 161 |
|
| 162 |
# Generate response
|
| 163 |
-
with st.spinner("Thinking..."):
|
| 164 |
response = generate_response(user_input)
|
| 165 |
|
| 166 |
# Add bot response to chat history
|
|
|
|
| 11 |
initial_sidebar_state="expanded"
|
| 12 |
)
|
| 13 |
|
| 14 |
+
# Custom CSS for styling with beautiful colors
|
| 15 |
st.markdown("""
|
| 16 |
<style>
|
| 17 |
.stApp {
|
| 18 |
+
background-image: linear-gradient(135deg, #f5f7fa 0%, #e4f0f8 100%);
|
| 19 |
}
|
| 20 |
.sidebar .sidebar-content {
|
| 21 |
+
background-image: linear-gradient(135deg, #6B73FF 0%, #000DFF 100%);
|
| 22 |
color: white;
|
| 23 |
}
|
| 24 |
.stTextInput>div>div>input {
|
| 25 |
border-radius: 20px;
|
| 26 |
padding: 10px 15px;
|
| 27 |
+
border: 1px solid #d1d5db;
|
| 28 |
}
|
| 29 |
.stButton>button {
|
| 30 |
border-radius: 20px;
|
| 31 |
padding: 10px 25px;
|
| 32 |
+
background-image: linear-gradient(to right, #6B73FF 0%, #000DFF 100%);
|
| 33 |
color: white;
|
| 34 |
border: none;
|
| 35 |
+
font-weight: 500;
|
| 36 |
+
transition: all 0.3s ease;
|
| 37 |
}
|
| 38 |
.stButton>button:hover {
|
| 39 |
+
background-image: linear-gradient(to right, #000DFF 0%, #6B73FF 100%);
|
| 40 |
+
transform: translateY(-2px);
|
| 41 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
| 42 |
}
|
| 43 |
.chat-container {
|
| 44 |
+
background-color: rgba(255, 255, 255, 0.95);
|
| 45 |
border-radius: 15px;
|
| 46 |
padding: 20px;
|
| 47 |
+
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
|
| 48 |
+
border: 1px solid #e5e7eb;
|
| 49 |
}
|
| 50 |
.title {
|
| 51 |
+
color: #2d3748;
|
| 52 |
text-align: center;
|
| 53 |
margin-bottom: 30px;
|
| 54 |
+
font-weight: 600;
|
| 55 |
+
}
|
| 56 |
+
.stSelectbox>div>div>select {
|
| 57 |
+
border-radius: 12px;
|
| 58 |
+
padding: 8px 12px;
|
| 59 |
+
}
|
| 60 |
+
.stSlider>div>div>div>div {
|
| 61 |
+
background-color: #6B73FF;
|
| 62 |
+
}
|
| 63 |
+
.st-expander {
|
| 64 |
+
border-radius: 12px;
|
| 65 |
+
border: 1px solid #e5e7eb;
|
| 66 |
+
}
|
| 67 |
+
.stMarkdown h1 {
|
| 68 |
+
color: #2d3748;
|
| 69 |
}
|
| 70 |
</style>
|
| 71 |
""", unsafe_allow_html=True)
|
| 72 |
|
| 73 |
# Sidebar
|
| 74 |
with st.sidebar:
|
| 75 |
+
st.title("⚙️ Chatbot Settings")
|
| 76 |
st.markdown("""
|
| 77 |
+
### ✨ About
|
| 78 |
This is a ChatGPT-style chatbot powered by a fine-tuned LLM.
|
| 79 |
""")
|
| 80 |
|
|
|
|
| 86 |
)
|
| 87 |
|
| 88 |
# Advanced settings
|
| 89 |
+
with st.expander("🔧 Advanced Settings"):
|
| 90 |
max_length = st.slider("Max response length", 50, 500, 100)
|
| 91 |
temperature = st.slider("Temperature", 0.1, 1.0, 0.7)
|
| 92 |
top_p = st.slider("Top-p", 0.1, 1.0, 0.9)
|
| 93 |
|
| 94 |
st.markdown("---")
|
| 95 |
+
st.markdown("🚀 Built with ❤️ using [Streamlit](https://streamlit.io/) and [Hugging Face](https://huggingface.co/)")
|
| 96 |
|
| 97 |
# Initialize chat history
|
| 98 |
if 'generated' not in st.session_state:
|
|
|
|
| 156 |
chat_container = st.container()
|
| 157 |
|
| 158 |
# Load model button
|
| 159 |
+
if st.button("🚀 Load Model"):
|
| 160 |
with st.spinner(f"Loading {model_name}..."):
|
| 161 |
st.session_state['model'], st.session_state['tokenizer'] = load_model(model_name)
|
| 162 |
st.success(f"Model {model_name} loaded successfully!")
|
|
|
|
| 171 |
# User input
|
| 172 |
with st.form(key='chat_form', clear_on_submit=True):
|
| 173 |
user_input = st.text_input("You:", key='input', placeholder="Type your message here...")
|
| 174 |
+
submit_button = st.form_submit_button(label='Send ➤')
|
| 175 |
|
| 176 |
if submit_button and user_input:
|
| 177 |
if st.session_state['model'] is None or st.session_state['tokenizer'] is None:
|
| 178 |
+
st.warning("⚠️ Please load the model first!")
|
| 179 |
else:
|
| 180 |
# Add user message to chat history
|
| 181 |
st.session_state['past'].append(user_input)
|
| 182 |
|
| 183 |
# Generate response
|
| 184 |
+
with st.spinner("🤔 Thinking..."):
|
| 185 |
response = generate_response(user_input)
|
| 186 |
|
| 187 |
# Add bot response to chat history
|