Ozgur Unlu commited on
Commit
4d843b5
β€’
1 Parent(s): e8a9ce9

added a placeholder message

Browse files
Files changed (1) hide show
  1. app.py +67 -9
app.py CHANGED
@@ -273,7 +273,6 @@ def create_interface():
273
  generator_tokenizer, generator, sentiment_analyzer, content_checker = load_models()
274
  print("Models loaded successfully!")
275
 
276
- # Sample data function remains the same
277
  def fill_sample_data():
278
  return [
279
  "EcoBottle",
@@ -285,18 +284,73 @@ def create_interface():
285
  "professional"
286
  ]
287
 
288
- # Process input function remains the same
289
- def process_input(
 
290
  product_name,
291
  product_description,
292
  target_audience,
293
  key_features,
294
  unique_benefits,
295
  platform,
296
- tone
 
297
  ):
298
- # Your existing process_input function code here
299
- pass
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
300
 
301
  # Create the interface with blocks for custom layout
302
  with gr.Blocks(theme=gr.themes.Default()) as demo:
@@ -309,7 +363,7 @@ def create_interface():
309
  "Fill the form with sample data",
310
  variant="primary",
311
  size="sm",
312
- scale=0.2 # Makes button smaller
313
  )
314
 
315
  # Main content area with two columns
@@ -331,7 +385,11 @@ def create_interface():
331
 
332
  # Right column - Output
333
  with gr.Column(scale=1):
334
- output = gr.Textbox(label="Generated Content", lines=12)
 
 
 
 
335
 
336
  # Connect the buttons to functions
337
  fill_button.click(
@@ -348,7 +406,7 @@ def create_interface():
348
  )
349
 
350
  submit_button.click(
351
- fn=process_input,
352
  inputs=[
353
  product_name,
354
  product_description,
 
273
  generator_tokenizer, generator, sentiment_analyzer, content_checker = load_models()
274
  print("Models loaded successfully!")
275
 
 
276
  def fill_sample_data():
277
  return [
278
  "EcoBottle",
 
284
  "professional"
285
  ]
286
 
287
+ import time
288
+
289
+ def process_input_with_loading(
290
  product_name,
291
  product_description,
292
  target_audience,
293
  key_features,
294
  unique_benefits,
295
  platform,
296
+ tone,
297
+ progress=gr.Progress()
298
  ):
299
+ # Initial loading message
300
+ features_list = """⚑ While I generate your content, here's what I can do:
301
+
302
+ πŸ“ Generate multiple unique marketing messages
303
+ 🎯 Adapt content for different platforms
304
+ πŸ” Ensure ethical content generation
305
+ πŸ“Š Analyze sentiment and safety
306
+ ✨ Create platform-specific formatting
307
+
308
+ Processing your request..."""
309
+
310
+ yield features_list + "\n\n⏳ Starting generation..."
311
+ time.sleep(1)
312
+
313
+ # Update message with steps
314
+ steps = [
315
+ "Loading language models...",
316
+ "Analyzing product information...",
317
+ "Generating content variations...",
318
+ "Checking content safety...",
319
+ "Finalizing output..."
320
+ ]
321
+
322
+ for i, step in enumerate(steps, 1):
323
+ progress(i/len(steps))
324
+ yield features_list + f"\n\n⏳ {step}"
325
+ time.sleep(1)
326
+
327
+ # Generate actual content
328
+ try:
329
+ results = generate_content(
330
+ product_name,
331
+ product_description,
332
+ target_audience,
333
+ key_features,
334
+ unique_benefits,
335
+ platform,
336
+ tone,
337
+ generator_tokenizer,
338
+ generator,
339
+ sentiment_analyzer,
340
+ content_checker
341
+ )
342
+
343
+ output = "🎯 Generated Marketing Content:\n\n"
344
+ for i, content in enumerate(results, 1):
345
+ output += f"Version {i}:\n"
346
+ output += f"πŸ“ Content: {content['text']}\n"
347
+ output += f"😊 Sentiment: {content['sentiment']}\n"
348
+ output += f"βœ… Safety Score: {content['safety_score']}\n"
349
+ output += "-" * 50 + "\n"
350
+
351
+ yield output
352
+ except Exception as e:
353
+ yield f"An error occurred: {str(e)}"
354
 
355
  # Create the interface with blocks for custom layout
356
  with gr.Blocks(theme=gr.themes.Default()) as demo:
 
363
  "Fill the form with sample data",
364
  variant="primary",
365
  size="sm",
366
+ scale=0.2
367
  )
368
 
369
  # Main content area with two columns
 
385
 
386
  # Right column - Output
387
  with gr.Column(scale=1):
388
+ output = gr.Textbox(
389
+ label="Generated Content",
390
+ lines=12,
391
+ value="✨ Enter your product details and click 'Generate Content' to start!"
392
+ )
393
 
394
  # Connect the buttons to functions
395
  fill_button.click(
 
406
  )
407
 
408
  submit_button.click(
409
+ fn=process_input_with_loading,
410
  inputs=[
411
  product_name,
412
  product_description,