Spaces:
Sleeping
Sleeping
WebashalarForML
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,7 @@ from utils.anoter_to_json import process_uploaded_json
|
|
7 |
from utils.json_to_spacy import convert_json_to_spacy
|
8 |
from utils.model import train_model
|
9 |
import zipfile
|
|
|
10 |
|
11 |
|
12 |
app = Flask(__name__)
|
@@ -43,6 +44,14 @@ file_path = os.path.join(app.config['DATA_FOLDER'], 'resume_text.txt')
|
|
43 |
with open(file_path, 'w') as file:
|
44 |
pass
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
# Allowed file extensions
|
47 |
ALLOWED_EXTENSIONS = {'pdf', 'docx', 'rsf', 'odt', 'png', 'jpg', 'jpeg', 'json'}
|
48 |
|
@@ -171,7 +180,7 @@ def save_and_download():
|
|
171 |
f.write(edited_text)
|
172 |
|
173 |
# flash('Text edited successfully', 'success')
|
174 |
-
|
175 |
# Now send the file as a download
|
176 |
return send_from_directory(app.config['DATA_FOLDER'], 'resume_text.txt', as_attachment=True)
|
177 |
|
@@ -200,6 +209,7 @@ def upload_json_file():
|
|
200 |
file.save(json_path)
|
201 |
session['uploaded_json'] = filename
|
202 |
flash(f'JSON file {filename} uploaded successfully')
|
|
|
203 |
else:
|
204 |
flash('File type not allowed', 'error')
|
205 |
except Exception as e:
|
@@ -228,7 +238,7 @@ def process_json_file():
|
|
228 |
process_uploaded_json(json_path)
|
229 |
os.makedirs(app.config['DATA_FOLDER'], exist_ok=True)
|
230 |
processed_file_path = os.path.join(app.config['DATA_FOLDER'], f'Processed_{filename}')
|
231 |
-
|
232 |
flash(f'JSON file {filename} processed successfully')
|
233 |
except Exception as e:
|
234 |
flash(f"Error processing JSON file: {str(e)}", 'error')
|
@@ -290,7 +300,7 @@ def to_sapcy():
|
|
290 |
|
291 |
# Call the conversion function
|
292 |
convert_json_to_spacy(json_file_path, spacy_file_path)
|
293 |
-
|
294 |
flash('Model training data converted successfully', 'success')
|
295 |
except Exception as e:
|
296 |
flash(f"Error during conversion: {str(e)}", 'error')
|
@@ -307,7 +317,7 @@ def train_model_endpoint():
|
|
307 |
# Call the training function with user-defined parameters
|
308 |
model_path = f"./Models/ner_model_{version}"
|
309 |
train_model(epochs, model_path)
|
310 |
-
|
311 |
flash('Model training completed successfully', 'success')
|
312 |
except Exception as e:
|
313 |
flash(f"Error during training: {str(e)}", 'error')
|
@@ -371,7 +381,6 @@ def download_latest_model():
|
|
371 |
except Exception as e:
|
372 |
flash(f"Error while downloading the model: {str(e)}", 'error')
|
373 |
return redirect(request.referrer)
|
374 |
-
|
375 |
|
376 |
# Route to serve uploaded files
|
377 |
'''
|
@@ -382,3 +391,4 @@ def uploaded_file(filename):
|
|
382 |
|
383 |
if __name__ == '__main__':
|
384 |
app.run(debug=True)
|
|
|
|
7 |
from utils.json_to_spacy import convert_json_to_spacy
|
8 |
from utils.model import train_model
|
9 |
import zipfile
|
10 |
+
import shutil
|
11 |
|
12 |
|
13 |
app = Flask(__name__)
|
|
|
44 |
with open(file_path, 'w') as file:
|
45 |
pass
|
46 |
|
47 |
+
file_path = os.path.join(app.config['DATA_FOLDER'], 'Json_Data.json')
|
48 |
+
with open(file_path, 'w') as file:
|
49 |
+
pass
|
50 |
+
|
51 |
+
file_path = os.path.join(app.config['DATA_FOLDER'], 'Spacy_data.spacy')
|
52 |
+
with open(file_path, 'w') as file:
|
53 |
+
pass
|
54 |
+
|
55 |
# Allowed file extensions
|
56 |
ALLOWED_EXTENSIONS = {'pdf', 'docx', 'rsf', 'odt', 'png', 'jpg', 'jpeg', 'json'}
|
57 |
|
|
|
180 |
f.write(edited_text)
|
181 |
|
182 |
# flash('Text edited successfully', 'success')
|
183 |
+
print(f"Saved instace: {app.config['DATA_FOLDER']}/resume_text.txt")
|
184 |
# Now send the file as a download
|
185 |
return send_from_directory(app.config['DATA_FOLDER'], 'resume_text.txt', as_attachment=True)
|
186 |
|
|
|
209 |
file.save(json_path)
|
210 |
session['uploaded_json'] = filename
|
211 |
flash(f'JSON file {filename} uploaded successfully')
|
212 |
+
print(f"Saved instace for JSon: {app.config['JSON_FOLDER']}/{filename}")
|
213 |
else:
|
214 |
flash('File type not allowed', 'error')
|
215 |
except Exception as e:
|
|
|
238 |
process_uploaded_json(json_path)
|
239 |
os.makedirs(app.config['DATA_FOLDER'], exist_ok=True)
|
240 |
processed_file_path = os.path.join(app.config['DATA_FOLDER'], f'Processed_{filename}')
|
241 |
+
|
242 |
flash(f'JSON file {filename} processed successfully')
|
243 |
except Exception as e:
|
244 |
flash(f"Error processing JSON file: {str(e)}", 'error')
|
|
|
300 |
|
301 |
# Call the conversion function
|
302 |
convert_json_to_spacy(json_file_path, spacy_file_path)
|
303 |
+
|
304 |
flash('Model training data converted successfully', 'success')
|
305 |
except Exception as e:
|
306 |
flash(f"Error during conversion: {str(e)}", 'error')
|
|
|
317 |
# Call the training function with user-defined parameters
|
318 |
model_path = f"./Models/ner_model_{version}"
|
319 |
train_model(epochs, model_path)
|
320 |
+
print(f"Saved instace for Model: app//Models/ner_model_{version}")
|
321 |
flash('Model training completed successfully', 'success')
|
322 |
except Exception as e:
|
323 |
flash(f"Error during training: {str(e)}", 'error')
|
|
|
381 |
except Exception as e:
|
382 |
flash(f"Error while downloading the model: {str(e)}", 'error')
|
383 |
return redirect(request.referrer)
|
|
|
384 |
|
385 |
# Route to serve uploaded files
|
386 |
'''
|
|
|
391 |
|
392 |
if __name__ == '__main__':
|
393 |
app.run(debug=True)
|
394 |
+
|