krishbaresha commited on
Commit
5200a58
·
verified ·
1 Parent(s): 6ecdb55

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -19
app.py CHANGED
@@ -7,10 +7,7 @@ import requests
7
  # ---------------------------
8
  # PAGE CONFIG
9
  # ---------------------------
10
- st.set_page_config(
11
- page_title="Krish GPT Pro",
12
- layout="wide",
13
- )
14
 
15
  # ---------------------------
16
  # THEME & CSS
@@ -24,8 +21,8 @@ body {
24
  .chat-container {
25
  max-width: 800px;
26
  margin: auto;
27
- padding-bottom: 120px;
28
- height: 75vh;
29
  overflow-y: auto;
30
  }
31
  .chat-bubble {
@@ -57,6 +54,10 @@ body {
57
  max-width: 800px;
58
  margin-left: auto;
59
  margin-right: auto;
 
 
 
 
60
  }
61
  textarea {
62
  border-radius: 12px;
@@ -65,8 +66,10 @@ textarea {
65
  background-color: #1f2937;
66
  color: #d1d5db;
67
  border: none;
68
- resize: none;
69
  font-size: 16px;
 
 
 
70
  }
71
  button {
72
  background-color: #4f46e5;
@@ -79,8 +82,11 @@ button {
79
  button:hover {
80
  background-color: #4338ca;
81
  }
82
- .file-uploader {
83
  border-radius: 12px;
 
 
 
84
  }
85
  </style>
86
  """, unsafe_allow_html=True)
@@ -110,21 +116,27 @@ with chat_container.container():
110
  )
111
 
112
  # ---------------------------
113
- # INPUT BOX + FILE UPLOAD
114
  # ---------------------------
115
  with st.form("chat_form", clear_on_submit=True):
116
- prompt_col, file_col, submit_col = st.columns([7, 2, 1])
117
- with prompt_col:
118
- prompt = st.text_area("", height=50, placeholder="Type your question here...")
119
- with file_col:
 
 
 
 
 
 
120
  uploaded_file = st.file_uploader("", label_visibility="collapsed")
121
- with submit_col:
122
  submitted = st.form_submit_button("Send")
 
123
 
124
- if submitted and (prompt or uploaded_file):
125
  context = ""
126
  if uploaded_file:
127
- st.success(f"📎 Uploaded: {uploaded_file.name}")
128
  if uploaded_file.type == "application/pdf":
129
  reader = PdfReader(uploaded_file)
130
  for page in reader.pages:
@@ -142,8 +154,7 @@ with st.form("chat_form", clear_on_submit=True):
142
  except:
143
  context = ""
144
 
145
- if prompt:
146
- st.session_state.messages.append({"role": "user", "content": prompt})
147
 
148
  final_prompt = (prompt or "") + "\n" + context[:2000]
149
 
@@ -157,4 +168,21 @@ with st.form("chat_form", clear_on_submit=True):
157
  except:
158
  reply = "⚠️ Something went wrong. Try again."
159
 
160
- st.session_state.messages.append({"role": "assistant", "content": reply})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  # ---------------------------
8
  # PAGE CONFIG
9
  # ---------------------------
10
+ st.set_page_config(page_title="Krish GPT Pro", layout="wide")
 
 
 
11
 
12
  # ---------------------------
13
  # THEME & CSS
 
21
  .chat-container {
22
  max-width: 800px;
23
  margin: auto;
24
+ padding-bottom: 180px;
25
+ height: 70vh;
26
  overflow-y: auto;
27
  }
28
  .chat-bubble {
 
54
  max-width: 800px;
55
  margin-left: auto;
56
  margin-right: auto;
57
+ background-color: #111827;
58
+ padding: 10px;
59
+ border-radius: 12px;
60
+ box-shadow: 0 0 10px rgba(0,0,0,0.5);
61
  }
62
  textarea {
63
  border-radius: 12px;
 
66
  background-color: #1f2937;
67
  color: #d1d5db;
68
  border: none;
 
69
  font-size: 16px;
70
+ resize: none;
71
+ min-height: 40px;
72
+ max-height: 150px;
73
  }
74
  button {
75
  background-color: #4f46e5;
 
82
  button:hover {
83
  background-color: #4338ca;
84
  }
85
+ input[type="file"] {
86
  border-radius: 12px;
87
+ padding: 5px;
88
+ background-color: #1f2937;
89
+ color: #d1d5db;
90
  }
91
  </style>
92
  """, unsafe_allow_html=True)
 
116
  )
117
 
118
  # ---------------------------
119
+ # INPUT + FILE UPLOAD (Merged)
120
  # ---------------------------
121
  with st.form("chat_form", clear_on_submit=True):
122
+ st.markdown('<div class="input-container">', unsafe_allow_html=True)
123
+ col1, col2, col3 = st.columns([6, 3, 1])
124
+ with col1:
125
+ prompt = st.text_area(
126
+ "Type a message...",
127
+ key="input_text",
128
+ placeholder="Press Enter to send, Ctrl+Enter for new line",
129
+ height=50
130
+ )
131
+ with col2:
132
  uploaded_file = st.file_uploader("", label_visibility="collapsed")
133
+ with col3:
134
  submitted = st.form_submit_button("Send")
135
+ st.markdown('</div>', unsafe_allow_html=True)
136
 
137
+ if submitted and (prompt.strip() != "" or uploaded_file):
138
  context = ""
139
  if uploaded_file:
 
140
  if uploaded_file.type == "application/pdf":
141
  reader = PdfReader(uploaded_file)
142
  for page in reader.pages:
 
154
  except:
155
  context = ""
156
 
157
+ st.session_state.messages.append({"role": "user", "content": prompt})
 
158
 
159
  final_prompt = (prompt or "") + "\n" + context[:2000]
160
 
 
168
  except:
169
  reply = "⚠️ Something went wrong. Try again."
170
 
171
+ st.session_state.messages.append({"role": "assistant", "content": reply})
172
+
173
+ # ---------------------------
174
+ # JS Trick: Enter = Send, Ctrl+Enter = New line
175
+ # ---------------------------
176
+ st.markdown("""
177
+ <script>
178
+ const textarea = window.parent.document.querySelector('textarea');
179
+ if (textarea) {
180
+ textarea.addEventListener('keydown', function(e){
181
+ if(e.key === 'Enter' && !e.ctrlKey){
182
+ e.preventDefault();
183
+ document.querySelector('button[kind="primary"]').click();
184
+ }
185
+ });
186
+ }
187
+ </script>
188
+ """, unsafe_allow_html=True)