Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| # Logic-driven content generation | |
| def generate_copywriting(audience, tone, keywords): | |
| # Normalize and analyze inputs | |
| audience = audience.strip().lower() or "health seekers" | |
| tone = tone.lower() | |
| keyword_list = [k.strip().lower() for k in keywords.split(",") if k.strip()] | |
| primary_keyword = keyword_list[0] if keyword_list else "wellness" | |
| secondary_keyword = keyword_list[1] if len(keyword_list) > 1 else None | |
| # Infer audience goals and pain points | |
| is_busy = any(x in audience for x in ["mom", "parent", "busy"]) | |
| is_pro = any(x in audience for x in ["coach", "pro", "trainer"]) | |
| goal = "quick results" if is_busy else "expertise" if is_pro else "balance" | |
| # Keyword intent analysis | |
| if "weight" in primary_keyword or "fit" in primary_keyword: | |
| focus = "physical transformation" | |
| action = "move more" | |
| elif "mental" in primary_keyword or "stress" in primary_keyword: | |
| focus = "mindset shift" | |
| action = "pause and breathe" | |
| elif "nutrition" in primary_keyword or "diet" in primary_keyword: | |
| focus = "healthy eating" | |
| action = "swap one meal" | |
| else: | |
| focus = "overall wellness" | |
| action = "start small" | |
| # Generate hook based on tone and intent | |
| if tone == "motivational": | |
| hook = f"{audience.capitalize()}, your {focus} starts with one step—{action} today!" | |
| elif tone == "funny": | |
| hook = f"Think {primary_keyword} is a myth for {audience}? Spoiler: it’s not (but {action} helps)!" | |
| else: # educational | |
| hook = f"Why {primary_keyword} matters for {audience}—and how {action} changes everything." | |
| # Add secondary keyword nuance if present | |
| if secondary_keyword: | |
| hook += f" (Bonus: add some {secondary_keyword} vibes!)" | |
| # Generate caption with cohesive narrative | |
| caption = f"{hook}\n\n" | |
| if is_busy: | |
| caption += f"Life’s hectic for {audience}, but {primary_keyword} doesn’t need hours. " | |
| elif is_pro: | |
| caption += f"{audience}, your clients crave {primary_keyword}—show them how. " | |
| else: | |
| caption += f"Hey {audience}, {primary_keyword} is simpler than you think. " | |
| caption += f"Try this: {action}. It’s {focus} in action. What’s your next move? Tell me below! " | |
| if tone == "motivational": | |
| caption += "You’re unstoppable—own it! #RiseUp" | |
| elif tone == "funny": | |
| caption += "No excuses (or naps) needed! #HealthHumor" | |
| else: | |
| caption += "Small steps, big impact. #LearnWell" | |
| # Generate post idea based on focus | |
| if focus == "physical transformation": | |
| post_idea = f"A snappy reel: ‘{action}’ for {audience}—{primary_keyword} made fun!" | |
| elif focus == "mindset shift": | |
| post_idea = f"A story poll: ‘{audience}, how do you {action}?’ + a {primary_keyword} tip." | |
| elif focus == "healthy eating": | |
| post_idea = f"A carousel: 3 {primary_keyword} swaps for {audience}—{action} included!" | |
| else: | |
| post_idea = f"A quick IGTV: How {audience} can {action} for {primary_keyword}." | |
| return hook, caption, post_idea | |
| # Minimalistic CSS | |
| css = """ | |
| body {background-color: #f7f9fc; font-family: 'Helvetica', sans-serif; margin: 0; padding: 20px;} | |
| .gr-button {background-color: #5e81ac; color: white; border: none; padding: 8px 16px; border-radius: 4px; font-size: 14px;} | |
| .gr-button:hover {background-color: #4c6b8a;} | |
| .gr-textbox {border: 1px solid #e0e4e8; border-radius: 4px; padding: 8px; font-size: 14px; background-color: #fff;} | |
| h1 {color: #2b3e50; font-size: 24px; text-align: center; margin-bottom: 20px;} | |
| label {color: #5e81ac; font-weight: bold; font-size: 12px; margin-bottom: 4px;} | |
| .gr-box {background-color: #fff; border: 1px solid #e0e4e8; border-radius: 4px; padding: 10px; margin-top: 10px;} | |
| """ | |
| # Gradio interface | |
| with gr.Blocks(css=css, theme=gr.themes.Default()) as app: | |
| gr.Markdown("### Instagram Copywriting Generator") | |
| # Compact input section | |
| with gr.Column(scale=1, min_width=300): | |
| audience_input = gr.Textbox(label="Audience", placeholder="busy moms, fitness pros", lines=1) | |
| tone_input = gr.Dropdown(label="Tone", choices=["Motivational", "Funny", "Educational"], value="Motivational") | |
| keywords_input = gr.Textbox(label="Keywords", placeholder="weight loss, nutrition", lines=1) | |
| generate_btn = gr.Button("Generate") | |
| # Compact output section | |
| with gr.Column(scale=1, min_width=300): | |
| hook_output = gr.Textbox(label="Hook", lines=2, show_copy_button=True, elem_classes="gr-box") | |
| caption_output = gr.Textbox(label="Caption", lines=5, show_copy_button=True, elem_classes="gr-box") | |
| post_idea_output = gr.Textbox(label="Post Idea", lines=2, show_copy_button=True, elem_classes="gr-box") | |
| generate_btn.click( | |
| fn=generate_copywriting, | |
| inputs=[audience_input, tone_input, keywords_input], | |
| outputs=[hook_output, caption_output, post_idea_output] | |
| ) | |
| # Launch the app | |
| app.launch() |