YchKhan commited on
Commit
4700455
1 Parent(s): ac2abcc

Update users_management.py

Browse files
Files changed (1) hide show
  1. users_management.py +8 -6
users_management.py CHANGED
@@ -4,11 +4,11 @@ from hashlib import sha256
4
  import gradio as gr
5
 
6
 
7
- def save_user_data_to_json(user, file_path='users.json'):
8
  username = user['name']
9
  # Load existing data
10
- if os.path.exists(file_path):
11
- with open(file_path, 'r') as file:
12
  try:
13
  existing_data = json.load(file)
14
  except json.JSONDecodeError:
@@ -20,9 +20,11 @@ def save_user_data_to_json(user, file_path='users.json'):
20
  existing_data[username] = user
21
 
22
  # Save updated data back to file
23
- with open(file_path, 'w') as file:
24
  json.dump(existing_data, file, indent=4)
25
 
 
 
26
  def load_from_json(file_path='users.json'):
27
  """
28
  Load user data from a JSON file and return it as a dictionary.
@@ -65,14 +67,14 @@ def update_json(user, prompt, keywords):
65
  if username != 'Guest':
66
  user = add_user_pref(user, prompt, input_type='prompts')
67
  user = add_user_pref(user, keywords, input_type='keywords')
68
- save_user_data_to_json(user)
69
 
70
  # with open('users.json', 'r') as file:
71
  # saved_data = json.load(file)
72
 
73
  users = load_from_json()
74
  user = users.get(username)
75
- return gr.update(choices=user['history']['prompts']), gr.update(choices=user['history']['keywords']), user
76
 
77
  def auth_user(username, password):
78
  users = load_from_json()
 
4
  import gradio as gr
5
 
6
 
7
+ def save_user_data_to_json(user, conf_file_path='users.json'):
8
  username = user['name']
9
  # Load existing data
10
+ if os.path.exists(conf_file_path):
11
+ with open(conf_file_path, 'r') as file:
12
  try:
13
  existing_data = json.load(file)
14
  except json.JSONDecodeError:
 
20
  existing_data[username] = user
21
 
22
  # Save updated data back to file
23
+ with open(conf_file_path, 'w') as file:
24
  json.dump(existing_data, file, indent=4)
25
 
26
+ return conf_file_path
27
+
28
  def load_from_json(file_path='users.json'):
29
  """
30
  Load user data from a JSON file and return it as a dictionary.
 
67
  if username != 'Guest':
68
  user = add_user_pref(user, prompt, input_type='prompts')
69
  user = add_user_pref(user, keywords, input_type='keywords')
70
+ conf_file_path = save_user_data_to_json(user)
71
 
72
  # with open('users.json', 'r') as file:
73
  # saved_data = json.load(file)
74
 
75
  users = load_from_json()
76
  user = users.get(username)
77
+ return gr.update(choices=user['history']['prompts']), gr.update(choices=user['history']['keywords']), user, conf_file_path
78
 
79
  def auth_user(username, password):
80
  users = load_from_json()