Spaces:
Sleeping
Update app.py
Browse filesUI Enhancements (Already Included):
Custom CSS for a clean, modern look (light background, rounded inputs, styled buttons).
Improved typography with Roboto font and hierarchy (title, subtitle).
Responsive layout using st.container() and st.columns().
Chat-Like Output:
Session state (st.session_state.chat_history) stores input/output pairs as dictionaries.
Each entry is displayed with the user’s input and generated code in a conversational format.
Timestamps:
Added from datetime import datetime to include timestamps.
Each chat entry now includes a "time" key with the current time (e.g., "14:35:22"), shown next to "You" in the UI.
Clear History Button:
Added a "Clear History" button in the second column (col2), which resets st.session_state.chat_history to an empty list.
Displays a success message ("Chat history cleared!") for feedback.
Layout Adjustments:
Adjusted st.columns([1, 1]) to balance the "Generate" and "Clear History" buttons side by side.
Kept the chat history and tip below the input area for a natural flow.
@@ -1,5 +1,6 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
|
|
3 |
|
4 |
# Custom CSS for a Grok/ChatGPT-like look
|
5 |
st.markdown("""
|
@@ -94,24 +95,31 @@ with st.container():
|
|
94 |
height=150
|
95 |
)
|
96 |
|
97 |
-
col1, col2 = st.columns([1,
|
98 |
with col1:
|
99 |
if st.button("Generate"):
|
100 |
if description.strip():
|
101 |
with st.spinner("Thinking..."):
|
102 |
generated_code = generate_code(description)
|
103 |
-
# Append to chat history
|
104 |
-
st.session_state.chat_history.append({
|
|
|
|
|
|
|
|
|
105 |
else:
|
106 |
st.warning("Please enter a description first!")
|
|
|
107 |
with col2:
|
108 |
-
st.
|
|
|
|
|
109 |
|
110 |
# Display chat history
|
111 |
if st.session_state.chat_history:
|
112 |
st.write("### Chat History")
|
113 |
for chat in st.session_state.chat_history:
|
114 |
-
st.markdown(f'<div class="chat-message"><strong>You:</strong> {chat["input"]}</div>', unsafe_allow_html=True)
|
115 |
st.markdown(f'<div class="code-output">{chat["output"]}</div>', unsafe_allow_html=True)
|
116 |
st.markdown("---") # Separator for readability
|
117 |
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
+
from datetime import datetime
|
4 |
|
5 |
# Custom CSS for a Grok/ChatGPT-like look
|
6 |
st.markdown("""
|
|
|
95 |
height=150
|
96 |
)
|
97 |
|
98 |
+
col1, col2 = st.columns([1, 1]) # Adjusted for two buttons
|
99 |
with col1:
|
100 |
if st.button("Generate"):
|
101 |
if description.strip():
|
102 |
with st.spinner("Thinking..."):
|
103 |
generated_code = generate_code(description)
|
104 |
+
# Append to chat history with timestamp
|
105 |
+
st.session_state.chat_history.append({
|
106 |
+
"input": description,
|
107 |
+
"output": generated_code,
|
108 |
+
"time": datetime.now().strftime("%H:%M:%S")
|
109 |
+
})
|
110 |
else:
|
111 |
st.warning("Please enter a description first!")
|
112 |
+
|
113 |
with col2:
|
114 |
+
if st.button("Clear History"):
|
115 |
+
st.session_state.chat_history = []
|
116 |
+
st.success("Chat history cleared!")
|
117 |
|
118 |
# Display chat history
|
119 |
if st.session_state.chat_history:
|
120 |
st.write("### Chat History")
|
121 |
for chat in st.session_state.chat_history:
|
122 |
+
st.markdown(f'<div class="chat-message"><strong>You ({chat["time"]}):</strong> {chat["input"]}</div>', unsafe_allow_html=True)
|
123 |
st.markdown(f'<div class="code-output">{chat["output"]}</div>', unsafe_allow_html=True)
|
124 |
st.markdown("---") # Separator for readability
|
125 |
|