Spaces:
Sleeping

Shirpi commited on
Commit
2469259
Β·
verified Β·
1 Parent(s): 51c2260

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -19
app.py CHANGED
@@ -10,7 +10,6 @@ from flask import Flask, request, jsonify, render_template_string, Response
10
  import google.generativeai as genai
11
 
12
  # --- FIX: IGNORE DEPRECATION WARNINGS ---
13
- # Idhu Google 'FutureWarning' error-a ignore panna sollum
14
  warnings.filterwarnings("ignore")
15
 
16
  # ==========================================
@@ -53,13 +52,10 @@ def get_working_model(key):
53
  genai.configure(api_key=key)
54
  models = list(genai.list_models())
55
  chat_models = [m for m in models if 'generateContent' in m.supported_generation_methods]
56
-
57
- # Priority Order
58
  for m in chat_models:
59
  if "flash" in m.name.lower() and "1.5" in m.name: return m.name
60
  for m in chat_models:
61
  if "pro" in m.name.lower() and "1.5" in m.name: return m.name
62
-
63
  if chat_models: return chat_models[0].name
64
  except: return None
65
  return None
@@ -130,7 +126,6 @@ HTML_TEMPLATE = """
130
 
131
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/atom-one-dark.min.css">
132
  <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
133
-
134
  <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
135
  <script>window.MathJax = { tex: { inlineMath: [['$', '$']] }, svg: { fontCache: 'global' } };</script>
136
  <script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
@@ -146,11 +141,31 @@ HTML_TEMPLATE = """
146
  --accent: #fff; --border: #27272a; --dim: #71717a;
147
  }
148
  * { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
149
- body, html { margin: 0; padding: 0; height: 100%; width: 100%; background: var(--bg); color: var(--text); font-family: 'Outfit', sans-serif; overflow: hidden; user-select: none; font-size: 17px; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
 
151
  #app-container { display: flex; flex-direction: column; height: 100dvh; position: relative; }
152
 
153
- /* HEADER */
154
  header {
155
  height: 70px; padding: 0 20px;
156
  background: rgba(9,9,11, 0.98);
@@ -166,7 +181,6 @@ HTML_TEMPLATE = """
166
  .menu-btn:active { transform: scale(0.95); background: #222; }
167
  .app-title { font-size: 24px; font-weight: 800; letter-spacing: -0.5px; color: #fff; }
168
 
169
- /* SIDEBAR */
170
  #sidebar {
171
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
172
  background: var(--bg); z-index: 100;
@@ -204,7 +218,6 @@ HTML_TEMPLATE = """
204
  .brand-name { font-family: 'Outfit', sans-serif; font-weight: 600; font-size: 12px; color: var(--dim); letter-spacing: 2px; margin-bottom: 10px; opacity: 0.6; }
205
  .logout-btn { color: #ef4444; cursor: pointer; font-size: 15px; font-weight: 600; padding: 10px; }
206
 
207
- /* CHAT AREA */
208
  #chat-box {
209
  flex: 1; overflow-y: auto; padding: 20px 5%;
210
  display: flex; flex-direction: column; gap: 30px;
@@ -215,10 +228,10 @@ HTML_TEMPLATE = """
215
  @keyframes fadeInstant { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
216
 
217
  .user-msg { text-align: right; }
218
- .user-content { display: inline-block; background: var(--user-msg); padding: 12px 20px; border-radius: 20px 20px 4px 20px; text-align: left; max-width: 85%; user-select: text; color: #fff; }
219
 
220
  .ai-msg { text-align: left; }
221
- .ai-content { user-select: text; color: #d4d4d8; }
222
  .ai-content strong { color: #fff; font-weight: 700; }
223
  .ai-content h1, .ai-content h2 { margin-top: 20px; color: #fff; font-weight: 700; }
224
 
@@ -234,7 +247,6 @@ HTML_TEMPLATE = """
234
  .action-icon { cursor: pointer; color: var(--dim); font-size: 18px; transition: 0.2s; }
235
  .action-icon:hover { color: #fff; transform: scale(1.1); }
236
 
237
- /* INPUT AREA */
238
  .input-wrapper { background: var(--bg); padding: 15px; border-top: 1px solid var(--border); flex-shrink: 0; z-index: 60; padding-bottom: max(15px, env(safe-area-inset-bottom)); }
239
  .input-container {
240
  max-width: 900px; margin: 0 auto; background: var(--card);
@@ -395,7 +407,7 @@ HTML_TEMPLATE = """
395
  const imgData = currentAttachment.type === 'image' ? currentAttachment.data : null;
396
  const fileText = currentAttachment.type === 'file' ? currentAttachment.data : null;
397
 
398
- input.value = ''; input.style.height= 'auto';
399
  clearAttachment();
400
  scrollToBottom();
401
 
@@ -597,8 +609,7 @@ def chat():
597
  save_db(user_db)
598
  return jsonify({"response": reply, "new_title": new_title})
599
 
600
- # --- PWA CONFIG FOR FULLSCREEN ---
601
- # --- PWA CONFIG FOR FULLSCREEN ---
602
  @app.route('/manifest.json')
603
  def manifest():
604
  data = {
@@ -611,19 +622,20 @@ def manifest():
611
  "theme_color": "#09090b",
612
  "icons": [
613
  {
614
- # πŸ‘‡ INGA DHAN MAATHANUM πŸ‘‡
615
- "src": "https://huggingface.co/spaces/Shirpi/Student-s_AI/resolve/main/1000177401.png",
616
  "sizes": "192x192",
617
  "type": "image/png"
618
  },
619
  {
620
- # πŸ‘‡ PERIYA ICON KUM SAME LINK PODUNGA πŸ‘‡
621
- "src": "https://huggingface.co/spaces/Shirpi/Student-s_AI/resolve/main/1000177401.png",
622
  "sizes": "512x512",
623
  "type": "image/png"
624
  }
625
  ]
626
  }
627
  return Response(json.dumps(data), mimetype='application/json')
 
628
  if __name__ == '__main__':
629
  app.run(host='0.0.0.0', port=7860)
 
10
  import google.generativeai as genai
11
 
12
  # --- FIX: IGNORE DEPRECATION WARNINGS ---
 
13
  warnings.filterwarnings("ignore")
14
 
15
  # ==========================================
 
52
  genai.configure(api_key=key)
53
  models = list(genai.list_models())
54
  chat_models = [m for m in models if 'generateContent' in m.supported_generation_methods]
 
 
55
  for m in chat_models:
56
  if "flash" in m.name.lower() and "1.5" in m.name: return m.name
57
  for m in chat_models:
58
  if "pro" in m.name.lower() and "1.5" in m.name: return m.name
 
59
  if chat_models: return chat_models[0].name
60
  except: return None
61
  return None
 
126
 
127
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/atom-one-dark.min.css">
128
  <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
 
129
  <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
130
  <script>window.MathJax = { tex: { inlineMath: [['$', '$']] }, svg: { fontCache: 'global' } };</script>
131
  <script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
 
141
  --accent: #fff; --border: #27272a; --dim: #71717a;
142
  }
143
  * { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
144
+
145
+ /* --- DISABLE TEXT SELECTION GLOBALLY --- */
146
+ body, html, .msg, .user-content, .ai-content, code, pre {
147
+ margin: 0; padding: 0; height: 100%; width: 100%;
148
+ background: var(--bg); color: var(--text); font-family: 'Outfit', sans-serif;
149
+ overflow: hidden;
150
+ font-size: 17px;
151
+
152
+ /* No Selection Allowed */
153
+ -webkit-user-select: none;
154
+ -moz-user-select: none;
155
+ -ms-user-select: none;
156
+ user-select: none;
157
+ }
158
+
159
+ /* --- ALLOW SELECTION ONLY IN INPUTS --- */
160
+ textarea, input {
161
+ -webkit-user-select: text !important;
162
+ -moz-user-select: text !important;
163
+ -ms-user-select: text !important;
164
+ user-select: text !important;
165
+ }
166
 
167
  #app-container { display: flex; flex-direction: column; height: 100dvh; position: relative; }
168
 
 
169
  header {
170
  height: 70px; padding: 0 20px;
171
  background: rgba(9,9,11, 0.98);
 
181
  .menu-btn:active { transform: scale(0.95); background: #222; }
182
  .app-title { font-size: 24px; font-weight: 800; letter-spacing: -0.5px; color: #fff; }
183
 
 
184
  #sidebar {
185
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
186
  background: var(--bg); z-index: 100;
 
218
  .brand-name { font-family: 'Outfit', sans-serif; font-weight: 600; font-size: 12px; color: var(--dim); letter-spacing: 2px; margin-bottom: 10px; opacity: 0.6; }
219
  .logout-btn { color: #ef4444; cursor: pointer; font-size: 15px; font-weight: 600; padding: 10px; }
220
 
 
221
  #chat-box {
222
  flex: 1; overflow-y: auto; padding: 20px 5%;
223
  display: flex; flex-direction: column; gap: 30px;
 
228
  @keyframes fadeInstant { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
229
 
230
  .user-msg { text-align: right; }
231
+ .user-content { display: inline-block; background: var(--user-msg); padding: 12px 20px; border-radius: 20px 20px 4px 20px; text-align: left; max-width: 85%; color: #fff; }
232
 
233
  .ai-msg { text-align: left; }
234
+ .ai-content { color: #d4d4d8; }
235
  .ai-content strong { color: #fff; font-weight: 700; }
236
  .ai-content h1, .ai-content h2 { margin-top: 20px; color: #fff; font-weight: 700; }
237
 
 
247
  .action-icon { cursor: pointer; color: var(--dim); font-size: 18px; transition: 0.2s; }
248
  .action-icon:hover { color: #fff; transform: scale(1.1); }
249
 
 
250
  .input-wrapper { background: var(--bg); padding: 15px; border-top: 1px solid var(--border); flex-shrink: 0; z-index: 60; padding-bottom: max(15px, env(safe-area-inset-bottom)); }
251
  .input-container {
252
  max-width: 900px; margin: 0 auto; background: var(--card);
 
407
  const imgData = currentAttachment.type === 'image' ? currentAttachment.data : null;
408
  const fileText = currentAttachment.type === 'file' ? currentAttachment.data : null;
409
 
410
+ input.value = ''; input.style.height = 'auto';
411
  clearAttachment();
412
  scrollToBottom();
413
 
 
609
  save_db(user_db)
610
  return jsonify({"response": reply, "new_title": new_title})
611
 
612
+ # --- MANIFEST FOR APP LOGO ---
 
613
  @app.route('/manifest.json')
614
  def manifest():
615
  data = {
 
622
  "theme_color": "#09090b",
623
  "icons": [
624
  {
625
+ # πŸ‘‡ Paste your 192x192 Image Link Here πŸ‘‡
626
+ "src": "https://cdn-icons-png.flaticon.com/512/4712/4712035.png",
627
  "sizes": "192x192",
628
  "type": "image/png"
629
  },
630
  {
631
+ # πŸ‘‡ Paste your 512x512 Image Link Here πŸ‘‡
632
+ "src": "https://cdn-icons-png.flaticon.com/512/4712/4712035.png",
633
  "sizes": "512x512",
634
  "type": "image/png"
635
  }
636
  ]
637
  }
638
  return Response(json.dumps(data), mimetype='application/json')
639
+
640
  if __name__ == '__main__':
641
  app.run(host='0.0.0.0', port=7860)