ruiheesi commited on
Commit
3e52d66
·
1 Parent(s): eeb192d

Add applicaiton file

Browse files
Files changed (2) hide show
  1. app.py +4 -47
  2. templates/index.html +0 -14
app.py CHANGED
@@ -15,7 +15,8 @@ EMBEDDING_MODEL = "text-embedding-ada-002"
15
  config_dir = dir_path + "/src/utils"
16
  config = configparser.ConfigParser()
17
  config.read(os.path.join(config_dir, 'gpt_local_config.cfg'))
18
- openai.api_key = config.get('token', 'GPT_TOKEN')
 
19
 
20
  import embedding_qa as emq
21
 
@@ -60,25 +61,6 @@ def nl2br_filter(s):
60
 
61
  @app.route('/', methods=['GET', 'POST'])
62
  def index():
63
- global authenticated, last_activity_time, login_time
64
-
65
- if not authenticated:
66
- return redirect(url_for('login'))
67
-
68
- # Check for timeout
69
- current_time = time.time()
70
- if current_time - last_activity_time > timeout_duration:
71
- authenticated = False
72
- return redirect(url_for('login'))
73
-
74
- # Check for session timeout
75
- if current_time - login_time > session_duration:
76
- authenticated = False
77
- return redirect(url_for('login'))
78
-
79
- # Update last activity time
80
- last_activity_time = current_time
81
-
82
  user_input = ""
83
  processed_input = None
84
  if request.method == 'POST':
@@ -94,34 +76,9 @@ def index():
94
  'index.html',
95
  processed_input=processed_input,
96
  source_sections=chosen_sec_idxes,
97
- user_input=user_input,
98
- authenticated=authenticated)
99
 
100
- return render_template('index.html', authenticated=authenticated)
101
-
102
-
103
- @app.route('/login', methods=['GET', 'POST'])
104
- def login():
105
- global authenticated, last_activity_time, login_time
106
-
107
- if request.method == 'POST':
108
- password = request.form['passcode']
109
- if password == PASSCODE_auth:
110
- authenticated = True
111
- last_activity_time = time.time()
112
- login_time = time.time()
113
- return redirect(url_for('index'))
114
- else:
115
- return render_template('login.html', message='Incorrect password')
116
-
117
- return render_template('login.html')
118
-
119
-
120
- @app.route('/logout')
121
- def logout():
122
- global authenticated
123
- authenticated = False
124
- return redirect(url_for('login'))
125
 
126
 
127
  if __name__ == '__main__':
 
15
  config_dir = dir_path + "/src/utils"
16
  config = configparser.ConfigParser()
17
  config.read(os.path.join(config_dir, 'gpt_local_config.cfg'))
18
+ # openai.api_key = config.get('token', 'GPT_TOKEN')
19
+ openai.api_key = os.environ.get("GPT_TOKEN")
20
 
21
  import embedding_qa as emq
22
 
 
61
 
62
  @app.route('/', methods=['GET', 'POST'])
63
  def index():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  user_input = ""
65
  processed_input = None
66
  if request.method == 'POST':
 
76
  'index.html',
77
  processed_input=processed_input,
78
  source_sections=chosen_sec_idxes,
79
+ user_input=user_input)
 
80
 
81
+ return render_template('index.html')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
 
83
 
84
  if __name__ == '__main__':
templates/index.html CHANGED
@@ -73,15 +73,6 @@
73
  text-align: center;
74
  margin-bottom: 20px;
75
  }
76
- .logout-button {
77
- position: absolute;
78
- top: 10px;
79
- right: 10px;
80
- color: #fff;
81
- background-color: #333;
82
- padding: 10px;
83
- text-decoration: none;
84
- }
85
 
86
  .another-box.folded {
87
  display: flex;
@@ -111,11 +102,6 @@
111
 
112
  <img src="{{ url_for('static', filename='caNanoLablogo.jpg') }}" alt="caNanoWiki AI Logo" class="logo">
113
 
114
-
115
- {% if authenticated %}
116
- <a class="logout-button" href="{{ url_for('logout') }}">Logout</a>
117
- {% endif %}
118
-
119
  <form method="POST" action="/">
120
  <label for="user_input">How can I help?</label>
121
  <input type="text" id="user_input" name="user_input" value="{{ user_input }}" autofocus>
 
73
  text-align: center;
74
  margin-bottom: 20px;
75
  }
 
 
 
 
 
 
 
 
 
76
 
77
  .another-box.folded {
78
  display: flex;
 
102
 
103
  <img src="{{ url_for('static', filename='caNanoLablogo.jpg') }}" alt="caNanoWiki AI Logo" class="logo">
104
 
 
 
 
 
 
105
  <form method="POST" action="/">
106
  <label for="user_input">How can I help?</label>
107
  <input type="text" id="user_input" name="user_input" value="{{ user_input }}" autofocus>