Spaces:
Sleeping
Sleeping
Update app.py
Browse files47 unmodified lines484950515253545556575859605 unmodified lines666768697071727374757677787980818283848586878889909192939495969798991001011021031041 unmodified line1061071081091101111121131141151161174 unmodified lines12212312412512612712812913013113213313413547 unmodified linesdo_seo,do_budget_roi):# β Session-based limit (optional)if ENABLE_SESSION_LIMIT:if session_usage[session_id] >= MAX_USES:return (f"β οΈ You have reached the maximum limit of {MAX_USES} uses for this session. All functions are now disabled.",f"Remaining attempts: 0/{MAX_USES}",*[gr.update(interactive=False)] * 10,gr.update(value="<div style='background-color:#ffdddd; color:#a33; padding:10px; border-radius:8px; font-weight:bold;'>β οΈ Limit reached β contact agent admin for further details</div>",visible=True5 unmodified lineselse:remaining = "β"if not product_name or not product_name.strip():return ("Please enter a valid product or campaign name.",f"Remaining attempts: {remaining}/{MAX_USES}" if ENABLE_SESSION_LIMIT else "Unlimited attempts",*[gr.update(interactive=True)] * 10,gr.update(value="", visible=False))sections = []if do_competitors:sections.append("Competitor Names: List the major competitor names relevant to this product or campaign.")if do_competitor_analysis:sections.append("Competitor Analysis Insights: Provide a detailed analysis of competitors, including strengths and weaknesses.")if do_message:sections.append("Campaign Messages: Provide key marketing messages tailored for social media, and specify which message is best suited for which channel.")if do_launch_time:sections.append("Best Launch Time: Recommend the optimal timing for campaign launch.")if do_seo:sections.append("SEO Keywords: Suggest relevant SEO keywords for the campaign.")if do_budget_roi:sections.append("Budget and ROI: Estimate campaign budget and expected return on investment.")if not sections:return ("Please select at least one option to generate the marketing plan.",f"Remaining attempts: {remaining}/{MAX_USES}" if ENABLE_SESSION_LIMIT else "Unlimited attempts",*[gr.update(interactive=True)] * 10,gr.update(value="", visible=False))prompt = f"Create a detailed marketing plan for the product or campaign named '{product_name}'.\n"for s in sections:prompt += f"- {s.split(':')[0]}\n"prompt += "\nRespond with each section clearly headed as shown above."try:1 unmodified lineexcept Exception as e:response = f"Error calling API: {e}"if ENABLE_SESSION_LIMIT:if session_usage[session_id] >= MAX_USES:return (f"β Attempt {session_usage[session_id]}/{MAX_USES}\n\n{response}\n\nβ οΈ Limit reached. All functions are now disabled.",f"Remaining attempts: 0/{MAX_USES}",*[gr.update(interactive=False)] * 10,gr.update(value="<div style='background-color:#ffdddd; color:#a33; padding:10px; border-radius:8px; font-weight:bold;'>β οΈ Limit reached β contact agent admin for further details</div>",visible=True4 unmodified linesreturn (f"β Attempt {session_usage[session_id]}/{MAX_USES}\n\n{response}",counter_text,*[gr.update(interactive=True)] * 10,gr.update(value="", visible=False))else:return (response,"Unlimited attempts",*[gr.update(interactive=True)] * 10,gr.update(value="", visible=False))47 unmodified lines484950515253545556575859605 unmodified lines666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071 unmodified line1091101111121131141151161171181191201214 unmodified lines12612712812913013113213313413513613713813947 unmodified linesdo_seo,do_budget_roi):# β Session-based limitif ENABLE_SESSION_LIMIT:if session_usage[session_id] >= MAX_USES:return (f"β οΈ You have reached the maximum limit of {MAX_USES} uses for this session. All functions are now disabled.",f"Remaining attempts: 0/{MAX_USES}",*[gr.update(interactive=False)] * 11, # run_btn β social_channelsgr.update(value="<div style='background-color:#ffdddd; color:#a33; padding:10px; border-radius:8px; font-weight:bold;'>β οΈ Limit reached β contact agent admin for further details</div>",visible=True5 unmodified lineselse:remaining = "β"# π₯ Case: empty product nameif not product_name or not product_name.strip():return ("Please enter a valid product or campaign name.",f"Remaining attempts: {remaining}/{MAX_USES}" if ENABLE_SESSION_LIMIT else "Unlimited attempts",*[gr.update(interactive=True)] * 11,gr.update(value="", visible=False))# π₯ Build sectionssections = []if do_competitors:sections.append("Competitor Names")if do_competitor_analysis:sections.append("Competitor Analysis Insights")if do_message:sections.append("Campaign Messages")if do_launch_time:sections.append("Best Launch Time")if do_seo:sections.append("SEO Keywords")if do_budget_roi:sections.append("Budget and ROI")if not sections:return ("Please select at least one option to generate the marketing plan.",f"Remaining attempts: {remaining}/{MAX_USES}" if ENABLE_SESSION_LIMIT else "Unlimited attempts",*[gr.update(interactive=True)] * 11,gr.update(value="", visible=False))# π© Build promptprompt = f"Create a detailed marketing plan for the product or campaign named '{product_name}'.\n"for s in sections:prompt += f"- {s}\n"prompt += "\nRespond with each section clearly headed as shown above."try:1 unmodified lineexcept Exception as e:response = f"Error calling API: {e}"# π© Return with counter + lock if neededif ENABLE_SESSION_LIMIT:if session_usage[session_id] >= MAX_USES:return (f"β Attempt {session_usage[session_id]}/{MAX_USES}\n\n{response}\n\nβ οΈ Limit reached. All functions are now disabled.",f"Remaining attempts: 0/{MAX_USES}",*[gr.update(interactive=False)] * 11,gr.update(value="<div style='background-color:#ffdddd; color:#a33; padding:10px; border-radius:8px; font-weight:bold;'>β οΈ Limit reached β contact agent admin for further details</div>",visible=True4 unmodified linesreturn (f"β Attempt {session_usage[session_id]}/{MAX_USES}\n\n{response}",counter_text,*[gr.update(interactive=True)] * 11,gr.update(value="", visible=False))else:return (response,"Unlimited attempts",*[gr.update(interactive=True)] * 11,gr.update(value="", visible=False))
app.py+18-14