pratikshahp commited on
Commit
cb7401f
·
verified ·
1 Parent(s): 4b957b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -12
app.py CHANGED
@@ -9,20 +9,26 @@ llm = HuggingFaceEndpoint(
9
  repo_id="mistralai/Mistral-7B-Instruct-v0.3",
10
  huggingfacehub_api_token=HF_TOKEN,
11
  temperature=0.7,
12
- max_new_tokens=200
13
  )
14
 
 
 
 
 
 
 
15
  def check_and_improve_seo(content):
16
  # Define basic SEO criteria
17
- keywords = ["SEO", "content", "optimization", "keywords", "readability"]
18
  keyword_found = any(keyword.lower() in content.lower() for keyword in keywords)
19
-
20
  # Check readability score
21
  readability_score = textstat.flesch_reading_ease(content)
22
 
23
  # Prepare a prompt for the LLM to improve content
24
  prompt = (
25
- "Optimize the following content for SEO. Ensure it includes relevant keywords, "
26
  "is easy to read, and meets SEO best practices.\n\n"
27
  "Content:\n" + content
28
  )
@@ -31,20 +37,22 @@ def check_and_improve_seo(content):
31
  response = llm(prompt)
32
  optimized_content = response
33
 
34
- # Define SEO checks
35
- seo_checks = {
36
- "Keywords Present": keyword_found,
37
- "Readability Score (Flesch)": readability_score,
38
- "Optimized Content": optimized_content
39
- }
 
 
40
 
41
- return seo_checks
42
 
43
  # Define Gradio interface
44
  interface = gr.Interface(
45
  fn=check_and_improve_seo,
46
  inputs=gr.Textbox(lines=10, placeholder="Enter your content here..."),
47
- outputs="json",
48
  title="SEO Compatibility Checker and Optimizer",
49
  description="Check if the given content is SEO compatible and get an improved version based on SEO best practices."
50
  )
 
9
  repo_id="mistralai/Mistral-7B-Instruct-v0.3",
10
  huggingfacehub_api_token=HF_TOKEN,
11
  temperature=0.7,
12
+ max_new_tokens=500
13
  )
14
 
15
+ def generate_keywords(content):
16
+ prompt = f"Generate a list of most appropriate 10 SEO keywords for the following content:\n\n{content}"
17
+ response = llm(prompt)
18
+ keywords = response.split(",") # Assuming the model returns a comma-separated list
19
+ return [keyword.strip() for keyword in keywords]
20
+
21
  def check_and_improve_seo(content):
22
  # Define basic SEO criteria
23
+ keywords = generate_keywords(content)
24
  keyword_found = any(keyword.lower() in content.lower() for keyword in keywords)
25
+
26
  # Check readability score
27
  readability_score = textstat.flesch_reading_ease(content)
28
 
29
  # Prepare a prompt for the LLM to improve content
30
  prompt = (
31
+ "Optimize the following content for SEO. Ensure it includes appropriate keywords in text, "
32
  "is easy to read, and meets SEO best practices.\n\n"
33
  "Content:\n" + content
34
  )
 
37
  response = llm(prompt)
38
  optimized_content = response
39
 
40
+ # Format the output as plain text
41
+ output = (
42
+ # f"**Generated Keywords:**\n\n"
43
+ #f"Relevant SEO keywords: {', '.join(keywords)}\n\n"
44
+ f"**Keywords Present:** {keyword_found}\n\n"
45
+ f"**Readability Score (Flesch):** {readability_score}\n\n"
46
+ f"**Optimized Content:**\n{optimized_content}"
47
+ )
48
 
49
+ return output
50
 
51
  # Define Gradio interface
52
  interface = gr.Interface(
53
  fn=check_and_improve_seo,
54
  inputs=gr.Textbox(lines=10, placeholder="Enter your content here..."),
55
+ outputs="text", # Change output to 'text' to return plain text
56
  title="SEO Compatibility Checker and Optimizer",
57
  description="Check if the given content is SEO compatible and get an improved version based on SEO best practices."
58
  )