Tngarg commited on
Commit
e3ec474
·
verified ·
1 Parent(s): 9d1cf85

Update seo_agent/seo_agent.py

Browse files
Files changed (1) hide show
  1. seo_agent/seo_agent.py +40 -36
seo_agent/seo_agent.py CHANGED
@@ -1,36 +1,40 @@
1
- # seo_agent.py
2
-
3
- import os
4
- from string import Template
5
- from chat_wrapper import ChatRefiner
6
-
7
- class SEOAgent:
8
- def __init__(self, model_name="gemini-1.5-flash"):
9
- base = os.path.dirname(__file__)
10
- seo_path = os.path.join(base, "prompts", "seo_prompt.txt")
11
- img_path = os.path.join(base, "prompts", "image_prompt.txt")
12
-
13
- self.chat = ChatRefiner(model_name=model_name)
14
-
15
- # load as dollar‐templates
16
- with open(seo_path, encoding="utf-8") as f:
17
- self.seo_template = Template(f.read())
18
- with open(img_path, encoding="utf-8") as f:
19
- self.img_template = Template(f.read())
20
-
21
- def analyze_seo(self, html: str, text: str) -> str:
22
- """
23
- Returns the raw SEO analysis text from the chat model.
24
- """
25
- prompt = self.seo_template.safe_substitute(
26
- html=html,
27
- text=text,
28
- )
29
- return self.chat.answer(prompt)
30
-
31
- def analyze_images(self, images: list[str], text: str) -> str:
32
- prompt = self.img_template.safe_substitute(
33
- images=images, # pass the list directly
34
- text=text,
35
- )
36
- return self.chat.answer(prompt)
 
 
 
 
 
1
+ # seo_agent.py
2
+
3
+ import os
4
+ from string import Template
5
+ from chat_wrapper import ChatRefiner
6
+
7
+ class SEOAgent:
8
+ def __init__(self, model_name="gemini-1.5-flash"):
9
+ base = os.path.dirname(__file__)
10
+ seo_path = os.path.join(base, "prompts", "seo_prompt.txt")
11
+ img_path = os.path.join(base, "prompts", "image_prompt.txt")
12
+
13
+ self.chat = ChatRefiner(model_name=model_name)
14
+
15
+ # load as dollar‐templates
16
+ with open(seo_path, encoding="utf-8") as f:
17
+ self.seo_template = Template(f.read())
18
+ with open(img_path, encoding="utf-8") as f:
19
+ self.img_template = Template(f.read())
20
+
21
+ def analyze_seo(self, html: str, text: str) -> str:
22
+ """
23
+ Returns the raw SEO analysis text from the chat model.
24
+ """
25
+ short_html = html[:5000]
26
+ short_text = text[:5000]
27
+ prompt = self.seo_template.safe_substitute(
28
+ html=short_html,
29
+ text=short_text,
30
+ )
31
+ return self.chat.answer(prompt)
32
+
33
+ def analyze_images(self, images: list[str], text: str) -> str:
34
+ limited_images = list(dict.fromkeys(images))[:10]
35
+ short_text = text[:5000]
36
+ prompt = self.img_template.safe_substitute(
37
+ images=limited_images, # pass the list directly
38
+ text=short_text,
39
+ )
40
+ return self.chat.answer(prompt)