Dooratre commited on
Commit
b75f7d6
1 Parent(s): 63e7ccd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -37
app.py CHANGED
@@ -1,4 +1,4 @@
1
- from flask import Flask, render_template, request, send_from_directory, url_for, flash,redirect
2
  import requests
3
  import base64
4
  import json
@@ -315,6 +315,26 @@ def create_account():
315
 
316
  return render_template('sign-up.html')
317
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
318
 
319
 
320
 
@@ -326,43 +346,54 @@ def login():
326
  password = request.form.get("password")
327
  message = process_account_action("login", account_name, password)
328
  flash(message)
329
- if "Login successful." in message :
330
- ############### GET INFO ABOUT USER ###############################################
331
- url = f"https://api.github.com/repos/omarnuwrar/{repository_name}/contents/user.json"
332
- headers = {
333
- "Authorization": f"token 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",
334
- "Accept": "application/vnd.github.v3+json"
335
- }
336
- response = requests.get(url, headers=headers)
337
- if response.status_code == 200:
338
- file_info = response.json()
339
- file_content = base64.b64decode(file_info['content']).decode()
340
- users = eval(file_content) # Convert the string to a list of dictionaries
341
-
342
- target_username = account_name
343
-
344
- target_user = None
345
- for user in users:
346
- if user['username'] == target_username:
347
- target_user = user
348
- break
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
349
 
350
-
351
- first = target_user['first_name']
352
- last = target_user['last_name']
353
- token2 = target_user['token']
354
- user_name.append(first)
355
-
356
- ##############END INFO ABOUT USER #################################################
357
- conversation_history = []
358
- image_chat = []
359
- user_input =f"user name : {first} \n \n message : أهلا"
360
- greet = get_assistant_response(user_input)
361
- conversation_history.append({f"AI : {greet}"})
362
- return render_template('ai-chat-bot.html' ,account_name=account_name , greet=greet , first=first , last = last , token2 = token2)
363
-
364
  return render_template("sign-in.html", message=message)
365
 
 
 
366
  ############## END LOGIN #############################################
367
 
368
  @app.route('/get_response', methods=['POST'])
@@ -376,8 +407,6 @@ def get_response():
376
 
377
  response_text = get_assistant_response(user_input)
378
  check_image = get_image_Ai(user_input)
379
- print (response_text)
380
- print (check_image)
381
 
382
  if "~" in check_image:
383
  image_chat.append({f"AI : {check_image}"})
 
1
+ from flask import Flask, render_template, request, send_from_directory, url_for, flash,redirect,session
2
  import requests
3
  import base64
4
  import json
 
315
 
316
  return render_template('sign-up.html')
317
 
318
+ @app.route("/")
319
+ def home():
320
+ global conversation_history
321
+ conversation_history = []
322
+
323
+ # Retrieve user information from the session
324
+ user_info = session.get('user_info', {})
325
+ account_name = user_info.get('account_name')
326
+ first = user_info.get('first')
327
+ last = user_info.get('last')
328
+ token2 = user_info.get('token2')
329
+ greet = user_info.get('greet')
330
+
331
+ if not account_name:
332
+ conversation_history = []
333
+ return redirect(url_for('login'))
334
+
335
+ return render_template('ai-chat-bot.html', account_name=account_name, greet=greet, first=first, last=last, token2=token2)
336
+
337
+
338
 
339
 
340
 
 
346
  password = request.form.get("password")
347
  message = process_account_action("login", account_name, password)
348
  flash(message)
349
+ if "Login successful." in message:
350
+ ############### GET INFO ABOUT USER ###############################################
351
+ url = f"https://api.github.com/repos/omarnuwrar/{repository_name}/contents/user.json"
352
+ headers = {
353
+ "Authorization": f"token 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",
354
+ "Accept": "application/vnd.github.v3+json"
355
+ }
356
+ response = requests.get(url, headers=headers)
357
+ if response.status_code == 200:
358
+ file_info = response.json()
359
+ file_content = base64.b64decode(file_info['content']).decode()
360
+ users = eval(file_content) # Convert the string to a list of dictionaries
361
+
362
+ target_username = account_name
363
+
364
+ target_user = None
365
+ for user in users:
366
+ if user['username'] == target_username:
367
+ target_user = user
368
+ break
369
+
370
+ first = target_user['first_name']
371
+ last = target_user['last_name']
372
+ token2 = target_user['token']
373
+ user_name.append(first)
374
+
375
+ ############## END INFO ABOUT USER #################################################
376
+
377
+ # Initialize the user input and get the assistant's response
378
+ user_input = f"user name : {first} \n \n message : أهلا"
379
+ greet = get_assistant_response(user_input)
380
+
381
+ # Store user details in the session
382
+ session['user_info'] = {
383
+ 'account_name': account_name,
384
+ 'first': first,
385
+ 'last': last,
386
+ 'token2': token2,
387
+ 'greet': greet
388
+ }
389
+
390
+ # Redirect to the main route
391
+ return redirect(url_for('home'))
392
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
393
  return render_template("sign-in.html", message=message)
394
 
395
+
396
+
397
  ############## END LOGIN #############################################
398
 
399
  @app.route('/get_response', methods=['POST'])
 
407
 
408
  response_text = get_assistant_response(user_input)
409
  check_image = get_image_Ai(user_input)
 
 
410
 
411
  if "~" in check_image:
412
  image_chat.append({f"AI : {check_image}"})