Spaces:
Runtime error
Runtime error
jaifar530
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -101,47 +101,26 @@ for filename, url in file_urls.items():
|
|
| 101 |
# st.write(f"File {filename} already exists. Skipping download.")
|
| 102 |
############ download ridge and ExtraTree stuff
|
| 103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
def check_and_download_files():
|
| 106 |
-
file_names = [
|
| 107 |
-
"truncated_260_to_284.xlsx_vectorizer.pkl",
|
| 108 |
-
"not_trancated_full_paragraph.xlsx_extra_trees_model.pkl",
|
| 109 |
-
"not_trancated_full_paragraph.xlsx_ridge_model.pkl",
|
| 110 |
-
"not_trancated_full_paragraph.xlsx_vectorizer.pkl",
|
| 111 |
-
"truncated_10_to_34.xlsx_extra_trees_model.pkl",
|
| 112 |
-
"truncated_10_to_34.xlsx_ridge_model.pkl",
|
| 113 |
-
"truncated_10_to_34.xlsx_vectorizer.pkl",
|
| 114 |
-
"truncated_35_to_59.xlsx_extra_trees_model.pkl",
|
| 115 |
-
"truncated_35_to_59.xlsx_ridge_model.pkl",
|
| 116 |
-
"truncated_35_to_59.xlsx_vectorizer.pkl",
|
| 117 |
-
"truncated_60_to_84.xlsx_extra_trees_model.pkl",
|
| 118 |
-
"truncated_60_to_84.xlsx_ridge_model.pkl",
|
| 119 |
-
"truncated_60_to_84.xlsx_vectorizer.pkl",
|
| 120 |
-
"truncated_85_to_109.xlsx_extra_trees_model.pkl",
|
| 121 |
-
"truncated_85_to_109.xlsx_ridge_model.pkl",
|
| 122 |
-
"truncated_85_to_109.xlsx_vectorizer.pkl",
|
| 123 |
-
"truncated_110_to_134.xlsx_extra_trees_model.pkl",
|
| 124 |
-
"truncated_110_to_134.xlsx_ridge_model.pkl",
|
| 125 |
-
"truncated_110_to_134.xlsx_vectorizer.pkl",
|
| 126 |
-
"truncated_135_to_159.xlsx_extra_trees_model.pkl",
|
| 127 |
-
"truncated_135_to_159.xlsx_ridge_model.pkl",
|
| 128 |
-
"truncated_135_to_159.xlsx_vectorizer.pkl",
|
| 129 |
-
"truncated_160_to_184.xlsx_extra_trees_model.pkl",
|
| 130 |
-
"truncated_160_to_184.xlsx_ridge_model.pkl",
|
| 131 |
-
"truncated_160_to_184.xlsx_vectorizer.pkl",
|
| 132 |
-
"truncated_185_to_209.xlsx_extra_trees_model.pkl",
|
| 133 |
-
"truncated_185_to_209.xlsx_ridge_model.pkl",
|
| 134 |
-
"truncated_185_to_209.xlsx_vectorizer.pkl",
|
| 135 |
-
"truncated_210_to_234.xlsx_extra_trees_model.pkl",
|
| 136 |
-
"truncated_210_to_234.xlsx_ridge_model.pkl",
|
| 137 |
-
"truncated_210_to_234.xlsx_vectorizer.pkl",
|
| 138 |
-
"truncated_235_to_259.xlsx_extra_trees_model.pkl",
|
| 139 |
-
"truncated_235_to_259.xlsx_ridge_model.pkl",
|
| 140 |
-
"truncated_235_to_259.xlsx_vectorizer.pkl",
|
| 141 |
-
"truncated_260_to_284.xlsx_extra_trees_model.pkl",
|
| 142 |
-
"truncated_260_to_284.xlsx_ridge_model.pkl"
|
| 143 |
-
]
|
| 144 |
missing_files = []
|
|
|
|
| 145 |
for file_name in file_names:
|
| 146 |
if not os.path.exists(file_name):
|
| 147 |
missing_files.append(file_name)
|
|
@@ -150,29 +129,40 @@ def check_and_download_files():
|
|
| 150 |
print("The following files are missing:")
|
| 151 |
for file_name in missing_files:
|
| 152 |
print(file_name)
|
| 153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
try:
|
| 155 |
headers = {
|
| 156 |
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3',
|
| 157 |
}
|
| 158 |
-
url = 'https://jaifar.net/ADS/content.zip'
|
| 159 |
-
|
| 160 |
response = requests.get(url, headers=headers)
|
| 161 |
response.raise_for_status()
|
| 162 |
|
| 163 |
with open('content.zip', 'wb') as zip_file:
|
| 164 |
zip_file.write(response.content)
|
| 165 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
with zipfile.ZipFile('content.zip', 'r') as zip_ref:
|
| 167 |
zip_ref.extractall()
|
| 168 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
print("content.zip downloaded and extracted successfully.")
|
| 170 |
except Exception as e:
|
| 171 |
print(f"Error downloading or extracting content.zip: {e}")
|
| 172 |
else:
|
| 173 |
print("All files exist.")
|
| 174 |
|
| 175 |
-
|
| 176 |
check_and_download_files()
|
| 177 |
|
| 178 |
############### Load CNN Model ############
|
|
|
|
| 101 |
# st.write(f"File {filename} already exists. Skipping download.")
|
| 102 |
############ download ridge and ExtraTree stuff
|
| 103 |
|
| 104 |
+
def has_internet_connection():
|
| 105 |
+
try:
|
| 106 |
+
response = requests.get("https://www.google.com/", timeout=5)
|
| 107 |
+
return True
|
| 108 |
+
except requests.ConnectionError:
|
| 109 |
+
return False
|
| 110 |
+
|
| 111 |
+
def is_zip_file(file_path):
|
| 112 |
+
return zipfile.is_zipfile(file_path)
|
| 113 |
+
|
| 114 |
+
def are_files_extracted(extracted_files, missing_files):
|
| 115 |
+
for file in missing_files:
|
| 116 |
+
if file not in extracted_files:
|
| 117 |
+
return False
|
| 118 |
+
return True
|
| 119 |
|
| 120 |
def check_and_download_files():
|
| 121 |
+
file_names = [ ... ] # Existing list of files
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
missing_files = []
|
| 123 |
+
|
| 124 |
for file_name in file_names:
|
| 125 |
if not os.path.exists(file_name):
|
| 126 |
missing_files.append(file_name)
|
|
|
|
| 129 |
print("The following files are missing:")
|
| 130 |
for file_name in missing_files:
|
| 131 |
print(file_name)
|
| 132 |
+
|
| 133 |
+
if not has_internet_connection():
|
| 134 |
+
print("No internet connection. Cannot download missing files.")
|
| 135 |
+
return
|
| 136 |
+
|
| 137 |
try:
|
| 138 |
headers = {
|
| 139 |
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3',
|
| 140 |
}
|
| 141 |
+
url = 'https://jaifar.net/ADS/content.zip'
|
|
|
|
| 142 |
response = requests.get(url, headers=headers)
|
| 143 |
response.raise_for_status()
|
| 144 |
|
| 145 |
with open('content.zip', 'wb') as zip_file:
|
| 146 |
zip_file.write(response.content)
|
| 147 |
|
| 148 |
+
if not is_zip_file('content.zip'):
|
| 149 |
+
print("Downloaded content is not a ZIP file.")
|
| 150 |
+
return
|
| 151 |
+
|
| 152 |
with zipfile.ZipFile('content.zip', 'r') as zip_ref:
|
| 153 |
zip_ref.extractall()
|
| 154 |
|
| 155 |
+
extracted_files = os.listdir()
|
| 156 |
+
if not are_files_extracted(extracted_files, missing_files):
|
| 157 |
+
print("Not all missing files were extracted.")
|
| 158 |
+
return
|
| 159 |
+
|
| 160 |
print("content.zip downloaded and extracted successfully.")
|
| 161 |
except Exception as e:
|
| 162 |
print(f"Error downloading or extracting content.zip: {e}")
|
| 163 |
else:
|
| 164 |
print("All files exist.")
|
| 165 |
|
|
|
|
| 166 |
check_and_download_files()
|
| 167 |
|
| 168 |
############### Load CNN Model ############
|