New: AI SEO tools- OpenGraph Tags generation, blog from pdf

This commit is contained in:
ajaysi
2024-08-14 14:21:57 +05:30
parent 20bda6c964
commit ac43dee24f
8 changed files with 304 additions and 220 deletions

View File

@@ -1,15 +1,32 @@
> [!NOTE]
><p><em>H Content Enthusiast !</em></p>
><p><em>ALwrity is in the "just for friends" stage and WIP (Work in Progress). Run this App or visit alwrity.com to gauge present status. Read About present features below. Our highly ambitious Roadmap is here. We'd love your feedback or contributions.</em></p>
# How to ALwrity - Getting Started
Alwrity assists content creators and digital marketers in keyword web research, AI website & Social media content generation & AI Copywriting.
ALwrity assists content creators and digital marketers in keyword web research, AI website & Social media content generation & AI Copywriting.
Our toolkit integrates **(OpenAI, Gemini, Anthropic)** AI models for text generation, image creation **(Stability.ai), STT(whisper, AssemblyAI)** and AI Web research **(Tavily AI, exa AI, Serper.dev)**, streamlining your content creation pipeline and ensuring high-quality output with minimal effort.
Prompting is abstracted to get going sooner. Focus on your content quality, rather than AI tooling around it.
Alwrity gives hyper content personalization, factual web researched & SEO optimized content and tools for automating content & digital marketing.
[!NOTE] Wide Range of AI Writers for All platforms
AI content generators for blogs, news, articles, essay, story, Linkedin & Facebook posts, tweets, instagram captions, YT descriptions, titles etc.
Alwrity, is a complete content life cycle platform with Content planning, Content Generation, Content publishing, Analytics & monitoring & more. AI SEO & marketing tools will help reach wider audience. Its in active development with many bridges to cross.
AI will help achieve Content Hyper-Personalization.
![](https://github.com/AJaySi/AI-Writer/blob/main/lib/workspace/keyword_blog.gif)
[!NOTE] Prompting is abstracted to get going sooner.
Focus on your content quality, rather than AI tooling around it.
ALwrity gives hyper content personalization, factual web researched & SEO optimized content and tools for automating content & digital marketing.
[!NOTE] AI Agents for Content planning & Personalized Teams
ALwrity integrates AI Agents team for content creators & Marketing teams. Brainstrom content calenders, write in hyper personlized brand tone, voice. Its very easy to create your own content AI Agents team with ALwrity.
[!NOTE] All in One Content platform (WIP)
Not just AI Writer, content planning, scheduling, publishing, monitoring analytics. ALwrity, is a complete content life cycle platform with **Content planning, Content Generation, Content publishing, Analytics & monitoring & more**. We are busy building blocks for each phase of content life cycle with AI.
[!NOTE] AI SEO & marketing tools (WIP)
AI SEO Tools create Titles, meta descriptions, opengraph tags, structured data(json-ld) are already present to help with technical SEO.
![This helps SEO & For growing your traffic.](https://github.com/AJaySi/AI-Writer/wiki/ALwrity-AI-SEO-Tools)
---
1). [Visit alwrity.com](https://www.alwrity.com/ai-writing-tools), You will find AI content writing tools, which are Free & No-Signup.
@@ -42,59 +59,32 @@ If you have 💻 Laptop + 🛜 Internet + 10 minutes, you will be generating blo
---
Still stuck, [Open issue here](https://github.com/AJaySi/AI-Writer/issues) & Someone will bail you out.
[!NOTE]![Alwrity Documentation is here for more details](https://github.com/AJaySi/AI-Writer/wiki)
---
![AI SEO Tool Structured Data Generator](https://github.com/AJaySi/AI-Writer/blob/main/lib/workspace/structured_data.gif)
![ALwrity AI Blog writer](https://github.com/AJaySi/AI-Writer/blob/main/lib/workspace/keyword_blog.gif)
![ALwrity AI Linkedin Post generator](https://github.com/AJaySi/AI-Writer/blob/main/lib/workspace/Alwrity_linkedin_post_generator.gif)
![ALwrity AI writer](https://github.com/AJaySi/AI-Writer/blob/main/lib/workspace/alwrity_blog_post_writer.gif)
![AI Google Ads Generator](https://github.com/AJaySi/AI-Writer/blob/main/lib/workspace/alwrity_google_ads_generator.gif)
### AI Tools & Features of Alwrity:
| No. | Alwrity Tool | Description |
|-----|------------------------------------|--------------------------------------------------------------------------------|
| 1 | AI Blog Writer | Generates blog content based on the latest web research on given keywords. |
| 2 | AI YouTube to Content Writer | Transforms content from provided YouTube URLs into written form. |
| 3 | AI Long Form Content | Creates extensive and detailed articles. |
| 4 | AI Essay Writer | Produces lengthy essays on various topics, with room for improvement. |
| 5 | AI Story Writer | Constructs narratives and stories based on provided backstories and characters.|
| 6 | AI Email Writer | Generates various types of professional letters. |
| 7 | AI Letter Writer | Crafts business letters for formal communication. |
| 8 | AI LinkedIn Blog Post Generator | Develops blog posts optimized for sharing on LinkedIn. |
| 9 | AI Instagram Caption Generation | Creates engaging captions for Instagram posts. |
| 10 | AI Content Outline Generator | Generates outlines based on keywords gathered from web research. |
| 11 | AI Web Researcher | Conducts comprehensive web research and analysis using various methods. |
| 12 | AI Content Planning & Calendar | Assists in planning and organizing content with a comprehensive calendar. |
| 13 | Create Blog Images | Generates images to complement blog content using Stable Diffusion. |
| 14 | Agentic Content Creation | Explores innovative content creation methods with CrewAI. |
| 15 | AI Finance Writer | Uses ufinance & padnas_ta to write TA report for given stock symbol |
| 16 | AI Agents Team | Easily create AI Agents team for Content creation & Digital marketing |
| 17 | Talk to your Docs (WIP) | Write content from your local documents of any type(multi-modal) |
| 18 | Wordpress API integration | Programmatically upload blogs to wordpress website with API keys |
| 19 | Talk to your website | Crawl Crawl your entire website & write content based on its content, Or Not |
| 20 | Content From URLs | Provide any URL to create an original, unique content from |
| 21 | SEO Structured Data | Feature: AI SEO - Generate rich snippet from url |
---
### ![List of all AI Tools & Features of Alwrity](https://github.com/AJaySi/AI-Writer/wiki/Features-of-ALwrity-AI-writer)
[!NOTE] Alwrity is WIP & Under active development.
---
How To Personlize ALwrity & Content Generation
# AI Content Generation Toolkit - Alwrity
![](https://github.com/AJaySi/AI-Writer/blob/main/lib/workspace/alwrity_ai_writer.png)
(Click to Read Details of each available features)[https://github.com/AJaySi/AI-Writer/wiki/ALwrity-Interface-first-page-explanation]
## Introduction
Alwrity automates and enhances the process of content creation, optimization, and management(Really ?).
Leveraging AI technologies, it assists content creators and digital marketers in generating, formatting,
and uploading blog content efficiently(Hmmmm, OK...).
The toolkit integrates advanced AI models for text generation, image creation,
and data analysis, streamlining the content creation pipeline(Who reads introductions, right!).
## [Read Alwrity Configuration Options](https://www.alwrity.com/post/know-powerful-alwrity-ai-writer-configuration):
Use the [main_config](https://github.com/AJaySi/AI-Writer/blob/main/main_config) file to modify Alwrity behavior for your content needs.
---
## Under the hood:
## Under the hood: Tech-Stack on the shoulders of Giants - (Credits):
### Tech-Stack on the shoulders of Giants - (Credits):
- **APIs**:
- [Exa API](https://exa.ai/): Provides semantic search capabilities for finding similar topics and technologies.
- [Tavily API](https://tavily.com/): Offers AI-powered web search functionality for conducting in-depth keyword research.
@@ -107,6 +97,7 @@ Use the [main_config](https://github.com/AJaySi/AI-Writer/blob/main/main_config)
- [Ollama](https://ollama.com/) : Local, Privacy focused, LLM provider for research and content generation capabilities.
- [CrewAI](https://www.crewai.com/): Collaborative AI agents framework.
- [firecrawl](https://www.firecrawl.dev/): Turn websites into LLM-ready data
---
## Features
@@ -133,16 +124,8 @@ This gives context for generating content. Tavily AI, Google search, serp and Vi
- **Wordpress, Jekyll Integration**: Implemented generating and uploading blog content, media to wordpress via its REST APIs. Most of the static website which can work with markdown style should work with little testing.
### AI-Driven Content Creation
- **Text Generation**: Leverages OpenAI's ChatGPT, Google Gemini Pro for generating text for blogs.
- [**Customizable AI Parameters**](https://github.com/AJaySi/AI-Writer/blob/main/main_config): Offers flexibility in adjusting AI parameters like model selection, temperature, and token limits to suit different content needs.
### Image Detail Extraction
- **Analyzing and Extracting Image Details**: Uses OpenAI's Vision API, Google Gemini vision to analyze images and extract details such as alt text, descriptions, titles, and captions, enhancing the SEO of image content.
---
**Note**: This toolkit is designed for automated blog management and requires appropriate API keys and access credentials for full functionality.
[!NOTE] This toolkit is designed for automated blog management and requires appropriate API keys and access credentials for full functionality.
---
### Web Research

View File

@@ -18,83 +18,78 @@ from lib.ai_writers.ai_story_writer.story_writer import story_input_section
from lib.ai_writers.ai_product_description_writer import write_ai_prod_desc
# Function to check if API keys are present and prompt user to input if not
def check_api_keys():
"""
Checks if the required API keys are present in the environment variables.
Prompts the user to enter missing keys and saves them in the .env file.
"""
api_keys = {
"METAPHOR_API_KEY": "[Get Metaphor AI Key](https://dashboard.exa.ai/login)",
"TAVILY_API_KEY": "[Get Tavily AI Key](https://tavily.com/#api)",
"SERPER_API_KEY": "[Get Serper API Key](https://serper.dev/signup)",
"STABILITY_API_KEY": "[Get Stability API Key Here](https://platform.stability.ai/)",
"FIRECRAWL_API_KEY": "[Get Firecrawl API key Here](https://www.firecrawl.dev/account)"
"METAPHOR_API_KEY": "https://dashboard.exa.ai/login",
"TAVILY_API_KEY": "https://tavily.com/#api",
"SERPER_API_KEY": "https://serper.dev/signup",
"STABILITY_API_KEY": "https://platform.stability.ai/",
"FIRECRAWL_API_KEY": "https://www.firecrawl.dev/account"
}
missing_keys = []
for key, description in api_keys.items():
if os.getenv(key) is None:
missing_keys.append((key, description))
missing_keys = {
key: url for key, url in api_keys.items() if os.getenv(key) is None
}
if missing_keys:
st.error("🚨 Some API keys are missing! Please provide them below: 🚨")
new_keys = []
for key, description in missing_keys:
api_key = st.text_input(f"Enter 🔏 {key}: 👉{description}👈", placeholder=description, help=description)
st.error("🚨 Some API keys are missing! Please provide them below:")
for key, url in missing_keys.items():
api_key = st.text_input(f"Enter 🔏 {key}: 👉[Get it here]({url})👈")
if api_key:
new_keys.append((key, api_key))
if new_keys:
with open(".env", "a") as env_file:
for key, api_key in new_keys:
os.environ[key] = api_key
with open(".env", "a") as env_file:
env_file.write(f"{key}={api_key}\n")
os.environ[key] = api_key
st.success(f"{key} added successfully! Press Enter to continue.")
st.success(f"{key} added successfully!")
return False
return True
# Function to check LLM provider and API key
def check_llm_environs():
"""
Ensures that the LLM provider and corresponding API key are set.
Prompts the user to select a provider and enter the API key if missing.
"""
gpt_provider = os.getenv("GPT_PROVIDER")
supported_providers = ['google', 'openai', 'mistralai']
supported_providers = {
'google': "GEMINI_API_KEY",
'openai': "OPENAI_API_KEY",
'mistralai': "MISTRAL_API_KEY"
}
if gpt_provider is None or gpt_provider.lower() not in map(str.lower, supported_providers):
if not gpt_provider or gpt_provider.lower() not in supported_providers:
gpt_provider = st.selectbox(
"Select your LLM Provider",
options=["google", "openai", "mistralai"],
help="Select from 'google', 'openai', 'mistralai'"
"Select your LLM Provider", options=list(supported_providers.keys())
)
os.environ["GPT_PROVIDER"] = gpt_provider
with open(".env", "a") as env_file:
env_file.write(f"GPT_PROVIDER={gpt_provider}\n")
st.success(f"GPT Provider set to {gpt_provider}")
api_key_var = ""
if gpt_provider.lower() == "google":
api_key_var = "GEMINI_API_KEY"
missing_api_msg = "To get your Gemini API key, please visit: https://aistudio.google.com/app/apikey"
elif gpt_provider.lower() == "openai":
api_key_var = "OPENAI_API_KEY"
missing_api_msg = "To get your OpenAI API key, please visit: https://openai.com/blog/openai-api"
elif gpt_provider.lower() == "mistralai":
api_key_var = "MISTRAL_API_KEY"
missing_api_msg = "To get your MistralAI API key, please visit: https://mistralai.com/api"
if os.getenv(api_key_var) is None:
api_key = st.text_input(f"Enter {api_key_var}:", placeholder=missing_api_msg, help=missing_api_msg)
api_key_var = supported_providers[gpt_provider.lower()]
if not os.getenv(api_key_var):
api_key = st.text_input(f"Enter {api_key_var}:")
if api_key:
os.environ[api_key_var] = api_key
with open(".env", "a") as env_file:
env_file.write(f"{api_key_var}={api_key}\n")
os.environ[api_key_var] = api_key
st.success(f"{api_key_var} added successfully! Enter to continue..")
st.success(f"{api_key_var} added successfully!")
return False
return True
# Function to save configuration to a file
def save_config(config):
with open(os.getenv("ALWRITY_CONFIG"), "w") as config_file:
json.dump(config, config_file, indent=4)
"""
Saves the provided configuration dictionary to a JSON file specified by the environment variable.
"""
try:
with open(os.getenv("ALWRITY_CONFIG"), "w") as config_file:
json.dump(config, config_file, indent=4)
except Exception as e:
st.error(f"An error occurred while saving the configuration: {e}")
# Sidebar configuration
@@ -325,13 +320,9 @@ def main():
os.environ["ALWRITY_CONFIG"] = os.path.join(os.getcwd(), "lib", "workspace", "alwrity_config", "main_config.json")
# Check API keys and LLM environment settings
api_keys_valid = check_api_keys()
llm_environs_valid = check_llm_environs()
if api_keys_valid and llm_environs_valid:
# Clear previous messages and display the sidebar configuration
sidebar_configuration()
sidebar_configuration()
if check_api_keys() and check_llm_environs():
# Define the tabs
tab1, tab2, tab3, tab4, tab5, tab6 = st.tabs(
["AI Writers", "Content Planning", "Agents Teams", "AI SEO tools", "AI Social Tools", "Ask Alwrity"])
@@ -441,7 +432,6 @@ def alwrity_brain():
st.warning("Please enter a valid folder path.")
if __name__ == "__main__":
main()

119
lib/ai_seo_tools/README.md Normal file
View File

@@ -0,0 +1,119 @@
### Boost Your SEO Strategy with Alwrity's Advanced AI Tools
A lot of On-page SEO tools are present for now. We are integrating APIs for Analytics which will better the content quality & hence SEO.
Website audit, rank tracking, SEO suggestions, keyword research, link building and concepts EEAT will all be incorporated.
Checkout the TBD file in this directory for future enhancements.
Here's an in-depth look at how each of these tools can enhance your SEO efforts:
---
### 1. **SEO Analyzer** WIP
---
### 2. **Meta Description Generator**
**File:** `meta_desc_generator.py`
Meta descriptions play a crucial role in attracting clicks from search engine results pages (SERPs). Alwrity's Meta Description Generator crafts compelling, keyword-optimized meta descriptions tailored to your content. This tool ensures that your meta descriptions not only reflect the essence of your content but also entice users to click.
**Key Features:**
- Generates SEO-friendly meta descriptions
- Tailors descriptions to target keywords
- Enhances click-through rates (CTR) from SERPs
---
### 3. **Content Title Generator**
**File:** `content_title_generator.py`
Your content's title is the first impression you make on both search engines and users. The Content Title Generator by Alwrity creates attention-grabbing, keyword-optimized titles that resonate with your audience and improve your content's searchability.
**Key Features:**
- Generates optimized titles based on your keywords
- Ensures relevance and engagement
- Improves content visibility on search engines
---
### 4. **OpenGraph Generator**
**File:** `opengraph_generator.py`
OpenGraph tags are essential for social media optimization, allowing your content to be displayed beautifully when shared on platforms like Facebook and LinkedIn. The OpenGraph Generator ensures that your content is always presented in the best light, driving more traffic from social media channels.
**Key Features:**
- Automatically generates OpenGraph tags
- Optimizes content for social sharing
- Enhances visual appeal and clickability on social platforms
---
### 5. **Image Alt Text Generator**
**File:** `image_alt_text_generator.py`
Alt text is not just for accessibility; it's also a critical SEO factor that helps search engines understand the content of your images. The Image Alt Text Generator uses AI to create descriptive, keyword-rich alt texts that improve your image SEO.
**Key Features:**
- Generates SEO-friendly alt text for images
- Enhances image discoverability in search engines
- Improves website accessibility
---
### 6. **OpenGraph Image Generator**
**File:** `opengraph_image_generate.py`
A picture is worth a thousand words, especially on social media. The OpenGraph Image Generator creates custom images optimized for OpenGraph tags, ensuring that your content is visually appealing and engaging when shared across platforms.
**Key Features:**
- Generates custom images for OpenGraph tags
- Ensures optimal size and resolution for social media
- Enhances brand visibility and engagement
---
### 7. **SEO Analysis** WIP
---
### 8. **SEO Structured Data Generator**
**File:** `seo_structured_data.py`
Structured data is essential for modern SEO, enabling search engines to better understand your content and potentially display rich snippets. The SEO Structured Data Generator by Alwrity automates the creation of structured data, improving your chances of appearing in featured snippets.
**Key Features:**
- Automatically generates structured data
- Improves chances of rich snippet placement
- Enhances content discoverability
---
### 9. **Twitter Tags Generator**
**File:** `twitter_tags_generator.py`
Optimize your content for Twitter with Alwrity's Twitter Tags Generator. This tool creates the perfect set of tags to ensure your content gets noticed, shared, and engaged with on Twitter.
**Key Features:**
- Generates optimized Twitter tags
- Enhances content visibility on Twitter
- Increases engagement and shares
---
### Action Plan: How to Leverage Alwritys AI SEO Tools
1. **Audit Your Website:** Start with the SEO Analyzer to identify areas of improvement and optimize your on-page and technical SEO.
2. **Optimize Meta Descriptions and Titles:** Use the Meta Description Generator and Content Title Generator to craft compelling and search-friendly metadata.
3. **Enhance Social Media Presence:** Implement the OpenGraph Generator and OpenGraph Image Generator to ensure your content shines on social media platforms.
4. **Improve Image SEO:** Generate descriptive alt texts for all your images using the Image Alt Text Generator.
5. **Analyze and Refine:** Regularly use the SEO Analysis tool to monitor your progress and refine your strategies.
6. **Implement Structured Data:** Automate the creation of structured data with the SEO Structured Data Generator to boost your chances of appearing in rich snippets.
7. **Boost Twitter Engagement:** Optimize your Twitter content with the Twitter Tags Generator to increase visibility and engagement.
By integrating these AI-powered tools into your SEO strategy, you can drive significant organic growth, improve your search rankings, and stay ahead of the competition.

View File

@@ -5,3 +5,9 @@ https://developers.google.com/speed/docs/insights/v5/get-started
https://developers.google.com/search/apis/indexing-api/v3/prereqs
https://developer.chrome.com/docs/lighthouse/overview/#cli
APIs
https://docs.ayrshare.com/
https://github.com/dataforseo/PythonClient
https://mysiteauditor.com/api
https://github.com/searchsolved/search-solved-public-seo/blob/main/keyword-research/low-competition-keyword-finder-serp-api/low_competition_finder_serp_api.py

View File

@@ -0,0 +1,2 @@
ogImage TBD

View File

@@ -1,116 +0,0 @@
import streamlit as st
import openai
from bs4 import BeautifulSoup
import requests
import os
from ..ai_web_researcher.firecrawl_web_crawler import scrape_url
from ..gpt_providers.text_generation.main_text_generation import llm_text_gen
# Placeholder function for web scraping the URL (to be replaced with your mechanism)
def scrape_webpage(url):
try:
response = requests.get(url)
response.raise_for_status() # Raise an exception for bad status codes
soup = BeautifulSoup(response.content, 'html.parser')
# Extract the title
title = soup.find('title').text.strip() if soup.find('title') else None
# Extract the description
description = soup.find('meta', attrs={'name': 'description'})['content'] if soup.find('meta', attrs={'name': 'description'}) else None
# Extract the image URL
image_url = soup.find('meta', attrs={'property': 'og:image'})['content'] if soup.find('meta', attrs={'property': 'og:image'}) else None
return title, description, image_url
except requests.exceptions.RequestException as e:
st.error(f"An error occurred while scraping the webpage: {e}")
return None, None, None
# Function to generate OpenGraph meta tags
def generate_opengraph_meta_tags(url, html_content=None, title=None, description=None, image_url=None):
ai_prompt = f"""
Generate OpenGraph meta tags for a Twitter Card for the following webpage: {url}
Here is the HTML content of the page:
```html
{html_content}
```
Optional Customizations:
* Title: {title if title else "Infer from the page content"}
* Description: {description if description else "Infer from the page content"}
* Image URL: {image_url if image_url else "Infer from the page content"}
Best practices:
- Title: Should be concise and informative.
- Description: Provide a brief summary of the content.
- Image URL: Use a high-quality image.
- URL: Ensure the URL is correct.
- Type: Specify the content type (e.g., article, website).
- Site Name: Provide the name of the site.
Output the generated OpenGraph meta tags as a series of HTML meta tags in the following format:
<meta property="og:title" content="Extracted or provided title" />
<meta property="og:description" content="Extracted or provided description" />
<meta property="og:image" content="Extracted or provided image URL" />
<meta property="og:url" content="{url}" />
<meta property="og:type" content="Infer from the URL" />
<meta property="og:site_name" content="Extract site name from the URL" />
"""
response = openai.Completion.create(
engine="text-davinci-003",
prompt=ai_prompt,
max_tokens=150
)
return response.choices[0].text.strip()
# Function to display the Streamlit UI
def display_ui():
st.title('OpenGraph Meta Tags Generator for Twitter 🐦')
st.write('Generate OpenGraph meta tags for Twitter cards with ease. Just provide a URL and let our tool do the rest!')
# User inputs
url = st.text_input('Content URL', help="🔗 Paste the URL of the page you want to share on Twitter.", placeholder="e.g., https://example.com")
title = st.text_input('Title (optional)', help="📝 Optionally, provide a custom title for your Twitter card.", placeholder="e.g., Amazing Blog Post")
description = st.text_area('Description (optional)', help="✍️ Optionally, provide a custom description for your Twitter card.", placeholder="e.g., This blog post covers...")
image_url = st.text_input('Image URL (optional)', help="📸 Optionally, provide a URL to an image for your Twitter card.", placeholder="e.g., https://example.com/image.jpg")
if st.button('Generate Meta Tags'):
if url:
# Scrape the webpage for missing information if not provided
if not title or not description or not image_url:
scraped_title, scraped_description, scraped_image_url = scrape_webpage(url)
title = title or scraped_title
description = description or scraped_description
image_url = image_url or scraped_image_url
# Fetch HTML content
html_content = requests.get(url).text
# Generate OpenGraph meta tags
meta_tags = generate_opengraph_meta_tags(url, html_content=html_content, title=title, description=description, image_url=image_url)
st.subheader('Generated OpenGraph Meta Tags')
st.code(meta_tags, language='html')
else:
st.error('Please provide a content URL.')
# Instructions and preview
st.write('### Instructions')
st.write('1. Enter the URL of the content you want to share on Twitter.')
st.write('2. Optionally, provide a custom title, description, and image URL.')
st.write('3. Click "Generate Meta Tags" to see the generated OpenGraph meta tags.')
st.write('### Preview')
st.write('A preview of how the Twitter card will look with the generated meta tags will be shown here (Feature to be implemented).')
# Run the Streamlit UI
if __name__ == '__main__':
display_ui()

View File

@@ -0,0 +1,98 @@
import streamlit as st
import openai
import os
from bs4 import BeautifulSoup
import requests
from ..gpt_providers.text_generation.main_text_generation import llm_text_gen
def scrape_url_content(url):
"""
Scrapes the content from the provided URL.
Args:
url (str): The URL to scrape content from.
Returns:
str: The extracted text content from the webpage.
"""
# FIXME: Use firecrawl metadata option for this.
try:
response = requests.get(url)
response.raise_for_status()
soup = BeautifulSoup(response.content, 'html.parser')
text = ' '.join([p.text for p in soup.find_all('p')])
return text
except requests.exceptions.RequestException as e:
st.error(f"Error fetching the URL content: {e}")
return ""
except Exception as e:
st.error(f"Error parsing the HTML content: {e}")
return ""
def generate_twitter_tags(topic, scraped_content=""):
"""
Generates a list of relevant Twitter hashtags based on the topic and optional scraped content.
Args:
topic (str): The main topic or key phrase.
scraped_content (str): Optional scraped content to add more context.
Returns:
str: A list of Twitter hashtags as a string.
"""
prompt = f"Generate a list of highly relevant and trending Twitter hashtags based on the topic '{topic}'"
if scraped_content:
prompt += f" and the following content: {scraped_content[:700]}..." # Limit content to keep prompt manageable.
prompt += " Make sure the hashtags are popular and relevant to the topic. Follow Latest best practices for twitter tags."
try:
response = llm_text_gen(prompt)
return response
except Exception as err:
st.error(f"Failed to generate Open Graph tags: {err}")
return None
def display_app():
"""
Displays the Streamlit app UI and handles user interactions.
"""
st.title("AI Twitter Tag Generator")
st.write(
"Generate trending and highly relevant Twitter tags with minimal input. "
"Optionally, provide a URL to make the tags even more targeted."
)
# User Inputs
topic = st.text_input(
"Enter the topic or key phrase for Twitter tags",
placeholder="e.g., AI in marketing"
)
url = st.text_input(
"Optional: Enter a URL to scrape for more targeted tags",
placeholder="e.g., https://example.com/article"
)
if topic:
if url:
with st.spinner("Scraping content from the provided URL..."):
scraped_content = scrape_url_content(url)
if not scraped_content:
st.info("No content could be extracted from the provided URL.")
else:
scraped_content = ""
if st.button("Generate Twitter Tags"):
with st.spinner("Generating Twitter tags..."):
tags = generate_twitter_tags(topic, scraped_content)
if tags:
st.success("Twitter tags generated successfully!")
st.write(tags)
else:
st.info("Please enter a topic or key phrase to generate Twitter tags.")

View File

@@ -0,0 +1,2 @@
1). Replace Firecrawl with scrapy or crawlee : https://crawlee.dev/python/docs/introduction