Spaces:
Running
Running
jaifar530
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -35,7 +35,7 @@ st.image(banner_image, caption='', use_column_width=True)
|
|
35 |
################ end loading banner image ##################
|
36 |
|
37 |
|
38 |
-
|
39 |
# Check if the model folder exists
|
40 |
zip_file_path = "my_authorship_model_zip.zip"
|
41 |
if not os.path.exists('my_authorship_model'):
|
@@ -76,8 +76,8 @@ if not os.path.exists('my_authorship_model'):
|
|
76 |
except Exception as e:
|
77 |
st.write(f"Failed to download or extract the model: {e}")
|
78 |
exit(1)
|
79 |
-
|
80 |
-
|
81 |
|
82 |
|
83 |
# Download the required files
|
@@ -87,15 +87,19 @@ file_urls = {
|
|
87 |
}
|
88 |
|
89 |
for filename, url in file_urls.items():
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
|
|
|
|
|
|
98 |
|
|
|
99 |
# Load the saved model
|
100 |
loaded_model = load_model("my_authorship_model")
|
101 |
|
@@ -108,6 +112,8 @@ with open('label_encoder.pkl', 'rb') as handle:
|
|
108 |
|
109 |
max_length = 300 # As defined in the training code
|
110 |
|
|
|
|
|
111 |
# Function to predict author for new text
|
112 |
def predict_author(new_text, model, tokenizer, label_encoder):
|
113 |
sequence = tokenizer.texts_to_sequences([new_text])
|
|
|
35 |
################ end loading banner image ##################
|
36 |
|
37 |
|
38 |
+
############# Download Or Check Files/folders exeistince ##############
|
39 |
# Check if the model folder exists
|
40 |
zip_file_path = "my_authorship_model_zip.zip"
|
41 |
if not os.path.exists('my_authorship_model'):
|
|
|
76 |
except Exception as e:
|
77 |
st.write(f"Failed to download or extract the model: {e}")
|
78 |
exit(1)
|
79 |
+
else:
|
80 |
+
st.write("Version: 2.1")
|
81 |
|
82 |
|
83 |
# Download the required files
|
|
|
87 |
}
|
88 |
|
89 |
for filename, url in file_urls.items():
|
90 |
+
if not os.path.exists(filename): # Check if the file doesn't exist
|
91 |
+
try:
|
92 |
+
r = requests.get(url, headers=headers)
|
93 |
+
r.raise_for_status()
|
94 |
+
with open(filename, 'wb') as f:
|
95 |
+
f.write(r.content)
|
96 |
+
except Exception as e:
|
97 |
+
st.write(f"Failed to download {filename}: {e}")
|
98 |
+
exit(1)
|
99 |
+
else:
|
100 |
+
st.write(f"File {filename} already exists. Skipping download.")
|
101 |
|
102 |
+
############### Load CNN Model ############
|
103 |
# Load the saved model
|
104 |
loaded_model = load_model("my_authorship_model")
|
105 |
|
|
|
112 |
|
113 |
max_length = 300 # As defined in the training code
|
114 |
|
115 |
+
############### End Load CNN Model ############
|
116 |
+
|
117 |
# Function to predict author for new text
|
118 |
def predict_author(new_text, model, tokenizer, label_encoder):
|
119 |
sequence = tokenizer.texts_to_sequences([new_text])
|