farah1 commited on
Commit
b369092
·
verified ·
1 Parent(s): 92c2e11

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -9
app.py CHANGED
@@ -33,23 +33,27 @@ try:
33
  train_data = dataset["train"].to_pandas()
34
  validation_data = dataset["validation"].to_pandas()
35
  print("Dataset loaded successfully.")
 
36
  except Exception as e:
37
  print(f"Failed to load dataset: {e}")
38
  train_data = pd.DataFrame() # Fallback to empty DataFrame
39
  validation_data = pd.DataFrame()
40
 
 
 
 
 
 
 
 
41
  # Ensure the necessary columns exist in the training dataset
42
- required_columns = ["content", "Ground_Truth_Stress", "Ground_Truth_Anxiety", "Ground_Truth_Depression", "Ground_Truth_Other_binary"]
43
- if not train_data.empty:
44
- for column in required_columns:
45
- if column not in train_data.columns:
46
- raise ValueError(f"Missing required column '{column}' in the training dataset.")
47
- else:
48
- print("Training dataset is empty. Exiting.")
49
- exit(1)
50
 
51
  # Initialize BM25
52
- tokenized_train = [doc.split() for doc in train_data["content"]]
53
  bm25 = BM25Okapi(tokenized_train)
54
 
55
  # Set OpenAI API key
@@ -114,3 +118,4 @@ interface = gr.Interface(
114
 
115
  if __name__ == "__main__":
116
  interface.launch()
 
 
33
  train_data = dataset["train"].to_pandas()
34
  validation_data = dataset["validation"].to_pandas()
35
  print("Dataset loaded successfully.")
36
+ print("Train dataset columns:", train_data.columns)
37
  except Exception as e:
38
  print(f"Failed to load dataset: {e}")
39
  train_data = pd.DataFrame() # Fallback to empty DataFrame
40
  validation_data = pd.DataFrame()
41
 
42
+ # Check and create the 'text' column
43
+ if "text" not in train_data.columns:
44
+ if "title" in train_data.columns and "content" in train_data.columns:
45
+ train_data["text"] = train_data["title"] + " " + train_data["content"]
46
+ else:
47
+ raise ValueError("The 'text' column is missing, and the required 'title' and 'content' columns are not available to create it.")
48
+
49
  # Ensure the necessary columns exist in the training dataset
50
+ required_columns = ["text", "Ground_Truth_Stress", "Ground_Truth_Anxiety", "Ground_Truth_Depression", "Ground_Truth_Other_binary"]
51
+ for column in required_columns:
52
+ if column not in train_data.columns:
53
+ raise ValueError(f"Missing required column '{column}' in the training dataset.")
 
 
 
 
54
 
55
  # Initialize BM25
56
+ tokenized_train = [doc.split() for doc in train_data["text"]]
57
  bm25 = BM25Okapi(tokenized_train)
58
 
59
  # Set OpenAI API key
 
118
 
119
  if __name__ == "__main__":
120
  interface.launch()
121
+