decodingdatascience commited on
Commit
ace3851
·
verified ·
1 Parent(s): c48511a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -11,7 +11,6 @@ import gradio as gr
11
  from crewai import Agent, Task, Crew
12
 
13
  # --- Optional: ensure key exists (CrewAI will pick it up) ---
14
- # If the key is missing, we still allow template-mode to work.
15
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY", "")
16
 
17
  # --- DDS logo (raw GitHub URL conversion) ---
@@ -20,6 +19,12 @@ def to_raw_github(url: str) -> str:
20
 
21
  LOGO_URL = to_raw_github("https://github.com/Decoding-Data-Science/airesidency/blob/main/dds_logo.jpg")
22
 
 
 
 
 
 
 
23
  # ----------------------------
24
  # Agents (same logic)
25
  # ----------------------------
@@ -236,6 +241,8 @@ def generate(product_brand, target_audience, objective,
236
  # 1) Run the main Crew once
237
  strategy = run_marketing_crew(product_brand, target_audience, objective)
238
 
 
 
239
  # 2) Copy creation
240
  if use_llm and OPENAI_API_KEY:
241
  social = llm_copywriter(strategy, product_brand, target_audience, objective,
@@ -244,13 +251,13 @@ def generate(product_brand, target_audience, objective,
244
  else:
245
  if platform == "LinkedIn":
246
  social = tpl_linkedin(strategy, product_brand, target_audience, objective, hashtags, li_max_words)
247
- fname = f"linkedin_{re.sub(r'\\W+','_',product_brand.lower())}.md"
248
  elif platform == "X (Twitter)":
249
  social = tpl_tweet(strategy, product_brand, target_audience, objective, hashtags, tweet_max_chars)
250
- fname = f"tweet_{re.sub(r'\\W+','_',product_brand.lower())}.txt"
251
  else: # Article
252
  social = tpl_article(strategy, product_brand, target_audience, objective, hashtags, article_max_words)
253
- fname = f"article_{re.sub(r'\\W+','_',product_brand.lower())}.md"
254
 
255
  out_path = Path(fname).resolve()
256
  out_path.write_text(social, encoding="utf-8")
@@ -258,7 +265,7 @@ def generate(product_brand, target_audience, objective,
258
 
259
  # Save LLM result
260
  name_map = {"LinkedIn": "linkedin", "X (Twitter)": "tweet", "Article": "article"}
261
- fname = f"{name_map.get(platform,'post')}_{re.sub(r'\\W+','_',product_brand.lower())}.md"
262
  out_path = Path(fname).resolve()
263
  out_path.write_text(social, encoding="utf-8")
264
  return strategy, social, str(out_path)
 
11
  from crewai import Agent, Task, Crew
12
 
13
  # --- Optional: ensure key exists (CrewAI will pick it up) ---
 
14
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY", "")
15
 
16
  # --- DDS logo (raw GitHub URL conversion) ---
 
19
 
20
  LOGO_URL = to_raw_github("https://github.com/Decoding-Data-Science/airesidency/blob/main/dds_logo.jpg")
21
 
22
+ # --- Helper: safe filename slug ---
23
+ def slugify(s: str) -> str:
24
+ # replace non-word chars with underscores, collapse repeats, strip edges
25
+ slug = re.sub(r"\W+", "_", (s or "").lower())
26
+ return slug.strip("_") or "post"
27
+
28
  # ----------------------------
29
  # Agents (same logic)
30
  # ----------------------------
 
241
  # 1) Run the main Crew once
242
  strategy = run_marketing_crew(product_brand, target_audience, objective)
243
 
244
+ product_slug = slugify(product_brand)
245
+
246
  # 2) Copy creation
247
  if use_llm and OPENAI_API_KEY:
248
  social = llm_copywriter(strategy, product_brand, target_audience, objective,
 
251
  else:
252
  if platform == "LinkedIn":
253
  social = tpl_linkedin(strategy, product_brand, target_audience, objective, hashtags, li_max_words)
254
+ fname = f"linkedin_{product_slug}.md"
255
  elif platform == "X (Twitter)":
256
  social = tpl_tweet(strategy, product_brand, target_audience, objective, hashtags, tweet_max_chars)
257
+ fname = f"tweet_{product_slug}.txt"
258
  else: # Article
259
  social = tpl_article(strategy, product_brand, target_audience, objective, hashtags, article_max_words)
260
+ fname = f"article_{product_slug}.md"
261
 
262
  out_path = Path(fname).resolve()
263
  out_path.write_text(social, encoding="utf-8")
 
265
 
266
  # Save LLM result
267
  name_map = {"LinkedIn": "linkedin", "X (Twitter)": "tweet", "Article": "article"}
268
+ fname = f"{name_map.get(platform,'post')}_{product_slug}.md"
269
  out_path = Path(fname).resolve()
270
  out_path.write_text(social, encoding="utf-8")
271
  return strategy, social, str(out_path)