Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,7 @@ import matplotlib.pyplot as plt
|
|
| 6 |
import os
|
| 7 |
import openai
|
| 8 |
from sklearn.preprocessing import LabelEncoder
|
| 9 |
-
import requests
|
| 10 |
from io import BytesIO
|
| 11 |
import gdown
|
| 12 |
|
|
@@ -175,12 +175,11 @@ def create_brand_categories():
|
|
| 175 |
@st.cache_resource
|
| 176 |
def download_file_from_google_drive(file_id):
|
| 177 |
"""Downloads a file from Google Drive using gdown."""
|
|
|
|
| 178 |
try:
|
| 179 |
with st.spinner('Downloading from Google Drive...'):
|
| 180 |
-
# Use gdown with confirmation flag
|
| 181 |
output = f"temp_{file_id}.pkl"
|
| 182 |
-
url
|
| 183 |
-
gdown.download(url, output, quiet=False, fuzzy=True)
|
| 184 |
|
| 185 |
with open(output, 'rb') as f:
|
| 186 |
content = f.read()
|
|
@@ -191,15 +190,7 @@ def download_file_from_google_drive(file_id):
|
|
| 191 |
|
| 192 |
except Exception as e:
|
| 193 |
st.error(f"Error downloading from Google Drive: {str(e)}")
|
| 194 |
-
|
| 195 |
-
url = f"https://drive.google.com/uc?export=download&id={file_id}&confirm=t"
|
| 196 |
-
response = requests.get(url)
|
| 197 |
-
if response.status_code == 200:
|
| 198 |
-
return response.content
|
| 199 |
-
else:
|
| 200 |
-
raise Exception(f"Failed to download with status code: {response.status_code}")
|
| 201 |
-
except Exception as e2:
|
| 202 |
-
raise Exception(f"Both download methods failed. Error: {str(e2)}")
|
| 203 |
|
| 204 |
@st.cache_data
|
| 205 |
def load_datasets():
|
|
|
|
| 6 |
import os
|
| 7 |
import openai
|
| 8 |
from sklearn.preprocessing import LabelEncoder
|
| 9 |
+
import requests # Add this at the top with other imports
|
| 10 |
from io import BytesIO
|
| 11 |
import gdown
|
| 12 |
|
|
|
|
| 175 |
@st.cache_resource
|
| 176 |
def download_file_from_google_drive(file_id):
|
| 177 |
"""Downloads a file from Google Drive using gdown."""
|
| 178 |
+
url = f"https://drive.google.com/uc?id={file_id}"
|
| 179 |
try:
|
| 180 |
with st.spinner('Downloading from Google Drive...'):
|
|
|
|
| 181 |
output = f"temp_{file_id}.pkl"
|
| 182 |
+
gdown.download(url, output, quiet=False)
|
|
|
|
| 183 |
|
| 184 |
with open(output, 'rb') as f:
|
| 185 |
content = f.read()
|
|
|
|
| 190 |
|
| 191 |
except Exception as e:
|
| 192 |
st.error(f"Error downloading from Google Drive: {str(e)}")
|
| 193 |
+
raise e
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
|
| 195 |
@st.cache_data
|
| 196 |
def load_datasets():
|