shiva9876 commited on
Commit
8ea8534
·
verified ·
1 Parent(s): 12ce1ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +109 -74
app.py CHANGED
@@ -3,7 +3,7 @@ import requests
3
  import re
4
  import uuid
5
 
6
- # Backend URL - Update this with your actual Hugging Face Space URL
7
  BACKEND_URL = "https://shiva9876-code-gen-backend.hf.space"
8
 
9
  # Page Config with Logo
@@ -16,13 +16,10 @@ st.set_page_config(
16
  # Custom CSS for Logo & UI
17
  st.markdown("""
18
  <style>
19
- /* Full Center Alignment */
20
- .main-container {
21
- display: flex;
22
- flex-direction: column;
23
- justify-content: center;
24
- align-items: center;
25
- height: 90vh;
26
  }
27
 
28
  /* Logo Centered */
@@ -40,6 +37,13 @@ st.markdown("""
40
  font-size: 28px;
41
  font-weight: bold;
42
  color: #03dac6;
 
 
 
 
 
 
 
43
  }
44
 
45
  /* Chatbox UI */
@@ -56,42 +60,43 @@ st.markdown("""
56
  .ai-message { border-left: 5px solid #ff9800; padding-left: 10px; }
57
  pre { white-space: pre-wrap; word-wrap: break-word; }
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  /* Search Bar Styling */
60
  .search-container {
61
  display: flex;
62
  align-items: center;
63
  width: 100%;
64
- max-width: 600px;
65
  margin: auto;
66
  }
67
 
68
- .search-input {
69
- flex-grow: 1;
70
- padding: 12px 15px;
71
- border-radius: 25px;
72
- border: 2px solid #03dac6;
73
- background-color: #262626;
74
- color: white;
75
- font-size: 16px;
76
- outline: none;
77
- }
78
-
79
- /* Search Button */
80
- .search-button {
81
- width: 50px;
82
- height: 50px;
83
- border-radius: 50%;
84
- border: none;
85
- background-color: #00ffcc;
86
- color: black;
87
- font-size: 16px;
88
- cursor: pointer;
89
- transition: 0.3s;
90
- text-align: center;
91
- }
92
-
93
- .search-button:hover {
94
- background-color: #02c2ad;
95
  }
96
 
97
  /* Clear Chat Button */
@@ -107,6 +112,35 @@ st.markdown("""
107
  .stButton>button:hover {
108
  background-color: #cc0000;
109
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  </style>
111
  """, unsafe_allow_html=True)
112
 
@@ -126,26 +160,30 @@ if "messages" not in st.session_state:
126
  if "session_id" not in st.session_state:
127
  st.session_state.session_id = str(uuid.uuid4())
128
 
129
- # Display chat history
130
- for msg in st.session_state.messages:
131
- if msg["role"] == "user":
132
- st.markdown(f'<div class="chat-container user-message"><b>You:</b><br>{msg["content"]}</div>',
133
- unsafe_allow_html=True)
134
- elif msg["role"] == "ai":
135
- content = msg["content"]
136
-
137
- # Check if it's a conversational response or code response
138
- if isinstance(content, tuple):
139
- explanation, code = content
140
- if explanation:
141
- st.markdown(f'<div class="chat-container ai-message"><b>AI:</b><br>{explanation}</div>',
 
 
 
 
 
 
 
 
 
 
142
  unsafe_allow_html=True)
143
- if code:
144
- st.code(code, language="python")
145
- else:
146
- # Simple text response (for conversational messages)
147
- st.markdown(f'<div class="chat-container ai-message"><b>AI:</b><br>{content}</div>',
148
- unsafe_allow_html=True)
149
 
150
  # Sidebar with options
151
  with st.sidebar:
@@ -175,18 +213,22 @@ with st.sidebar:
175
  st.divider()
176
  st.caption("💡 Tip: Ask coding questions or request code generation!")
177
 
178
- # Input Form
179
- st.markdown('<div class="search-container">', unsafe_allow_html=True)
180
-
181
- with st.form(key="input_form"):
182
- user_input = st.text_input(
183
- "Your Prompt:",
184
- key="user_prompt",
185
- placeholder="e.g., Write a function to sort a list or just say Hi!"
186
- )
187
 
188
- # Single send button
189
- submit_button = st.form_submit_button("SEND ↗️")
 
 
 
 
 
 
 
 
 
 
 
190
 
191
  st.markdown("</div>", unsafe_allow_html=True)
192
 
@@ -278,11 +320,4 @@ if submit_button:
278
  except Exception as e:
279
  st.error(f"❌ Unexpected error: {str(e)}")
280
  else:
281
- st.warning("⚠️ Please enter a prompt before sending.")
282
-
283
- # Footer
284
- st.markdown("---")
285
- st.markdown(
286
- '<div style="text-align: center; color: #888;">Powered by Groq AI | Built with ❤️ using Streamlit</div>',
287
- unsafe_allow_html=True
288
- )
 
3
  import re
4
  import uuid
5
 
6
+ # Backend URL - Hugging Face Space API endpoint
7
  BACKEND_URL = "https://shiva9876-code-gen-backend.hf.space"
8
 
9
  # Page Config with Logo
 
16
  # Custom CSS for Logo & UI
17
  st.markdown("""
18
  <style>
19
+ /* Remove default padding */
20
+ .main .block-container {
21
+ padding-bottom: 120px;
22
+ max-height: calc(100vh - 140px);
 
 
 
23
  }
24
 
25
  /* Logo Centered */
 
37
  font-size: 28px;
38
  font-weight: bold;
39
  color: #03dac6;
40
+ margin-bottom: 20px;
41
+ }
42
+
43
+ /* Chat messages container - scrollable area */
44
+ .chat-messages {
45
+ margin-bottom: 20px;
46
+ padding-bottom: 10px;
47
  }
48
 
49
  /* Chatbox UI */
 
60
  .ai-message { border-left: 5px solid #ff9800; padding-left: 10px; }
61
  pre { white-space: pre-wrap; word-wrap: break-word; }
62
 
63
+ /* Fixed Input Container */
64
+ .fixed-input-container {
65
+ position: fixed;
66
+ bottom: 0;
67
+ left: 0;
68
+ right: 0;
69
+ background-color: #0e1117;
70
+ padding: 15px 20px;
71
+ border-top: 2px solid #262626;
72
+ z-index: 999;
73
+ box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.3);
74
+ }
75
+
76
+ /* Adjust for sidebar */
77
+ section[data-testid="stSidebar"] ~ .main .fixed-input-container {
78
+ left: calc(21rem);
79
+ }
80
+
81
+ @media (max-width: 768px) {
82
+ section[data-testid="stSidebar"] ~ .main .fixed-input-container {
83
+ left: 0;
84
+ }
85
+ }
86
+
87
  /* Search Bar Styling */
88
  .search-container {
89
  display: flex;
90
  align-items: center;
91
  width: 100%;
92
+ max-width: 800px;
93
  margin: auto;
94
  }
95
 
96
+ /* Hide default streamlit form */
97
+ .stForm {
98
+ border: none !important;
99
+ padding: 0 !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  }
101
 
102
  /* Clear Chat Button */
 
112
  .stButton>button:hover {
113
  background-color: #cc0000;
114
  }
115
+
116
+ /* Input field styling */
117
+ .stTextInput>div>div>input {
118
+ background-color: #262626;
119
+ color: white;
120
+ border: 2px solid #03dac6;
121
+ border-radius: 25px;
122
+ padding: 12px 15px;
123
+ }
124
+
125
+ .stTextInput>div>div>input:focus {
126
+ border-color: #00ffcc;
127
+ box-shadow: 0 0 0 0.2rem rgba(0, 255, 204, 0.25);
128
+ }
129
+
130
+ /* Form submit button */
131
+ .stFormSubmitButton>button {
132
+ background-color: #00ffcc !important;
133
+ color: black !important;
134
+ border-radius: 25px !important;
135
+ padding: 10px 30px !important;
136
+ border: none !important;
137
+ font-weight: bold !important;
138
+ transition: 0.3s !important;
139
+ }
140
+
141
+ .stFormSubmitButton>button:hover {
142
+ background-color: #02c2ad !important;
143
+ }
144
  </style>
145
  """, unsafe_allow_html=True)
146
 
 
160
  if "session_id" not in st.session_state:
161
  st.session_state.session_id = str(uuid.uuid4())
162
 
163
+ # Chat messages container (scrollable)
164
+ chat_container = st.container()
165
+
166
+ with chat_container:
167
+ # Display chat history
168
+ for msg in st.session_state.messages:
169
+ if msg["role"] == "user":
170
+ st.markdown(f'<div class="chat-container user-message"><b>You:</b><br>{msg["content"]}</div>',
171
+ unsafe_allow_html=True)
172
+ elif msg["role"] == "ai":
173
+ content = msg["content"]
174
+
175
+ # Check if it's a conversational response or code response
176
+ if isinstance(content, tuple):
177
+ explanation, code = content
178
+ if explanation:
179
+ st.markdown(f'<div class="chat-container ai-message"><b>AI:</b><br>{explanation}</div>',
180
+ unsafe_allow_html=True)
181
+ if code:
182
+ st.code(code, language="python")
183
+ else:
184
+ # Simple text response (for conversational messages)
185
+ st.markdown(f'<div class="chat-container ai-message"><b>AI:</b><br>{content}</div>',
186
  unsafe_allow_html=True)
 
 
 
 
 
 
187
 
188
  # Sidebar with options
189
  with st.sidebar:
 
213
  st.divider()
214
  st.caption("💡 Tip: Ask coding questions or request code generation!")
215
 
216
+ # Fixed Input Form at the bottom
217
+ st.markdown('<div class="fixed-input-container">', unsafe_allow_html=True)
 
 
 
 
 
 
 
218
 
219
+ with st.form(key="input_form", clear_on_submit=True):
220
+ col1, col2 = st.columns([5, 1])
221
+
222
+ with col1:
223
+ user_input = st.text_input(
224
+ "Your Prompt:",
225
+ key="user_prompt",
226
+ placeholder="e.g., Write a function to sort a list or just say Hi!",
227
+ label_visibility="collapsed"
228
+ )
229
+
230
+ with col2:
231
+ submit_button = st.form_submit_button("SEND ↗️", use_container_width=True)
232
 
233
  st.markdown("</div>", unsafe_allow_html=True)
234
 
 
320
  except Exception as e:
321
  st.error(f"❌ Unexpected error: {str(e)}")
322
  else:
323
+ st.warning("⚠️ Please enter a prompt before sending.")