SailajaS commited on
Commit
e4db00f
Β·
verified Β·
1 Parent(s): 562dab9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -14
app.py CHANGED
@@ -12,7 +12,7 @@ import requests
12
 
13
  app = FastAPI()
14
 
15
- # Hugging Face Dataset URL
16
  DATASET_URL = "https://huggingface.co/datasets/SailajaS/CDART/resolve/main/train.csv"
17
 
18
  # File path for saving dataset
@@ -21,31 +21,28 @@ DATASET_PATH = "dataset.csv"
21
  # Function to download dataset
22
  def download_dataset():
23
  if not os.path.exists(DATASET_PATH):
 
24
  response = requests.get(DATASET_URL)
 
25
  if response.status_code == 200:
26
  with open(DATASET_PATH, "wb") as file:
27
  file.write(response.content)
28
  print("βœ… Dataset downloaded successfully!")
29
  else:
30
- raise Exception(f"❌ Failed to download dataset: {response.status_code}")
31
-
32
- # Function to load dataset
33
- def load_data(file_path):
34
- df = pd.read_csv(file_path) # Load CSV directly
35
- return df
36
-
37
- # Placeholder for dataset and model
38
- df = None
39
- model = None
40
- encoder = LabelEncoder()
41
 
42
  # Download dataset at startup
43
- download_dataset()
 
 
44
 
45
  # Load dataset
46
- df = load_data(DATASET_PATH)
47
 
48
  # Encode categorical variables
 
49
  df["Case Problem"] = encoder.fit_transform(df["Case Problem"])
50
  df["Feedback"] = encoder.fit_transform(df["Feedback"])
51
 
 
12
 
13
  app = FastAPI()
14
 
15
+ # βœ… Correct Hugging Face Dataset URL
16
  DATASET_URL = "https://huggingface.co/datasets/SailajaS/CDART/resolve/main/train.csv"
17
 
18
  # File path for saving dataset
 
21
  # Function to download dataset
22
  def download_dataset():
23
  if not os.path.exists(DATASET_PATH):
24
+ print("πŸ“₯ Downloading dataset...")
25
  response = requests.get(DATASET_URL)
26
+
27
  if response.status_code == 200:
28
  with open(DATASET_PATH, "wb") as file:
29
  file.write(response.content)
30
  print("βœ… Dataset downloaded successfully!")
31
  else:
32
+ print(f"❌ Failed to download dataset: {response.status_code}")
33
+ return False
34
+ return True
 
 
 
 
 
 
 
 
35
 
36
  # Download dataset at startup
37
+ dataset_downloaded = download_dataset()
38
+ if not dataset_downloaded:
39
+ raise Exception("❌ Unable to start app: Dataset download failed.")
40
 
41
  # Load dataset
42
+ df = pd.read_csv(DATASET_PATH)
43
 
44
  # Encode categorical variables
45
+ encoder = LabelEncoder()
46
  df["Case Problem"] = encoder.fit_transform(df["Case Problem"])
47
  df["Feedback"] = encoder.fit_transform(df["Feedback"])
48