Vitrous commited on
Commit
a31cce5
·
verified ·
1 Parent(s): 7c1cb80

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -11
app.py CHANGED
@@ -16,14 +16,7 @@ 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 = '/articko/ArtickBot/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
- print("File found: conversations.jsonl")
25
- else:
26
- print("File not found: conversations.jsonl")
27
  # Initialize FastAPI application
28
  app = FastAPI(root_path="/api/v1")
29
  conversations = {}
@@ -123,9 +116,12 @@ def save_conversation(user_id, conversation):
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
 
130
  def chat_response(msg_prompt: str) -> dict:
131
  """
 
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
+ dataset = Dataset.from_json("articko/conversations/conversations.jsonl")
 
 
 
 
 
 
 
20
  # Initialize FastAPI application
21
  app = FastAPI(root_path="/api/v1")
22
  conversations = {}
 
116
  conversation (dict): The conversation data.
117
  hf_space_path (str): The path to the Hugging Face Space.
118
  """
119
+
120
+ # Add the new conversation to the dataset
121
+ dataset = dataset.add({"user_id": user_id, "conversation": conversation})
122
+
123
+ # Save the updated dataset back to the JSON file
124
+ dataset.save_to_disk("articko/conversations/conversations.jsonl")
125
 
126
  def chat_response(msg_prompt: str) -> dict:
127
  """