cyberandy commited on
Commit
56f3e42
·
verified ·
1 Parent(s): 25e9b9f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -23
app.py CHANGED
@@ -54,7 +54,7 @@ def increment_user_counter(user_id):
54
  # Function to get or create user ID from cookie
55
  def get_or_create_user_id(request: gr.Request):
56
  if request is None:
57
- return str(uuid.uuid4())
58
 
59
  cookies = SimpleCookie()
60
  cookies.load(request.headers.get('cookie', ''))
@@ -62,13 +62,9 @@ def get_or_create_user_id(request: gr.Request):
62
 
63
  if user_id is None:
64
  user_id = str(uuid.uuid4())
65
- cookies['user_id'] = user_id
66
- cookies['user_id']['httponly'] = True
67
- cookies['user_id']['max-age'] = 365 * 24 * 60 * 60 # 1 year
68
  else:
69
- user_id = user_id.value
70
-
71
- return user_id, cookies.output(header='', sep=';')
72
 
73
  # Function to encode the image
74
  def encode_image(image_array):
@@ -259,25 +255,25 @@ with gr.Blocks(css=css) as demo:
259
  gr.update(visible=False),
260
  gr.update(interactive=True),
261
  f"You have {remaining_tests} free test(s) remaining today.",
262
- cookie,
263
  )
264
  else:
265
  redirect_text = f"""
266
  Thank you for trying our product description generation tool!
267
-
268
  You've used all 4 of your free tests for today. We hope you found them helpful and insightful.
269
-
270
  To unlock unlimited access and discover how our AI-powered solution can revolutionize your content creation process:
271
-
272
  [Book a Personalized Demo with Our Experts]({demo_link})
273
-
274
  During the demo, you'll get:
275
  • A tailored walkthrough of our full suite of features
276
  • Insights on how to optimize your specific content workflow
277
  • Answers to any questions you may have about our solution
278
-
279
  We're excited to show you how we can help scale your content creation!
280
-
281
  (Your free tests will reset tomorrow, allowing you to try 4 more if you need additional time to decide.)
282
  """
283
  return (
@@ -285,25 +281,25 @@ with gr.Blocks(css=css) as demo:
285
  gr.update(visible=True, value=redirect_text),
286
  gr.update(interactive=False),
287
  "You've used all your free tests for today. We invite you to book a demo for full access!",
288
- cookie,
289
  )
290
  else:
291
  redirect_text = f"""
292
  Thank you for your interest in our product description generation tool!
293
-
294
  You've already used your 4 free tests for today. We hope they've given you a glimpse of how our AI can enhance your content creation.
295
-
296
  Ready to explore the full potential of our solution?
297
-
298
  [Book a Personalized Demo with Our Experts]({demo_link})
299
-
300
  In this demo, you'll discover:
301
  • How our AI can be customized for your specific needs
302
  • Advanced features for scaling your content production
303
  • ROI projections based on your current content workflow
304
-
305
  Let's discuss how we can help you achieve your content goals!
306
-
307
  (Remember, your free tests will reset tomorrow if you need more time to evaluate.)
308
  """
309
  return (
@@ -311,15 +307,21 @@ with gr.Blocks(css=css) as demo:
311
  gr.update(visible=True, value=redirect_text),
312
  gr.update(interactive=False),
313
  "All free tests used. We invite you to book a demo for full access!",
314
- cookie,
315
  )
316
 
317
  submit_btn.click(
318
  handle_submit,
319
  inputs=[input_img, description_type, custom_instruction],
320
- outputs=[output_text, redirect_message, submit_btn, test_counter_display],
321
  )
322
 
 
 
 
 
 
 
323
  # Launch Gradio app
324
  demo.queue(api_open=False)
325
  demo.launch(debug=True)
 
54
  # Function to get or create user ID from cookie
55
  def get_or_create_user_id(request: gr.Request):
56
  if request is None:
57
+ return str(uuid.uuid4()), None
58
 
59
  cookies = SimpleCookie()
60
  cookies.load(request.headers.get('cookie', ''))
 
62
 
63
  if user_id is None:
64
  user_id = str(uuid.uuid4())
65
+ return user_id, ('user_id', user_id, {'httponly': True, 'max_age': 365 * 24 * 60 * 60})
 
 
66
  else:
67
+ return user_id.value, None
 
 
68
 
69
  # Function to encode the image
70
  def encode_image(image_array):
 
255
  gr.update(visible=False),
256
  gr.update(interactive=True),
257
  f"You have {remaining_tests} free test(s) remaining today.",
258
+ cookie, # This cookie is not being set in the response
259
  )
260
  else:
261
  redirect_text = f"""
262
  Thank you for trying our product description generation tool!
263
+
264
  You've used all 4 of your free tests for today. We hope you found them helpful and insightful.
265
+
266
  To unlock unlimited access and discover how our AI-powered solution can revolutionize your content creation process:
267
+
268
  [Book a Personalized Demo with Our Experts]({demo_link})
269
+
270
  During the demo, you'll get:
271
  • A tailored walkthrough of our full suite of features
272
  • Insights on how to optimize your specific content workflow
273
  • Answers to any questions you may have about our solution
274
+
275
  We're excited to show you how we can help scale your content creation!
276
+
277
  (Your free tests will reset tomorrow, allowing you to try 4 more if you need additional time to decide.)
278
  """
279
  return (
 
281
  gr.update(visible=True, value=redirect_text),
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
+ cookie, # This cookie is not being set in the response
285
  )
286
  else:
287
  redirect_text = f"""
288
  Thank you for your interest in our product description generation tool!
289
+
290
  You've already used your 4 free tests for today. We hope they've given you a glimpse of how our AI can enhance your content creation.
291
+
292
  Ready to explore the full potential of our solution?
293
+
294
  [Book a Personalized Demo with Our Experts]({demo_link})
295
+
296
  In this demo, you'll discover:
297
  • How our AI can be customized for your specific needs
298
  • Advanced features for scaling your content production
299
  • ROI projections based on your current content workflow
300
+
301
  Let's discuss how we can help you achieve your content goals!
302
+
303
  (Remember, your free tests will reset tomorrow if you need more time to evaluate.)
304
  """
305
  return (
 
307
  gr.update(visible=True, value=redirect_text),
308
  gr.update(interactive=False),
309
  "All free tests used. We invite you to book a demo for full access!",
310
+ cookie, # This cookie is not being set in the response
311
  )
312
 
313
  submit_btn.click(
314
  handle_submit,
315
  inputs=[input_img, description_type, custom_instruction],
316
+ outputs=[output_text, redirect_message, submit_btn, test_counter_display, gr.Markdown(visible=True, label="User ID")],
317
  )
318
 
319
+ with gr.Column():
320
+ output_text = gr.Markdown(label="Output Text", show_copy_button=True, elem_classes="output-text")
321
+ redirect_message = gr.Markdown(visible=False, elem_classes="redirect-message")
322
+ test_counter_display = gr.Markdown(visible=True, label="Test Counter")
323
+ user_id_display = gr.Markdown(visible=True, label="User ID") # Add this line
324
+
325
  # Launch Gradio app
326
  demo.queue(api_open=False)
327
  demo.launch(debug=True)