AI SEO alt text generator
This commit is contained in:
@@ -9,6 +9,7 @@ Alwrity gives hyper content personalization, factual web researched & SEO optimi
|
||||
AI will help achieve Content Hyper-Personalization.
|
||||

|
||||
---
|
||||
|
||||
1). [Visit alwrity.com](https://www.alwrity.com/ai-writing-tools), You will find AI content writing tools, which are Free & No-Signup.
|
||||
**Note:** Although, this is limited, as is our wallet & Resources.
|
||||
|
||||
@@ -19,15 +20,17 @@ If you have 💻 Laptop + 🛜 Internet + 10 minutes, you will be generating blo
|
||||
### [Step-By-Step: Getting Started for Absolute Begginers](https://www.alwrity.com/post/getting-started-with-alwrity-ai-writer)
|
||||
|
||||
---
|
||||
### [Getting started for Developers](https://github.com/AJaySi/AI-Writer/wiki/Alwrity--%E2%80%90-Get-started)
|
||||
|
||||
### [Getting started for Developers](https://github.com/AJaySi/AI-Writer/wiki/Getting-started-with-ALwrity-AI-writer)
|
||||
```
|
||||
1). git clone https://github.com/AJaySi/AI-Writer.git
|
||||
2). pip install -r -U requirements.txt
|
||||
2). pip install -r requirements.txt
|
||||
3). streamlit run alwrity.py
|
||||
|
||||
4). Visit Alwrity UI in a Browser & Start generation AI personalized content.
|
||||
```
|
||||
---
|
||||
|
||||
### Updating to latest Code: (Existing users)
|
||||
```
|
||||
1). Git pull
|
||||
|
||||
77
lib/ai_seo_tools/image_alt_text_generator.py
Normal file
77
lib/ai_seo_tools/image_alt_text_generator.py
Normal file
@@ -0,0 +1,77 @@
|
||||
import streamlit as st
|
||||
import base64
|
||||
import requests
|
||||
from PIL import Image
|
||||
import os
|
||||
|
||||
|
||||
# Function to encode the image
|
||||
def encode_image(image_path):
|
||||
with open(image_path, "rb") as image_file:
|
||||
return base64.b64encode(image_file.read()).decode('utf-8')
|
||||
|
||||
def get_image_description(image_path):
|
||||
base64_image = encode_image(image_path)
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": f"Bearer {os.getenv('OPENAI_API_KEY')}"
|
||||
}
|
||||
|
||||
payload = {
|
||||
"model": "gpt-4o-mini",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": """You are an SEO expert specializing in writing optimized Alt text for images.
|
||||
Your goal is to create clear, descriptive, and concise Alt text that accurately represents
|
||||
the content and context of the given image. Make sure your response is optimized for search engines and accessibility."""
|
||||
},
|
||||
{
|
||||
"type": "image_url",
|
||||
"image_url": {
|
||||
"url": f"data:image/jpeg;base64,{base64_image}"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"max_tokens": 300
|
||||
}
|
||||
|
||||
response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload)
|
||||
response_data = response.json()
|
||||
|
||||
# Extract the content field from the response
|
||||
content = response_data['choices'][0]['message']['content']
|
||||
return content
|
||||
|
||||
|
||||
def alt_text_gen():
|
||||
st.title("Image Description Generator")
|
||||
|
||||
image_path = st.text_input("Enter the full path of the image file")
|
||||
|
||||
if image_path:
|
||||
if os.path.exists(image_path) and image_path.lower().endswith(('jpg', 'jpeg', 'png')):
|
||||
try:
|
||||
image = Image.open(image_path)
|
||||
st.image(image, caption='Uploaded Image', use_column_width=True)
|
||||
|
||||
if st.button("Get Image Alt Text"):
|
||||
with st.spinner("Generating Alt Text..."):
|
||||
try:
|
||||
description = get_image_description(image_path)
|
||||
st.success("Alt Text generated successfully!")
|
||||
st.write("ALt Text:", description)
|
||||
except Exception as e:
|
||||
st.error(f"Error generating description: {e}")
|
||||
except Exception as e:
|
||||
st.error(f"Error processing image: {e}")
|
||||
else:
|
||||
st.error("Please enter a valid image file path ending with .jpg, .jpeg, or .png")
|
||||
else:
|
||||
st.info("Please enter the full path of an image file.")
|
||||
@@ -1,80 +0,0 @@
|
||||
import re
|
||||
|
||||
#######################################################################
|
||||
#
|
||||
# I want you to act as a plagiarism checker. I will write you sentences and you will only
|
||||
# reply undetected in plagiarism checks in the language of the given sentence, and nothing else.
|
||||
# Do not write explanations on replies. My first sentence is {}
|
||||
#
|
||||
######################################################################
|
||||
|
||||
|
||||
class PlagiarismChecker:
|
||||
def __init__(self, known_sources):
|
||||
self.known_sources = known_sources
|
||||
|
||||
def check_plagiarism(self, html_content):
|
||||
try:
|
||||
# Preprocess the HTML content by removing HTML tags and extra spaces
|
||||
text = re.sub(r'<[^>]+>', ' ', html_content)
|
||||
text = re.sub(r'\s+', ' ', text).strip().lower()
|
||||
|
||||
# Check for exact matches with known sources
|
||||
for source in self.known_sources:
|
||||
source_text = re.sub(r'<[^>]+>', ' ', source)
|
||||
source_text = re.sub(r'\s+', ' ', source_text).strip().lower()
|
||||
if text == source_text:
|
||||
return f"Plagiarism detected: Matches known source - {source}"
|
||||
|
||||
# If no exact matches are found
|
||||
return "No plagiarism detected. Content is original."
|
||||
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
|
||||
# Example usage:
|
||||
if __name__ == "__main__":
|
||||
# List of known sources
|
||||
known_sources = [
|
||||
"""
|
||||
<html>
|
||||
<head>
|
||||
<title>Sample Page 1</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Hello, World!</h1>
|
||||
<p>This is sample content from known source 1.</p>
|
||||
</body>
|
||||
</html>
|
||||
""",
|
||||
"""
|
||||
<html>
|
||||
<head>
|
||||
<title>Sample Page 2</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Welcome to Known Source 2</h1>
|
||||
<p>This is some content from another known source.</p>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
]
|
||||
|
||||
# HTML content to check for plagiarism
|
||||
html_content = """
|
||||
<html>
|
||||
<head>
|
||||
<title>Sample Page</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Hello, World!</h1>
|
||||
<p>This is sample content.</p>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
plagiarism_checker = PlagiarismChecker(known_sources)
|
||||
result = plagiarism_checker.check_plagiarism(html_content)
|
||||
|
||||
print(result)
|
||||
|
||||
@@ -41,6 +41,7 @@ from lib.ai_writers.ai_essay_writer import ai_essay_generator
|
||||
from lib.ai_seo_tools.seo_structured_data import ai_structured_data
|
||||
from lib.ai_seo_tools.content_title_generator import ai_title_generator
|
||||
from lib.ai_seo_tools.meta_desc_generator import metadesc_generator_main
|
||||
from lib.ai_seo_tools.image_alt_text_generator import alt_text_gen
|
||||
from lib.gpt_providers.text_to_image_generation.main_generate_image_from_prompt import generate_image
|
||||
from lib.content_planning_calender.content_planning_agents_alwrity_crew import ai_agents_planner
|
||||
from ..gpt_providers.text_generation.main_text_generation import llm_text_gen
|
||||
@@ -124,6 +125,7 @@ def ai_seo_tools():
|
||||
"Generate Structured Data - Rich Snippet",
|
||||
"Generate SEO optimized Blog Titles",
|
||||
"Generate Meta Description for SEO",
|
||||
"Generate Image Alt Text",
|
||||
"Quit"
|
||||
]
|
||||
choice = st.selectbox("**👇Select AI SEO Tool:**", options, index=0, format_func=lambda x: f"📝 {x}")
|
||||
@@ -134,6 +136,8 @@ def ai_seo_tools():
|
||||
metadesc_generator_main()
|
||||
elif choice == "Generate SEO optimized Blog Titles":
|
||||
ai_title_generator()
|
||||
elif choice == "Generate Image Alt Text":
|
||||
alt_text_gen()
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user