Vitrous commited on
Commit
0c9ff15
·
verified ·
1 Parent(s): 8ca7387

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -15,7 +15,15 @@ import json
15
  os.environ['PYTORCH_CUDA_ALLOC_CONF'] = 'expandable_segments:True'
16
  torch.cuda.empty_cache()
17
  torch.cuda.set_per_process_memory_fraction(0.8) # Adjust the fraction as needed
18
-
 
 
 
 
 
 
 
 
19
  # Initialize FastAPI application
20
  app = FastAPI(root_path="/api/v1")
21
  conversations = {}
@@ -107,7 +115,6 @@ def generate_message_id():
107
 
108
 
109
  def save_conversation(user_id, conversation):
110
- hf_space_path="/code"
111
  """
112
  Save conversation history to disk.
113
 
@@ -116,7 +123,7 @@ def save_conversation(user_id, conversation):
116
  conversation (dict): The conversation data.
117
  hf_space_path (str): The path to the Hugging Face Space.
118
  """
119
- with open(f'{hf_space_path}/conversations.jsonl', 'a') as file:
120
  json.dump({user_id: conversation}, file)
121
  file.write('\n')
122
 
 
15
  os.environ['PYTORCH_CUDA_ALLOC_CONF'] = 'expandable_segments:True'
16
  torch.cuda.empty_cache()
17
  torch.cuda.set_per_process_memory_fraction(0.8) # Adjust the fraction as needed
18
+ # Assuming you've created the file conversations.jsonl
19
+ conversations_jsonl = '/code/conversations.jsonl'
20
+
21
+ # Check if the file exists
22
+ if os.path.exists(conversations_jsonl):
23
+ # Set permissions to read and write for all users
24
+ os.chmod(conversations_jsonl, 0o666)
25
+ else:
26
+ print("File not found: conversations.jsonl")
27
  # Initialize FastAPI application
28
  app = FastAPI(root_path="/api/v1")
29
  conversations = {}
 
115
 
116
 
117
  def save_conversation(user_id, conversation):
 
118
  """
119
  Save conversation history to disk.
120
 
 
123
  conversation (dict): The conversation data.
124
  hf_space_path (str): The path to the Hugging Face Space.
125
  """
126
+ with open(conversations_jsonl, 'a') as file:
127
  json.dump({user_id: conversation}, file)
128
  file.write('\n')
129