Try Essay, story, Audio to Blog
This commit is contained in:
@@ -14,7 +14,7 @@ To start using this tool, simply follow one of the options below:
|
|||||||
|
|
||||||
---
|
---
|
||||||
### Option 1: FOLLOW-ME Local Laptop Install 💻 **(WINDOWS)**
|
### Option 1: FOLLOW-ME Local Laptop Install 💻 **(WINDOWS)**
|
||||||
|
|
||||||
#### Step 0 **Pre-requisites:** Git, Python3
|
#### Step 0 **Pre-requisites:** Git, Python3
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ To clone the repository to your local machine, perform the following steps:
|
|||||||
2. **Navigate to the Desired Directory:** Use the 'cd' command to move to the directory where you want to clone the repository.
|
2. **Navigate to the Desired Directory:** Use the 'cd' command to move to the directory where you want to clone the repository.
|
||||||
|
|
||||||
3. **Clone the Repository:** Run the following command in PowerShell to clone the repository:
|
3. **Clone the Repository:** Run the following command in PowerShell to clone the repository:
|
||||||
`git clone https://github.com/AJaySi/AI-Blog-Writer.git`
|
`git clone https://github.com/AJaySi/AI-Writer.git`
|
||||||
This command will download all the files from the repository to your local machine.
|
This command will download all the files from the repository to your local machine.
|
||||||
|
|
||||||
4. **Verify the Clone:** After the cloning process is complete, navigate into the newly created directory using:
|
4. **Verify the Clone:** After the cloning process is complete, navigate into the newly created directory using:
|
||||||
|
|||||||
36
alwrity.py
36
alwrity.py
@@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import configparser
|
import configparser
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
import typer
|
import typer
|
||||||
from prompt_toolkit.shortcuts import checkboxlist_dialog, message_dialog, input_dialog
|
from prompt_toolkit.shortcuts import checkboxlist_dialog, message_dialog, input_dialog
|
||||||
@@ -433,41 +434,35 @@ def do_web_research():
|
|||||||
|
|
||||||
def check_llm_environs():
|
def check_llm_environs():
|
||||||
""" Function to check which LLM api is given. """
|
""" Function to check which LLM api is given. """
|
||||||
# Check if GPT_PROVIDER is defined in .env file
|
|
||||||
gpt_provider = os.getenv("GPT_PROVIDER")
|
|
||||||
|
|
||||||
# Load .env file
|
# Load .env file
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
# Check if GPT_PROVIDER is defined in .env file
|
||||||
|
gpt_provider = os.getenv("GPT_PROVIDER")
|
||||||
|
|
||||||
# Disable unsupported GPT providers
|
# Disable unsupported GPT providers
|
||||||
supported_providers = ['google', 'openai', 'mistralai']
|
supported_providers = ['google', 'openai', 'mistralai']
|
||||||
if gpt_provider is None or gpt_provider.lower() not in supported_providers:
|
if gpt_provider is None or gpt_provider not in supported_providers:
|
||||||
#message_dialog(
|
|
||||||
# title="Unsupported GPT Provider",
|
|
||||||
# text="GPT_PROVIDER is not set or has an unsupported value."
|
|
||||||
#).run()
|
|
||||||
|
|
||||||
# Prompt user to select a provider
|
# Prompt user to select a provider
|
||||||
selected_provider = radiolist_dialog(
|
selected_provider = radiolist_dialog(
|
||||||
title='Select your preferred GPT provider:',
|
title='Select your preferred GPT provider:',
|
||||||
text="Please choose GPT provider Below:\n👺Google Gemini recommended, its 🆓.",
|
text="Please choose GPT provider Below:\n👺Google Gemini recommended, its 🆓.",
|
||||||
values=[
|
values=[
|
||||||
("Google", "google"),
|
("Google", "Google"),
|
||||||
("Openai", "openai"),
|
("OpenAI", "OpenAI"),
|
||||||
("MistralAI/WIP", "mistralai/WIP"),
|
("MistralAI/WIP", "mistralai/WIP"),
|
||||||
("Ollama", "Ollama (TBD)")
|
("Ollama", "Ollama (TBD)")
|
||||||
]
|
]
|
||||||
).run()
|
).run()
|
||||||
if selected_provider:
|
gpt_provider = selected_provider
|
||||||
gpt_provider = selected_provider
|
os.environ["GPT_PROVIDER"] = gpt_provider
|
||||||
|
|
||||||
if gpt_provider.lower() == "google":
|
if gpt_provider == "Google":
|
||||||
api_key_var = "GEMINI_API_KEY"
|
api_key_var = "GEMINI_API_KEY"
|
||||||
missing_api_msg = f"To get your {api_key_var}, please visit: https://aistudio.google.com/app/apikey"
|
missing_api_msg = f"To get your {api_key_var}, please visit: https://aistudio.google.com/app/apikey"
|
||||||
elif gpt_provider.lower() == "openai":
|
elif gpt_provider == "OpenAI":
|
||||||
api_key_var = "OPENAI_API_KEY"
|
api_key_var = "OPENAI_API_KEY"
|
||||||
missing_api_msg = "To get your OpenAI API key, please visit: https://openai.com/blog/openai-api"
|
missing_api_msg = "To get your OpenAI API key, please visit: https://openai.com/blog/openai-api"
|
||||||
elif gpt_provider.lower() == "mistralai":
|
elif gpt_provider == "mistralai":
|
||||||
api_key_var = "MISTRAL_API_KEY"
|
api_key_var = "MISTRAL_API_KEY"
|
||||||
missing_api_msg = "To get your MistralAI API key, please visit: https://mistralai.com/api"
|
missing_api_msg = "To get your MistralAI API key, please visit: https://mistralai.com/api"
|
||||||
|
|
||||||
@@ -475,13 +470,14 @@ def check_llm_environs():
|
|||||||
# Ask for the API key
|
# Ask for the API key
|
||||||
print(f"🚫The {api_key_var} is missing. {missing_api_msg}")
|
print(f"🚫The {api_key_var} is missing. {missing_api_msg}")
|
||||||
api_key = typer.prompt(f"\n🙆🙆Please enter {api_key_var} API Key:")
|
api_key = typer.prompt(f"\n🙆🙆Please enter {api_key_var} API Key:")
|
||||||
|
|
||||||
# Update .env file
|
# Update .env file
|
||||||
with open(".env", "a", encoding="utf-8") as env_file:
|
with open(".env", "a", encoding="utf-8") as env_file:
|
||||||
env_file.write(f"GPT_PROVIDER={gpt_provider.lower()}\n")
|
env_file.write(f"GPT_PROVIDER={gpt_provider}\n")
|
||||||
env_file.write(f"{api_key_var}={api_key}\n")
|
env_file.write(f"{api_key_var}={api_key}\n")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def check_internet():
|
def check_internet():
|
||||||
try:
|
try:
|
||||||
response = requests.get("http://www.google.com", timeout=20)
|
response = requests.get("http://www.google.com", timeout=20)
|
||||||
@@ -520,5 +516,7 @@ if __name__ == "__main__":
|
|||||||
check_search_apis()
|
check_search_apis()
|
||||||
print("Check LLM details & AI Model to use.")
|
print("Check LLM details & AI Model to use.")
|
||||||
check_llm_environs()
|
check_llm_environs()
|
||||||
|
os.environ["SEARCH_SAVE_FILE"] = os.path.join(os.getcwd(), "workspace",
|
||||||
|
"web_research_report" + "_" + datetime.now().strftime("%Y-%m-%d_%H-%M-%S"))
|
||||||
load_dotenv(Path('.env'))
|
load_dotenv(Path('.env'))
|
||||||
app()
|
app()
|
||||||
|
|||||||
@@ -45,10 +45,6 @@ logger.add(sys.stdout,
|
|||||||
def gpt_web_researcher(search_keywords):
|
def gpt_web_researcher(search_keywords):
|
||||||
""" Keyword based web researcher, basic, neural and Semantic search."""
|
""" Keyword based web researcher, basic, neural and Semantic search."""
|
||||||
|
|
||||||
# TBD: Keeping the results directory as fixed, for now.
|
|
||||||
os.environ["SEARCH_SAVE_FILE"] = os.path.join(os.getcwd(), "workspace",
|
|
||||||
search_keywords.replace(" ", "_") + "_" + datetime.now().strftime("%Y-%m-%d_%H-%M-%S"))
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
google_search_result = do_google_serp_search(search_keywords)
|
google_search_result = do_google_serp_search(search_keywords)
|
||||||
tavily_search_result = do_tavily_ai_search(search_keywords)
|
tavily_search_result = do_tavily_ai_search(search_keywords)
|
||||||
|
|||||||
@@ -30,9 +30,6 @@ def write_blog_from_keywords(search_keywords, url=None):
|
|||||||
This function will take a blog Topic to first generate sections for it
|
This function will take a blog Topic to first generate sections for it
|
||||||
and then generate content for each section.
|
and then generate content for each section.
|
||||||
"""
|
"""
|
||||||
# TBD: Keeping the results directory as fixed, for now.
|
|
||||||
os.environ["SEARCH_SAVE_FILE"] = os.path.join(os.getcwd(), "workspace", "web_research_reports",
|
|
||||||
search_keywords.replace(" ", "_") + "_" + datetime.now().strftime("%Y-%m-%d_%H-%M-%S"))
|
|
||||||
# Use to store the blog in a string, to save in a *.md file.
|
# Use to store the blog in a string, to save in a *.md file.
|
||||||
blog_markdown_str = ""
|
blog_markdown_str = ""
|
||||||
example_blog_titles = []
|
example_blog_titles = []
|
||||||
@@ -48,7 +45,6 @@ def write_blog_from_keywords(search_keywords, url=None):
|
|||||||
# logger.info/check the final blog content.
|
# logger.info/check the final blog content.
|
||||||
logger.info("\n######### Draft1: Finished Blog from Google web search: ###########\n\n")
|
logger.info("\n######### Draft1: Finished Blog from Google web search: ###########\n\n")
|
||||||
|
|
||||||
|
|
||||||
# Do Tavily AI research to augument the above blog.
|
# Do Tavily AI research to augument the above blog.
|
||||||
try:
|
try:
|
||||||
tavily_search_result, t_titles = do_tavily_ai_search(search_keywords)
|
tavily_search_result, t_titles = do_tavily_ai_search(search_keywords)
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ def youtube_to_blog(video_url):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
# Summarizing the content of the YouTube video
|
# Summarizing the content of the YouTube video
|
||||||
audio_blog_content = summarize_youtube_video(audio_text, "gemini")
|
audio_blog_content = summarize_youtube_video(audio_text)
|
||||||
logger.info("Successfully converted given URL to blog article.")
|
logger.info("Successfully converted given URL to blog article.")
|
||||||
return audio_blog_content, audio_title
|
return audio_blog_content, audio_title
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -44,7 +44,7 @@ def youtube_to_blog(video_url):
|
|||||||
sys.exit(1) # Exit the program due to error in summarize_youtube_video
|
sys.exit(1) # Exit the program due to error in summarize_youtube_video
|
||||||
|
|
||||||
|
|
||||||
def summarize_youtube_video(user_content, gpt_providers):
|
def summarize_youtube_video(user_content):
|
||||||
"""Generates a summary of a YouTube video using OpenAI GPT-3 and displays a progress bar.
|
"""Generates a summary of a YouTube video using OpenAI GPT-3 and displays a progress bar.
|
||||||
Args:
|
Args:
|
||||||
video_link: The URL of the YouTube video to summarize.
|
video_link: The URL of the YouTube video to summarize.
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ def llm_text_gen(prompt):
|
|||||||
# Check if API key is provided for the given gpt_provider
|
# Check if API key is provided for the given gpt_provider
|
||||||
get_api_key(gpt_provider)
|
get_api_key(gpt_provider)
|
||||||
|
|
||||||
logger.info(f"Temp: {temperature}, MaxTokens: {max_tokens}, TopP: {top_p}, N: {n}, FrequencyPenalty: {fp}")
|
|
||||||
# Perform text generation using the specified LLM parameters and prompt
|
# Perform text generation using the specified LLM parameters and prompt
|
||||||
if 'google' in gpt_provider.lower():
|
if 'google' in gpt_provider.lower():
|
||||||
try:
|
try:
|
||||||
@@ -69,9 +68,8 @@ def check_gpt_provider(gpt_provider):
|
|||||||
ValueError: If both the specified GPT provider and environment variable GPT_PROVIDER are missing.
|
ValueError: If both the specified GPT provider and environment variable GPT_PROVIDER are missing.
|
||||||
"""
|
"""
|
||||||
env_gpt_provider = os.getenv('GPT_PROVIDER')
|
env_gpt_provider = os.getenv('GPT_PROVIDER')
|
||||||
if gpt_provider and gpt_provider != env_gpt_provider:
|
if gpt_provider and gpt_provider.lower() != env_gpt_provider.lower():
|
||||||
logger.warning(f"Config: '{gpt_provider}' different to environment variable 'GPT_PROVIDER' '{env_gpt_provider}'")
|
logger.warning(f"Config: '{gpt_provider}' different to environment variable 'GPT_PROVIDER' '{env_gpt_provider}'")
|
||||||
logger.info(f"Using Environment GPT provider: {env_gpt_provider}")
|
|
||||||
gpt_provider = env_gpt_provider
|
gpt_provider = env_gpt_provider
|
||||||
|
|
||||||
return gpt_provider
|
return gpt_provider
|
||||||
|
|||||||
@@ -24,3 +24,4 @@ nltk
|
|||||||
prompt_toolkit
|
prompt_toolkit
|
||||||
ipython
|
ipython
|
||||||
html2image
|
html2image
|
||||||
|
lxml_html_clean
|
||||||
|
|||||||
Reference in New Issue
Block a user