vlff李飞飞 commited on
Commit
6a9dc3a
1 Parent(s): b27dd8f
browser_qwen/background.js CHANGED
@@ -1,7 +1,8 @@
1
- var database;
2
 
3
  function send_data(msg){
4
  chrome.storage.local.get(['access_token'], function(result) {
 
5
  if (result.access_token) {
6
  console.log('access_token currently is ' + result.access_token);
7
  database_url = "https://taohongxiu-qwen-agent.hf.space/endpoint";
 
1
+ var database_url;
2
 
3
  function send_data(msg){
4
  chrome.storage.local.get(['access_token'], function(result) {
5
+ console.log(result)
6
  if (result.access_token) {
7
  console.log('access_token currently is ' + result.access_token);
8
  database_url = "https://taohongxiu-qwen-agent.hf.space/endpoint";
browser_qwen/background_副本.js CHANGED
@@ -56,4 +56,3 @@ chrome.runtime.onMessage.addListener(async (msg, sender) => {
56
  // }
57
  // }
58
  });
59
- Add to Qwen's Reading List
 
56
  // }
57
  // }
58
  });
 
browser_qwen/src/content.js CHANGED
@@ -29,7 +29,7 @@ button.style.position = 'fixed';
29
  button.style.top = '30px';
30
  button.style.right = '30px';
31
  button.style.zIndex = "9999";
32
- button.textContent = "Add to Qwen's Reading List";
33
  button.style.fontFamily = 'Arial, sans-serif';
34
  button.style.fontSize = '14px';
35
  button.style.width = '140px';
 
29
  button.style.top = '30px';
30
  button.style.right = '30px';
31
  button.style.zIndex = "9999";
32
+ button.textContent = "Add to ChatGpt's Reading List";
33
  button.style.fontFamily = 'Arial, sans-serif';
34
  button.style.fontSize = '14px';
35
  button.style.width = '140px';
browser_qwen/src/popup.html CHANGED
@@ -112,10 +112,6 @@
112
  <!-- <iframe src=$popup_url style="height: 550px"></iframe>-->
113
  <div id="iframe_area" style="height: 570px"></div>
114
 
115
- <h3 style="display: none;">Customize Address:</h3>
116
- <input type="text" id="addr" name="addr" class="input-text" style="display: none;">
117
- <button id="set_addr" class="upload_btn" style="display: none;">Change</button>
118
-
119
  <h3>Customize Token:</h3>
120
  <input type="text" id="access_token" name="access_token" class="input-text" placeholder="input and chick change button, then reopen this">
121
  <button id="set_access_token" class="upload_btn">Change</button>
 
112
  <!-- <iframe src=$popup_url style="height: 550px"></iframe>-->
113
  <div id="iframe_area" style="height: 570px"></div>
114
 
 
 
 
 
115
  <h3>Customize Token:</h3>
116
  <input type="text" id="access_token" name="access_token" class="input-text" placeholder="input and chick change button, then reopen this">
117
  <button id="set_access_token" class="upload_btn">Change</button>
browser_qwen/src/popup.js CHANGED
@@ -41,26 +41,6 @@ document.addEventListener('DOMContentLoaded', function() {
41
  });
42
  }, 500);
43
 
44
- // fetch('../config_host.json')
45
- // .then(response => response.json())
46
- // .then(data => {
47
- // console.log(data);
48
- // popup_url = "http://"+data.database_host+":"+data.app_in_browser_port+"/";
49
- // console.log(popup_url);
50
- // })
51
- // .catch(error => console.error('Error:', error));
52
- })
53
-
54
- document.getElementById('set_addr').addEventListener('click', function() {
55
- var addr = document.getElementById('addr').value;
56
- // save config
57
- chrome.storage.local.set({database_host: addr}, function() {
58
- console.log('database_host is set to ' + addr);
59
- // chrome.runtime.sendMessage({ data: addr , close: true , flag: 'set_addr'});
60
- document.getElementById('addr').value = '';
61
- });
62
- })
63
-
64
  document.getElementById('set_access_token').addEventListener('click', function() {
65
  var access_token = document.getElementById('access_token').value;
66
  // save config
 
41
  });
42
  }, 500);
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  document.getElementById('set_access_token').addEventListener('click', function() {
45
  var access_token = document.getElementById('access_token').value;
46
  // save config
qwen_server/database_server.py CHANGED
@@ -15,9 +15,7 @@ from qwen_agent.log import logger
15
  from qwen_agent.utils.utils import get_local_ip
16
  from qwen_server.schema import GlobalConfig
17
  from qwen_server.utils import extract_and_cache_document
18
- from starlette.middleware.base import BaseHTTPMiddleware
19
- from typing import Callable, Coroutine, Any
20
-
21
 
22
  # Read config
23
  with open(Path(__file__).resolve().parent / 'server_config.json', 'r') as f:
@@ -80,9 +78,10 @@ def change_checkbox_state(text, cache_file):
80
  @app.middleware("http")
81
  async def add_process_time_header(request: Request, call_next):
82
  print(f"Request URL path: {request.url}")
83
- access_token: str = request.headers.get("Authorization") or request.query_params.get("access_token")
84
  if not access_token or os.getenv("ACCESS_TOKEN") != access_token:
85
  return Response(status_code=401, content="the token is not valid")
 
86
  return await call_next(request)
87
 
88
 
@@ -132,7 +131,7 @@ from qwen_server.assistant_server import demo as assistant_app
132
 
133
  # app = gr.mount_gradio_app(app, workstation_app, path="/workstation")
134
  app = gr.mount_gradio_app(app, assistant_app, path="/")
135
-
136
  if __name__ == '__main__':
137
  uvicorn.run(app='database_server:app',
138
  host=server_config.server.server_host,
 
15
  from qwen_agent.utils.utils import get_local_ip
16
  from qwen_server.schema import GlobalConfig
17
  from qwen_server.utils import extract_and_cache_document
18
+ from starlette.middleware.sessions import SessionMiddleware
 
 
19
 
20
  # Read config
21
  with open(Path(__file__).resolve().parent / 'server_config.json', 'r') as f:
 
78
  @app.middleware("http")
79
  async def add_process_time_header(request: Request, call_next):
80
  print(f"Request URL path: {request.url}")
81
+ access_token: str = request.headers.get("Authorization") or request.query_params.get("access_token") or request.session.get("access_token")
82
  if not access_token or os.getenv("ACCESS_TOKEN") != access_token:
83
  return Response(status_code=401, content="the token is not valid")
84
+ request.session.setdefault("access_token", access_token)
85
  return await call_next(request)
86
 
87
 
 
131
 
132
  # app = gr.mount_gradio_app(app, workstation_app, path="/workstation")
133
  app = gr.mount_gradio_app(app, assistant_app, path="/")
134
+ app.add_middleware(SessionMiddleware, secret_key='dddsadf453454f64554dsgdfghfg', max_age=25200)
135
  if __name__ == '__main__':
136
  uvicorn.run(app='database_server:app',
137
  host=server_config.server.server_host,
requirements.txt CHANGED
@@ -34,4 +34,5 @@ supervisor
34
  torch==2.0.1
35
  transformers_stream_generator
36
  einops
37
- accelerate
 
 
34
  torch==2.0.1
35
  transformers_stream_generator
36
  einops
37
+ accelerate
38
+ itsdangerous