Update app.py
Browse files
app.py
CHANGED
|
@@ -167,37 +167,10 @@ custom_css = """
|
|
| 167 |
}
|
| 168 |
"""
|
| 169 |
|
| 170 |
-
custom_js = """
|
| 171 |
-
function getUserId() {
|
| 172 |
-
let userId = localStorage.getItem('wordlift_user_id');
|
| 173 |
-
if (!userId) {
|
| 174 |
-
userId = generateUUID();
|
| 175 |
-
localStorage.setItem('wordlift_user_id', userId);
|
| 176 |
-
}
|
| 177 |
-
return userId;
|
| 178 |
-
}
|
| 179 |
-
|
| 180 |
-
function generateUUID() {
|
| 181 |
-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
| 182 |
-
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
|
| 183 |
-
return v.toString(16);
|
| 184 |
-
});
|
| 185 |
-
}
|
| 186 |
-
|
| 187 |
-
function setUserId(userId) {
|
| 188 |
-
document.getElementById('user-id-input').value = userId;
|
| 189 |
-
}
|
| 190 |
-
|
| 191 |
-
// Set user ID when page loads
|
| 192 |
-
document.addEventListener('DOMContentLoaded', (event) => {
|
| 193 |
-
setUserId(getUserId());
|
| 194 |
-
});
|
| 195 |
-
"""
|
| 196 |
-
|
| 197 |
# Initialize user ID
|
| 198 |
user_id = str(uuid.uuid4())
|
| 199 |
|
| 200 |
-
with gr.Blocks(css=custom_css
|
| 201 |
gr.Markdown("<h1>WordLift Product Description Generation - [FREE]</h1>")
|
| 202 |
with gr.Tab(label="WordLift Product Description Generation"):
|
| 203 |
with gr.Row():
|
|
@@ -248,7 +221,7 @@ with gr.Blocks(css=custom_css, js=custom_js) as demo:
|
|
| 248 |
user_id_display = gr.Markdown(visible=True, label="User ID")
|
| 249 |
|
| 250 |
# Hidden textbox to store user ID
|
| 251 |
-
user_id_input = gr.Textbox(
|
| 252 |
|
| 253 |
|
| 254 |
# Toggle visibility of custom instruction based on selected type
|
|
@@ -261,8 +234,11 @@ with gr.Blocks(css=custom_css, js=custom_js) as demo:
|
|
| 261 |
outputs=[custom_instruction],
|
| 262 |
)
|
| 263 |
|
|
|
|
| 264 |
def handle_submit(image, description_type, custom_instruction, user_id):
|
| 265 |
-
|
|
|
|
|
|
|
| 266 |
check_and_reset_user_counter(user_id) # Check and reset counter if it's a new day
|
| 267 |
test_counter = increment_user_counter(user_id)
|
| 268 |
|
|
@@ -279,7 +255,7 @@ with gr.Blocks(css=custom_css, js=custom_js) as demo:
|
|
| 279 |
gr.update(interactive=True),
|
| 280 |
f"You have {remaining_tests} free test(s) remaining today.",
|
| 281 |
f"User ID: {user_id}",
|
| 282 |
-
user_id
|
| 283 |
)
|
| 284 |
else:
|
| 285 |
redirect_text = f"""
|
|
@@ -306,7 +282,7 @@ with gr.Blocks(css=custom_css, js=custom_js) as demo:
|
|
| 306 |
gr.update(interactive=False),
|
| 307 |
"You've used all your free tests for today. We invite you to book a demo for full access!",
|
| 308 |
f"User ID: {user_id}",
|
| 309 |
-
user_id
|
| 310 |
)
|
| 311 |
else:
|
| 312 |
redirect_text = f"""
|
|
@@ -333,11 +309,10 @@ with gr.Blocks(css=custom_css, js=custom_js) as demo:
|
|
| 333 |
gr.update(interactive=False),
|
| 334 |
"All free tests used. We invite you to book a demo for full access!",
|
| 335 |
f"User ID: {user_id}",
|
| 336 |
-
user_id
|
| 337 |
)
|
| 338 |
|
| 339 |
|
| 340 |
-
|
| 341 |
# Update the outputs of the submit button click event
|
| 342 |
submit_btn.click(
|
| 343 |
handle_submit,
|
|
|
|
| 167 |
}
|
| 168 |
"""
|
| 169 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
# Initialize user ID
|
| 171 |
user_id = str(uuid.uuid4())
|
| 172 |
|
| 173 |
+
with gr.Blocks(css=custom_css) as demo:
|
| 174 |
gr.Markdown("<h1>WordLift Product Description Generation - [FREE]</h1>")
|
| 175 |
with gr.Tab(label="WordLift Product Description Generation"):
|
| 176 |
with gr.Row():
|
|
|
|
| 221 |
user_id_display = gr.Markdown(visible=True, label="User ID")
|
| 222 |
|
| 223 |
# Hidden textbox to store user ID
|
| 224 |
+
user_id_input = gr.Textbox(value="", visible=False)
|
| 225 |
|
| 226 |
|
| 227 |
# Toggle visibility of custom instruction based on selected type
|
|
|
|
| 234 |
outputs=[custom_instruction],
|
| 235 |
)
|
| 236 |
|
| 237 |
+
# Modify the handle_submit function
|
| 238 |
def handle_submit(image, description_type, custom_instruction, user_id):
|
| 239 |
+
if not user_id:
|
| 240 |
+
user_id = str(uuid.uuid4())
|
| 241 |
+
|
| 242 |
check_and_reset_user_counter(user_id) # Check and reset counter if it's a new day
|
| 243 |
test_counter = increment_user_counter(user_id)
|
| 244 |
|
|
|
|
| 255 |
gr.update(interactive=True),
|
| 256 |
f"You have {remaining_tests} free test(s) remaining today.",
|
| 257 |
f"User ID: {user_id}",
|
| 258 |
+
user_id
|
| 259 |
)
|
| 260 |
else:
|
| 261 |
redirect_text = f"""
|
|
|
|
| 282 |
gr.update(interactive=False),
|
| 283 |
"You've used all your free tests for today. We invite you to book a demo for full access!",
|
| 284 |
f"User ID: {user_id}",
|
| 285 |
+
user_id
|
| 286 |
)
|
| 287 |
else:
|
| 288 |
redirect_text = f"""
|
|
|
|
| 309 |
gr.update(interactive=False),
|
| 310 |
"All free tests used. We invite you to book a demo for full access!",
|
| 311 |
f"User ID: {user_id}",
|
| 312 |
+
user_id
|
| 313 |
)
|
| 314 |
|
| 315 |
|
|
|
|
| 316 |
# Update the outputs of the submit button click event
|
| 317 |
submit_btn.click(
|
| 318 |
handle_submit,
|