cmagganas commited on
Commit
a13da0d
1 Parent(s): 26475d9

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app/openai_chat_completion.py +16 -6
app/openai_chat_completion.py CHANGED
@@ -84,15 +84,25 @@ class OpenAIChatCompletions:
84
  # a method that samples n rows from a jsonl file, returning a pandas dataframe
85
  @staticmethod
86
  def _sample_jsonl(
87
- path_or_buf='../data/cookies_train.jsonl',
88
  # path_or_buf='~/data/cookies_train.jsonl',
89
  n_samples=5
90
  ):
91
 
92
  # jsonObj = pd.read_json(path_or_buf=path_or_buf, lines=True)
93
- file_path = os.path.join(os.getcwd(), "../data/cookies_train.jsonl")
94
- st.write(file_path)
95
- with open(file_path, "r") as file:
96
- jsonl_str = file.read()
97
- jsonObj = pd.read_json(BytesIO(jsonl_str.encode()), lines=True, engine="pyarrow")
 
 
 
 
 
 
 
 
 
 
98
  return jsonObj.sample(n_samples, random_state=42)
 
84
  # a method that samples n rows from a jsonl file, returning a pandas dataframe
85
  @staticmethod
86
  def _sample_jsonl(
87
+ path_or_buf='data/cookies_train.jsonl',
88
  # path_or_buf='~/data/cookies_train.jsonl',
89
  n_samples=5
90
  ):
91
 
92
  # jsonObj = pd.read_json(path_or_buf=path_or_buf, lines=True)
93
+ if "streamlit" in os.getcwd():
94
+ file_path = os.path.join(os.getcwd(), "..", path_or_buf)
95
+ else:
96
+ file_path = "/home/user/app/" + path_or_buf
97
+
98
+ try:
99
+ with open(file_path, "r") as file:
100
+ jsonl_str = file.read()
101
+
102
+ jsonObj = pd.read_json(BytesIO(jsonl_str.encode()), lines=True, engine="pyarrow")
103
+ except FileNotFoundError:
104
+ # Handle the case where the file is not found
105
+ # Display an error message or take appropriate action
106
+ st.write(f"File not found: {file_path}")
107
+
108
  return jsonObj.sample(n_samples, random_state=42)