Dhruv-Ty commited on
Commit
c62b501
Β·
verified Β·
1 Parent(s): 36e64a1

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +333 -63
src/streamlit_app.py CHANGED
@@ -1,73 +1,343 @@
1
  import streamlit as st
2
  import streamlit.components.v1 as components
3
 
4
- st.set_page_config(page_title="Custom Chat Bar", layout="wide")
 
 
 
 
 
 
5
 
6
- # Display main content
7
- st.title("Main Chat Area")
8
- st.markdown("This is where your chat messages would appear.")
9
-
10
- # Custom HTML + CSS + JS for the sticky bottom chat bar
11
- chat_bar_code = """
12
  <style>
13
- .chat-bar-container {
14
- position: fixed;
15
- bottom: 0;
16
- left: 0;
17
- width: 100%;
18
- background-color: #1e1e1e;
19
- border-top: 1px solid #333;
20
- padding: 10px 20px;
21
- z-index: 1000;
22
- }
23
-
24
- .chat-bar {
25
- display: flex;
26
- align-items: center;
27
- justify-content: space-between;
28
- background-color: #2a2a2a;
29
- border-radius: 20px;
30
- padding: 8px 16px;
31
- box-shadow: 0 2px 10px rgba(0,0,0,0.2);
32
- }
33
-
34
- .chat-bar input {
35
- flex: 1;
36
- border: none;
37
- background: transparent;
38
- color: white;
39
- font-size: 16px;
40
- outline: none;
41
- }
42
-
43
- .chat-bar-icons {
44
- display: flex;
45
- gap: 12px;
46
- }
47
-
48
- .chat-bar-icons i {
49
- color: #ccc;
50
- cursor: pointer;
51
- transition: 0.2s ease;
52
- }
53
-
54
- .chat-bar-icons i:hover {
55
- color: white;
56
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  </style>
 
58
 
59
- <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
60
-
61
- <div class="chat-bar-container">
62
- <div class="chat-bar">
63
- <input type="text" placeholder="Ask anything..." />
64
- <div class="chat-bar-icons">
65
- <i class="fas fa-paperclip"></i>
66
- <i class="fas fa-microphone"></i>
67
- <i class="fas fa-paper-plane"></i>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  </div>
69
- </div>
70
  </div>
71
- """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
 
73
- components.html(chat_bar_code, height=100)
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  import streamlit.components.v1 as components
3
 
4
+ # Set page config
5
+ st.set_page_config(
6
+ page_title="Perplexity AI Clone",
7
+ page_icon="πŸ”",
8
+ layout="wide",
9
+ initial_sidebar_state="collapsed"
10
+ )
11
 
12
+ # Custom CSS for dark theme and styling
13
+ st.markdown("""
 
 
 
 
14
  <style>
15
+ /* Hide Streamlit default elements */
16
+ .stDeployButton {display: none;}
17
+ header[data-testid="stHeader"] {display: none;}
18
+ .stMainBlockContainer {padding-top: 0rem;}
19
+
20
+ /* Dark theme background */
21
+ .stApp {
22
+ background-color: #1a1a1a;
23
+ color: white;
24
+ }
25
+
26
+ /* Main container styling */
27
+ .main-container {
28
+ background-color: #1a1a1a;
29
+ min-height: 100vh;
30
+ display: flex;
31
+ flex-direction: column;
32
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
33
+ }
34
+
35
+ /* Header styling */
36
+ .header {
37
+ display: flex;
38
+ justify-content: space-between;
39
+ align-items: center;
40
+ padding: 1rem 2rem;
41
+ background-color: #1a1a1a;
42
+ border-bottom: 1px solid #333;
43
+ }
44
+
45
+ .logo {
46
+ display: flex;
47
+ align-items: center;
48
+ font-size: 1.2rem;
49
+ font-weight: 600;
50
+ color: white;
51
+ }
52
+
53
+ .logo-icon {
54
+ width: 24px;
55
+ height: 24px;
56
+ margin-right: 8px;
57
+ background: linear-gradient(45deg, #00d4ff, #00a8cc);
58
+ border-radius: 4px;
59
+ display: flex;
60
+ align-items: center;
61
+ justify-content: center;
62
+ }
63
+
64
+ .get-app-btn {
65
+ background-color: #00d4ff;
66
+ color: #1a1a1a;
67
+ padding: 8px 16px;
68
+ border-radius: 20px;
69
+ border: none;
70
+ font-weight: 600;
71
+ cursor: pointer;
72
+ font-size: 14px;
73
+ }
74
+
75
+ /* Center content */
76
+ .center-content {
77
+ flex: 1;
78
+ display: flex;
79
+ flex-direction: column;
80
+ justify-content: center;
81
+ align-items: center;
82
+ max-width: 800px;
83
+ margin: 0 auto;
84
+ padding: 2rem;
85
+ }
86
+
87
+ /* Main heading */
88
+ .main-heading {
89
+ font-size: 3.5rem;
90
+ font-weight: 400;
91
+ text-align: center;
92
+ margin-bottom: 3rem;
93
+ color: white;
94
+ line-height: 1.2;
95
+ }
96
+
97
+ /* Chat input container */
98
+ .chat-container {
99
+ width: 100%;
100
+ max-width: 700px;
101
+ position: relative;
102
+ margin-bottom: 2rem;
103
+ }
104
+
105
+ /* Custom input styling */
106
+ .chat-input-wrapper {
107
+ position: relative;
108
+ background-color: #2d2d2d;
109
+ border-radius: 12px;
110
+ border: 1px solid #404040;
111
+ overflow: hidden;
112
+ }
113
+
114
+ .chat-input {
115
+ width: 100%;
116
+ padding: 16px 120px 16px 20px;
117
+ background: transparent;
118
+ border: none;
119
+ outline: none;
120
+ color: white;
121
+ font-size: 16px;
122
+ font-family: inherit;
123
+ resize: none;
124
+ min-height: 24px;
125
+ max-height: 200px;
126
+ }
127
+
128
+ .chat-input::placeholder {
129
+ color: #888;
130
+ }
131
+
132
+ /* Button container */
133
+ .button-container {
134
+ position: absolute;
135
+ right: 8px;
136
+ top: 50%;
137
+ transform: translateY(-50%);
138
+ display: flex;
139
+ align-items: center;
140
+ gap: 4px;
141
+ }
142
+
143
+ /* Individual buttons */
144
+ .action-btn {
145
+ width: 32px;
146
+ height: 32px;
147
+ background: transparent;
148
+ border: none;
149
+ border-radius: 6px;
150
+ cursor: pointer;
151
+ display: flex;
152
+ align-items: center;
153
+ justify-content: center;
154
+ color: #888;
155
+ transition: all 0.2s ease;
156
+ }
157
+
158
+ .action-btn:hover {
159
+ background-color: #404040;
160
+ color: white;
161
+ }
162
+
163
+ .search-btn {
164
+ background-color: #00d4ff;
165
+ color: #1a1a1a;
166
+ border-radius: 6px;
167
+ margin-right: 4px;
168
+ }
169
+
170
+ .search-btn:hover {
171
+ background-color: #00b8e6;
172
+ }
173
+
174
+ /* Bottom navigation placeholder */
175
+ .bottom-nav {
176
+ position: fixed;
177
+ bottom: 0;
178
+ left: 50%;
179
+ transform: translateX(-50%);
180
+ background-color: #1a1a1a;
181
+ padding: 1rem;
182
+ display: flex;
183
+ gap: 2rem;
184
+ border-top: 1px solid #333;
185
+ width: 200px;
186
+ justify-content: center;
187
+ }
188
+
189
+ .nav-item {
190
+ width: 24px;
191
+ height: 24px;
192
+ background-color: #333;
193
+ border-radius: 4px;
194
+ cursor: pointer;
195
+ }
196
+
197
+ /* Responsive design */
198
+ @media (max-width: 768px) {
199
+ .main-heading {
200
+ font-size: 2.5rem;
201
+ }
202
+
203
+ .header {
204
+ padding: 1rem;
205
+ }
206
+
207
+ .center-content {
208
+ padding: 1rem;
209
+ }
210
+ }
211
  </style>
212
+ """, unsafe_allow_html=True)
213
 
214
+ # Main HTML structure
215
+ st.markdown("""
216
+ <div class="main-container">
217
+ <div class="header">
218
+ <div class="logo">
219
+ <div class="logo-icon">⚑</div>
220
+ perplexity
221
+ </div>
222
+ <button class="get-app-btn">πŸ“± Get App</button>
223
+ </div>
224
+
225
+ <div class="center-content">
226
+ <h1 class="main-heading">What do you want to know?</h1>
227
+
228
+ <div class="chat-container">
229
+ <div class="chat-input-wrapper">
230
+ <textarea
231
+ class="chat-input"
232
+ placeholder="Ask anything..."
233
+ rows="1"
234
+ id="chatInput"
235
+ ></textarea>
236
+ <div class="button-container">
237
+ <button class="action-btn search-btn" title="Search">
238
+ πŸ”
239
+ </button>
240
+ <button class="action-btn" title="Image">
241
+ πŸ–ΌοΈ
242
+ </button>
243
+ <button class="action-btn" title="Globe">
244
+ 🌐
245
+ </button>
246
+ <button class="action-btn" title="Attachment">
247
+ πŸ“Ž
248
+ </button>
249
+ <button class="action-btn" title="Voice">
250
+ 🎀
251
+ </button>
252
+ <button class="action-btn" title="Send">
253
+ ➀
254
+ </button>
255
+ </div>
256
+ </div>
257
+ </div>
258
+ </div>
259
+
260
+ <div class="bottom-nav">
261
+ <div class="nav-item"></div>
262
+ <div class="nav-item"></div>
263
+ <div class="nav-item"></div>
264
  </div>
 
265
  </div>
266
+ """, unsafe_allow_html=True)
267
+
268
+ # JavaScript for interactive functionality
269
+ components.html("""
270
+ <script>
271
+ document.addEventListener('DOMContentLoaded', function() {
272
+ const chatInput = document.getElementById('chatInput');
273
+ const buttons = document.querySelectorAll('.action-btn');
274
+
275
+ // Auto-resize textarea
276
+ chatInput.addEventListener('input', function() {
277
+ this.style.height = 'auto';
278
+ this.style.height = Math.min(this.scrollHeight, 200) + 'px';
279
+ });
280
+
281
+ // Button click handlers
282
+ buttons.forEach(button => {
283
+ button.addEventListener('click', function() {
284
+ const title = this.getAttribute('title');
285
+ console.log(`${title} button clicked`);
286
+
287
+ // Add visual feedback
288
+ this.style.transform = 'scale(0.95)';
289
+ setTimeout(() => {
290
+ this.style.transform = 'scale(1)';
291
+ }, 100);
292
+
293
+ // Handle specific button actions
294
+ if (title === 'Send' && chatInput.value.trim()) {
295
+ console.log('Sending message:', chatInput.value);
296
+ // Here you would typically send the message
297
+ chatInput.value = '';
298
+ chatInput.style.height = 'auto';
299
+ }
300
+ });
301
+ });
302
+
303
+ // Enter key to send
304
+ chatInput.addEventListener('keydown', function(e) {
305
+ if (e.key === 'Enter' && !e.shiftKey) {
306
+ e.preventDefault();
307
+ if (this.value.trim()) {
308
+ console.log('Sending message:', this.value);
309
+ // Here you would typically send the message
310
+ this.value = '';
311
+ this.style.height = 'auto';
312
+ }
313
+ }
314
+ });
315
+
316
+ // Focus on input when page loads
317
+ chatInput.focus();
318
+ });
319
+ </script>
320
+ """, height=0)
321
+
322
+ # Session state for chat history
323
+ if 'messages' not in st.session_state:
324
+ st.session_state.messages = []
325
+
326
+ # Handle form submission (alternative method using Streamlit)
327
+ with st.form(key='chat_form', clear_on_submit=True):
328
+ user_input = st.text_input("", placeholder="Ask anything...", label_visibility="hidden", key="user_input")
329
+ submit_button = st.form_submit_button("Send", use_container_width=False)
330
+
331
+ if submit_button and user_input:
332
+ st.session_state.messages.append({"role": "user", "content": user_input})
333
+ # Here you would add your AI response logic
334
+ st.session_state.messages.append({"role": "assistant", "content": f"You asked: {user_input}"})
335
 
336
+ # Display chat history (if any messages exist)
337
+ if st.session_state.messages:
338
+ st.markdown("### Chat History")
339
+ for message in st.session_state.messages:
340
+ if message["role"] == "user":
341
+ st.markdown(f"**You:** {message['content']}")
342
+ else:
343
+ st.markdown(f"**Assistant:** {message['content']}")