From 822c2b9c77e3a953a088dc42dd44e357f12c3144 Mon Sep 17 00:00:00 2001 From: DavdaJames Date: Thu, 10 Oct 2024 22:32:45 +0530 Subject: [PATCH 1/3] some changes in other folder to solve merge conflicts --- video_cropper/video_cropper.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/video_cropper/video_cropper.py b/video_cropper/video_cropper.py index 65ce2ab95..e4237cf0e 100644 --- a/video_cropper/video_cropper.py +++ b/video_cropper/video_cropper.py @@ -11,8 +11,7 @@ def to_int(a, rel_to): If string contains "%" it converts it to a float and multiplies by rel_to EG: 50% -> 0.5*rel_to ''' - - if isinstance(a,int): + if isinstance(a, int): return a else: if '%' in a: From fd634a99ece27f48f0c47e7a6a95d0cff1d95147 Mon Sep 17 00:00:00 2001 From: DavdaJames Date: Sun, 13 Oct 2024 04:01:25 +0530 Subject: [PATCH 2/3] bot created for interaction with gemini --- aibot/.gitignore | 84 ++++++++++++++++++++++++++++++++++++++++++ aibot/AIbot.py | 56 ++++++++++++++++++++++++++++ aibot/README.md | 67 +++++++++++++++++++++++++++++++++ aibot/requirements.txt | 2 + 4 files changed, 209 insertions(+) create mode 100644 aibot/.gitignore create mode 100644 aibot/AIbot.py create mode 100644 aibot/README.md create mode 100644 aibot/requirements.txt diff --git a/aibot/.gitignore b/aibot/.gitignore new file mode 100644 index 000000000..edeb0e21f --- /dev/null +++ b/aibot/.gitignore @@ -0,0 +1,84 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# Virtual environments +venv/ +ENV/ +env/ +.venv/ +.ENV/ + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ +test-results/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# dotenv +.env +.env.* + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# pyright +pyrightconfig.json + +# VS Code settings (optional, but commonly used) +.vscode/ + +# Logs +*.log + +# Local development logs +*.log.* diff --git a/aibot/AIbot.py b/aibot/AIbot.py new file mode 100644 index 000000000..1691be5e1 --- /dev/null +++ b/aibot/AIbot.py @@ -0,0 +1,56 @@ +import os +import google.generativeai as genai +import dotenv + +# Load environment variables from .env file +dotenv.load_dotenv() + +# Configure the API key for the Gemini model +api_key = os.environ.get("GEMINI_API_KEY") +if not api_key: + raise ValueError("API key not found! Ensure GEMINI_API_KEY is set in the environment variables.") + +genai.configure(api_key=api_key) + +# Initialize the Generative Model +model = genai.GenerativeModel("gemini-1.5-flash") + +def generate_response(user_input): + """ + This function interacts with the Gemini model to generate creative and intelligent responses. + + :param user_input: The user's input to the chatbot. + :return: A response generated by the AI. + """ + try: + # Generate content based on the user input + response = model.generate_content(user_input) + return response.text if response else "Sorry, I couldn't generate a response." + except Exception as e: + return f"An error occurred: {e}" + +def chatbot(): + """ + Main function to handle continuous interaction with the chatbot. + It allows the user to ask anything from blog posts to code explanations. + """ + print("πŸš€ Welcome to the most amazing AI Bot! 🌟") + print("πŸ’¬ You can ask me anything from writing blog posts, to explaining code, to creative writing.\n") + print("✨ Just type 'exit' anytime to quit.\n") + + while True: + # Get user input + user_input = input("You: ") + + # Check for exit condition + if user_input.lower() == "exit": + print("πŸ‘‹ Goodbye! Thanks for chatting!") + break + + # Generate and print AI response + ai_response = generate_response(user_input) + print(f"AI Bot: {ai_response}\n") + +if __name__ == "__main__": + # Run the chatbot + chatbot() diff --git a/aibot/README.md b/aibot/README.md new file mode 100644 index 000000000..369a8cd86 --- /dev/null +++ b/aibot/README.md @@ -0,0 +1,67 @@ +# AI Bot using Google Generative AI + +This AI bot is designed to perform a wide range of tasks, such as writing blog posts, explaining code, or creating creative stories. It uses **Google's Gemini API** via the `google-generativeai` package to generate intelligent and creative responses to user queries. With a simple and secure setup, this bot makes interacting with AI effortless and enjoyable. + +## Key Features + +- **Versatile AI Responses**: From blog writing to coding explanations, the bot can tackle diverse tasks. +- **Seamless API Integration**: Integrates with **Google's Gemini model (gemini-1.5-flash)** for content generation. +- **Secure Key Management**: Uses `python-dotenv` to handle sensitive API keys securely. +- **User-Friendly**: Easy to set up and use. Just run the bot and start interacting! + +## Setup Instructions + +Follow these steps to set up and run the AI Bot on your local machine. + +### Step 1: Clone the Repository +If the code is hosted in a repository, clone it using the command: +```bash +git clone https://github.com/your-repo-name/ai-bot.git +cd ai-bot +``` +### Step 1: Install dependencies required for this script to run +``` +pip install -r requirements.txt +``` + +### Step 3: Setting Gemini API keys +## For linux/mac users +``` +touch .env +echo "GEMINI_API_KEY=your-gemini-api-key-here" >> .env +``` +## For Windows users +``` +new-item .env +echo GEMINI_API_KEY=your-gemini-api-key-here > .env +``` +### Step 4: Running the script +``` +python AIbot.py +``` + +## Enjoy talk with chat and have fun +### Script Explanation +Here’s a breakdown of what the script does: + +Environment Configuration: The script loads the GEMINI_API_KEY from the .env file using dotenv to securely access your API key. + +Google Generative AI Configuration: It sets up the google-generativeai library to interface with the Gemini model. + +User Interaction: The script continuously prompts the user for input. Users can ask anything from writing tasks (e.g., generating blog posts) to technical queries (e.g., explaining code). + +Generating Responses: Based on the user’s input, the bot generates relevant and creative responses using the *Gemini 1.5 Flash model*. + +## Disclaimer + +- **API Limitations**: This AI bot relies on the Google Generative AI (Gemini) API. Users should be aware of the API's rate limits and usage policies, as excessive requests may result in temporary suspension of access. + +- **Content Accuracy**: The responses generated by the AI bot are based on patterns learned from training data. While the bot aims to provide accurate and relevant information, it may occasionally produce incorrect or misleading content. Users should verify information before relying on it for critical tasks. + +- **No Legal or Medical Advice**: The AI bot is not a substitute for professional advice. Users should not rely on the information provided by the bot for legal, medical, or financial decisions. + +- **User Responsibility**: By using this bot, users agree to take full responsibility for their interactions with the AI and the content generated. The developers are not liable for any consequences resulting from the use of this bot. + +- **Ethical Use**: Users are encouraged to use the bot ethically and responsibly. Avoid using it to generate harmful, misleading, or abusive content. + +- **Privacy Considerations**: Any information shared with the bot during interactions may be processed according to Google's data privacy policies. Users should avoid sharing personal or sensitive information. diff --git a/aibot/requirements.txt b/aibot/requirements.txt new file mode 100644 index 000000000..050f7b1aa --- /dev/null +++ b/aibot/requirements.txt @@ -0,0 +1,2 @@ +google-generativeai==0.8.3 +python-dotenv==1.0.1 From 3bc2658ae5c5d1aa8099c381fb5f74de00c02398 Mon Sep 17 00:00:00 2001 From: DavdaJames Date: Sun, 13 Oct 2024 04:12:11 +0530 Subject: [PATCH 3/3] linted with black and checked with flake8 --- aibot/AIbot.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/aibot/AIbot.py b/aibot/AIbot.py index 1691be5e1..913e436e0 100644 --- a/aibot/AIbot.py +++ b/aibot/AIbot.py @@ -8,40 +8,52 @@ # Configure the API key for the Gemini model api_key = os.environ.get("GEMINI_API_KEY") if not api_key: - raise ValueError("API key not found! Ensure GEMINI_API_KEY is set in the environment variables.") + raise ValueError( + "API key not found! Ensure GEMINI_API_KEY is " + "set in the environment variables." + ) genai.configure(api_key=api_key) # Initialize the Generative Model model = genai.GenerativeModel("gemini-1.5-flash") + def generate_response(user_input): """ - This function interacts with the Gemini model to generate creative and intelligent responses. - + This function interacts with the Gemini model + to generate creative and intelligent responses. + :param user_input: The user's input to the chatbot. :return: A response generated by the AI. """ try: - # Generate content based on the user input response = model.generate_content(user_input) - return response.text if response else "Sorry, I couldn't generate a response." + return ( + response.text + if response + else "Sorry, I couldn't generate a response." + ) except Exception as e: return f"An error occurred: {e}" + def chatbot(): """ Main function to handle continuous interaction with the chatbot. It allows the user to ask anything from blog posts to code explanations. """ print("πŸš€ Welcome to the most amazing AI Bot! 🌟") - print("πŸ’¬ You can ask me anything from writing blog posts, to explaining code, to creative writing.\n") + print( + "πŸ’¬ You can ask me anything from writing blog posts, " + "to explaining code, to creative writing.\n" + ) print("✨ Just type 'exit' anytime to quit.\n") while True: # Get user input user_input = input("You: ") - + # Check for exit condition if user_input.lower() == "exit": print("πŸ‘‹ Goodbye! Thanks for chatting!") @@ -51,6 +63,7 @@ def chatbot(): ai_response = generate_response(user_input) print(f"AI Bot: {ai_response}\n") + if __name__ == "__main__": # Run the chatbot chatbot()