import os from datetime import datetime from dotenv import load_dotenv import streamlit as st # Load .env file load_dotenv() from lib.utils.alwrity_streamlit_utils import ( blog_from_keyword, ai_agents_team, blog_from_audio, write_story, essay_writer, ai_news_writer, ai_finance_ta_writer, ai_social_writer ) # Custom CSS for styling st.markdown( """ """, unsafe_allow_html=True ) # Function to check if API keys are present and prompt user to input if not def check_api_keys(): api_keys = { "METAPHOR_API_KEY": "Metaphor AI Key (Get it here: https://dashboard.exa.ai/login)", "TAVILY_API_KEY": "Tavily AI Key (Get it here: https://tavily.com/#api)", "SERPER_API_KEY": "Serper API Key (Get it here: https://serper.dev/signup)" } missing_keys = [] for key, description in api_keys.items(): if os.getenv(key) is None: missing_keys.append((key, description)) if missing_keys: st.warning(f"API keys are missing. Please provide them below:{missing_keys}") for key, description in missing_keys: api_key = st.text_input(f"Enter {key}:", placeholder=description, help=description) if 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! Enter to Continue..") return False return True # Function to check LLM provider and API key def check_llm_environs(): gpt_provider = os.getenv("GPT_PROVIDER") supported_providers = ['google', 'openai', 'mistralai'] if gpt_provider is None or gpt_provider.lower() not in map(str.lower, supported_providers): gpt_provider = st.selectbox( "Select your LLM Provider", options=["google", "openai", "mistralai"], help="Select from 'google', 'openai', 'mistralai'" ) 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) if 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..") return False return True # Sidebar configuration def sidebar_configuration(): st.sidebar.title("🛠️ Alwrity Configuration 🏗️") with st.sidebar.expander("👷 Blog Content Characteristics"): st.text_input("**Blog Length**", value="2000", help="Length of blogs Or word count. Note: It won't be exact and depends on GPT providers and Max token count.") st.text_input("**Blog Tone**", value="Casual", help="Professional, how-to, beginner, research, programming, casual, etc.") st.text_input("Blog Demographic", value="Content creators & Digital marketing", help="Target Audience, Gen-Z, Tech-savvy, Working professional, students, kids, etc.") st.text_input("Blog Type", value="Informational", help="Informational, commercial, company, news, finance, competitor, programming, scholar, etc.") st.text_input("Blog Language", value="English", help="Spanish, German, Chinese, Arabic, Nepali, Hindi, Hindustani, etc.") st.text_input("Blog Output Format", value="markdown", help="Specify the output format of the blog as: HTML, markdown, plaintext. Defaults to markdown.") with st.sidebar.expander("🩻 Blog Images Details"): st.text_input("Image Generation Model", value="stable-diffusion", help="Options are dalle2, dalle3, stable-diffusion.") st.number_input("Number of Blog Images", value=1, help="Number of blog images to include.") with st.sidebar.expander("🤖 LLM Options"): st.text_input("GPT Provider", value="google", help="Choose one of the following: Openai, Google, Minstral.") st.text_input("Model", value="gemini-1.5-flash-latest", help="Mention which model of the above provider to use.") st.number_input("Temperature", value=0.7, help="""Temperature controls the 'creativity' or randomness of the text generated by GPT. Greater determinism with higher values indicating more randomness.""") st.number_input("Top-p", value=0.9, help="Top-p sampling controls the level of diversity in the generated text.") st.number_input("Max Tokens", value=4096, help="Max tokens determine the maximum length of the output sequence generated by a model.") st.number_input("N", value=1, help="Defines the number of words or characters grouped together in a sequence when analyzing text.") st.number_input("Frequency Penalty", value=1, help="Influences word selection during text generation, promoting diversity with higher values.") st.number_input("Presence Penalty", value=1, help="Encourages the use of diverse words by discouraging repetition.") with st.sidebar.expander("🕵️ Search Engine Parameters"): st.text_input("Geographic Location", value="us", help="Geo location restricts the web search to a given country. Examples are us for United States, in for India, fr for France, cn for China, etc.") st.text_input("Search Language", value="en", help="Define the language you want search results in. Example: en for English, zn-cn for Chinese, de for German, hi for Hindi, etc.") st.number_input("Number of Results", value=10, help="Number of Google search results to fetch.") st.text_input("Time Range", value="anytime", help="Acceptable values: past day, past week, past month, past year. Limits the search results for a given time duration from today.") st.text_input("Include Domains", value="", help="A list of domains to specifically include in the search results. Default is None, which includes all domains.") st.text_input("Similar URL", value="", help="A single URL that instructs search engines to give results similar to the given URL.") # Function to read prompts from the file def read_prompts(file_path="prompt_llm.txt"): if os.path.exists(file_path): with open(file_path, "r") as file: prompts = file.readlines() return [prompt.strip() for prompt in prompts] return [] # Function to write prompts to the file def write_prompts(prompts, file_path="prompt_llm.txt"): with open(file_path, "w") as file: for prompt in prompts: file.write(f"{prompt}\n") def main(): st.markdown("