mahesh1209 commited on
Commit
28c1fd2
·
verified ·
1 Parent(s): 7f84a01

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -9
app.py CHANGED
@@ -1,6 +1,6 @@
1
  # app.py
2
  # Run: python app.py
3
- # Then open http://localhost:7860 in browser
4
 
5
  import re, random, torch, torch.nn as nn, torch.nn.functional as F
6
  from flask import Flask, request, jsonify
@@ -115,17 +115,32 @@ def index():
115
  return """
116
  <!doctype html><html><head><meta charset='utf-8'><title>Chatbot</title>
117
  <style>
118
- body{font-family:sans-serif;background:#111;color:#eee}
119
- #chat{height:300px;overflow-y:auto;border:1px solid #444;padding:10px;margin-bottom:10px}
120
- .bubble{margin:5px;padding:8px;border-radius:6px}
121
  .user{background:#2563eb;color:#fff}
122
  .bot{background:#374151;color:#eee}
 
 
 
 
 
 
123
  </style></head><body>
124
  <h2>SLM Chatbot</h2>
125
- <div><label>Username: <input id='username'></label><button onclick='setUser()'>Set</button></div>
 
 
 
126
  <div id='chat'></div>
127
- <input id='msg' placeholder='Type message'><button onclick='sendMsg()'>Submit</button>
128
- <button onclick='clearChat()'>Clear</button>
 
 
 
 
 
 
129
  <script>
130
  let banned=false,username='';
131
  function addBubble(sender,text){
@@ -133,6 +148,7 @@ function addBubble(sender,text){
133
  div.className='bubble '+sender;
134
  div.textContent=(sender==='user'?username||'You':'Bot')+': '+text;
135
  document.getElementById('chat').appendChild(div);
 
136
  }
137
  function setUser(){username=document.getElementById('username').value;addBubble('bot','Hello '+username);}
138
  async function sendMsg(){
@@ -146,6 +162,7 @@ async function sendMsg(){
146
  addBubble('bot',j.answer);
147
  }
148
  function clearChat(){document.getElementById('chat').innerHTML='';banned=false;}
 
149
  </script></body></html>
150
  """
151
 
@@ -153,8 +170,7 @@ function clearChat(){document.getElementById('chat').innerHTML='';banned=false;}
153
  def answer():
154
  q=request.json.get("q","")
155
  if BAN_REGEX.search(q): return jsonify({"answer":"banned"})
156
- ans=generate_answer(q)
157
- return jsonify({"answer":ans})
158
 
159
  if __name__=="__main__":
160
  app.run(host="0.0.0.0",port=7860)
 
1
  # app.py
2
  # Run: python app.py
3
+ # Open http://localhost:7860
4
 
5
  import re, random, torch, torch.nn as nn, torch.nn.functional as F
6
  from flask import Flask, request, jsonify
 
115
  return """
116
  <!doctype html><html><head><meta charset='utf-8'><title>Chatbot</title>
117
  <style>
118
+ body{font-family:sans-serif;background:#111;color:#eee;text-align:center}
119
+ #chat{height:300px;overflow-y:auto;border:1px solid #444;padding:10px;margin:20px auto;width:60%;background:#222}
120
+ .bubble{margin:5px;padding:8px;border-radius:6px;text-align:left}
121
  .user{background:#2563eb;color:#fff}
122
  .bot{background:#374151;color:#eee}
123
+ input{padding:10px;font-size:16px;margin:5px}
124
+ button{padding:15px 25px;font-size:18px;margin:10px;border:none;border-radius:8px;cursor:pointer}
125
+ .submit{background:#10b981;color:#06221b}
126
+ .clear{background:#f87171;color:#111}
127
+ .set{background:#3b82f6;color:#fff}
128
+ .home{background:#9ca3af;color:#111}
129
  </style></head><body>
130
  <h2>SLM Chatbot</h2>
131
+ <div>
132
+ <input id='username' placeholder='Enter username'>
133
+ <button class='set' onclick='setUser()'>Set Username</button>
134
+ </div>
135
  <div id='chat'></div>
136
+ <div>
137
+ <input id='msg' placeholder='Type message'>
138
+ </div>
139
+ <div>
140
+ <button class='submit' onclick='sendMsg()'>Submit</button>
141
+ <button class='clear' onclick='clearChat()'>Clear</button>
142
+ <button class='home' onclick='goHome()'>Home</button>
143
+ </div>
144
  <script>
145
  let banned=false,username='';
146
  function addBubble(sender,text){
 
148
  div.className='bubble '+sender;
149
  div.textContent=(sender==='user'?username||'You':'Bot')+': '+text;
150
  document.getElementById('chat').appendChild(div);
151
+ document.getElementById('chat').scrollTop=document.getElementById('chat').scrollHeight;
152
  }
153
  function setUser(){username=document.getElementById('username').value;addBubble('bot','Hello '+username);}
154
  async function sendMsg(){
 
162
  addBubble('bot',j.answer);
163
  }
164
  function clearChat(){document.getElementById('chat').innerHTML='';banned=false;}
165
+ function goHome(){window.location='/';}
166
  </script></body></html>
167
  """
168
 
 
170
  def answer():
171
  q=request.json.get("q","")
172
  if BAN_REGEX.search(q): return jsonify({"answer":"banned"})
173
+ return jsonify({"answer":generate_answer(q)})
 
174
 
175
  if __name__=="__main__":
176
  app.run(host="0.0.0.0",port=7860)