Ozgur Unlu
commited on
Commit
β’
a4cf769
1
Parent(s):
4d843b5
small changes
Browse files
app.py
CHANGED
@@ -284,73 +284,10 @@ def create_interface():
|
|
284 |
"professional"
|
285 |
]
|
286 |
|
287 |
-
|
|
|
288 |
|
289 |
-
|
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,7 +300,7 @@ Processing your request..."""
|
|
363 |
"Fill the form with sample data",
|
364 |
variant="primary",
|
365 |
size="sm",
|
366 |
-
scale=
|
367 |
)
|
368 |
|
369 |
# Main content area with two columns
|
@@ -381,7 +318,11 @@ Processing your request..."""
|
|
381 |
value="Twitter"
|
382 |
)
|
383 |
tone = gr.Textbox(label="Tone", placeholder="e.g., professional, casual, friendly")
|
384 |
-
|
|
|
|
|
|
|
|
|
385 |
|
386 |
# Right column - Output
|
387 |
with gr.Column(scale=1):
|
@@ -391,33 +332,32 @@ Processing your request..."""
|
|
391 |
value="β¨ Enter your product details and click 'Generate Content' to start!"
|
392 |
)
|
393 |
|
394 |
-
# Connect
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
395 |
fill_button.click(
|
396 |
fn=fill_sample_data,
|
397 |
-
outputs=
|
398 |
-
product_name,
|
399 |
-
product_description,
|
400 |
-
target_audience,
|
401 |
-
key_features,
|
402 |
-
unique_benefits,
|
403 |
-
platform,
|
404 |
-
tone
|
405 |
-
]
|
406 |
)
|
407 |
|
408 |
submit_button.click(
|
409 |
fn=process_input_with_loading,
|
410 |
-
inputs=
|
411 |
-
product_name,
|
412 |
-
product_description,
|
413 |
-
target_audience,
|
414 |
-
key_features,
|
415 |
-
unique_benefits,
|
416 |
-
platform,
|
417 |
-
tone
|
418 |
-
],
|
419 |
outputs=output
|
420 |
)
|
|
|
|
|
|
|
|
|
|
|
421 |
|
422 |
return demo
|
423 |
|
|
|
284 |
"professional"
|
285 |
]
|
286 |
|
287 |
+
def clear_form():
|
288 |
+
return [""] * 7 # Returns empty strings for all 7 input fields
|
289 |
|
290 |
+
# Rest of your process_input_with_loading function remains the same...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
291 |
|
292 |
# Create the interface with blocks for custom layout
|
293 |
with gr.Blocks(theme=gr.themes.Default()) as demo:
|
|
|
300 |
"Fill the form with sample data",
|
301 |
variant="primary",
|
302 |
size="sm",
|
303 |
+
scale=1
|
304 |
)
|
305 |
|
306 |
# Main content area with two columns
|
|
|
318 |
value="Twitter"
|
319 |
)
|
320 |
tone = gr.Textbox(label="Tone", placeholder="e.g., professional, casual, friendly")
|
321 |
+
|
322 |
+
# Buttons row at the bottom of the form
|
323 |
+
with gr.Row():
|
324 |
+
submit_button = gr.Button("Generate Content", variant="primary", scale=2)
|
325 |
+
clear_button = gr.Button("Clear Form", variant="secondary", scale=1)
|
326 |
|
327 |
# Right column - Output
|
328 |
with gr.Column(scale=1):
|
|
|
332 |
value="β¨ Enter your product details and click 'Generate Content' to start!"
|
333 |
)
|
334 |
|
335 |
+
# Connect all buttons to functions
|
336 |
+
input_components = [
|
337 |
+
product_name,
|
338 |
+
product_description,
|
339 |
+
target_audience,
|
340 |
+
key_features,
|
341 |
+
unique_benefits,
|
342 |
+
platform,
|
343 |
+
tone
|
344 |
+
]
|
345 |
+
|
346 |
fill_button.click(
|
347 |
fn=fill_sample_data,
|
348 |
+
outputs=input_components
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
349 |
)
|
350 |
|
351 |
submit_button.click(
|
352 |
fn=process_input_with_loading,
|
353 |
+
inputs=input_components,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
354 |
outputs=output
|
355 |
)
|
356 |
+
|
357 |
+
clear_button.click(
|
358 |
+
fn=clear_form,
|
359 |
+
outputs=input_components
|
360 |
+
)
|
361 |
|
362 |
return demo
|
363 |
|