Spaces:
Runtime error
Runtime error
File size: 1,789 Bytes
1503dc9 e30adea c34621f 1503dc9 ef529cc 1503dc9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import gradio as gr
import textstat
from langchain_huggingface import HuggingFaceEndpoint
import os
# Set up Hugging Face API token and model endpoint
HF_TOKEN = os.getenv("HF_TOKEN") # Ensure you have your token set in your environment
print(HF_TOKEN)
llm = HuggingFaceEndpoint(
repo_id="mistralai/Mistral-7B-Instruct-v0.3",
huggingfacehub_api_token=HF_TOKEN.strip(),
temperature=0.7,
max_new_tokens=200
)
def check_and_improve_seo(content):
# Define basic SEO criteria
keywords = ["SEO", "content", "optimization", "keywords", "readability"]
keyword_found = any(keyword.lower() in content.lower() for keyword in keywords)
# Check readability score
readability_score = textstat.flesch_reading_ease(content)
# Prepare a prompt for the LLM to improve content
prompt = (
"Optimize the following content for SEO. Ensure it includes relevant keywords, "
"is easy to read, and meets SEO best practices.\n\n"
"Content:\n" + content
)
# Generate SEO-optimized content using the Hugging Face model
response = llm(prompt)
optimized_content = response
# Define SEO checks
seo_checks = {
"Keywords Present": keyword_found,
"Readability Score (Flesch)": readability_score,
"Optimized Content": optimized_content
}
return seo_checks
# Define Gradio interface
interface = gr.Interface(
fn=check_and_improve_seo,
inputs=gr.Textbox(lines=10, placeholder="Enter your content here..."),
outputs="json",
title="SEO Compatibility Checker and Optimizer",
description="Check if the given content is SEO compatible and get an improved version based on SEO best practices."
)
# Launch the app
if __name__ == "__main__":
interface.launch()
|