Update app.py
Browse files
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 |
-
|
| 31 |
-
|
| 32 |
-
|
| 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 =
|
| 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 |
|