diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d06f2c --- /dev/null +++ b/.gitignore @@ -0,0 +1,21 @@ +# Python artifacts +__pycache__/ +*.py[cod] +*.egg-info/ + +# Environments +venv/ +.venv/ +ENV/ +env/ + +# dotenv files +*.env + +# Output files +*.docx +*.html + +# Node +node_modules/ + diff --git a/README.md b/README.md index 48f235a..519baf3 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,15 @@ This repository contains small Python utilities for interacting with AI models. All scripts are located in the `scripts/` directory. +## Setup + +Create the conda environment and install the required Python packages: + +```bash +conda env create -f environment.yml +conda activate myscripts +``` + ## Available Scripts - **claude_call.py** – Query Anthropic's Claude model and save results to a DOCX @@ -14,3 +23,7 @@ All scripts are located in the `scripts/` directory. outputs. See [scripts/README.md](scripts/README.md) for more details on each script. + +The repository also includes a simple monitoring demo located in +`monitoring-app/`. Consult its README for instructions on running the FastAPI +backend and React frontend. diff --git a/environment.yml b/environment.yml new file mode 100644 index 0000000..7ac7c1c --- /dev/null +++ b/environment.yml @@ -0,0 +1,22 @@ +name: myscripts +channels: + - conda-forge +dependencies: + - python=3.10 + - pip + - pip: + - python-docx + - markdown2 + - tqdm + - anthropic + - groq + - faster-whisper + - ollama + - langchain-community + - psutil + - pyjwt + - requests + - fastapi + - uvicorn + - websockets + - python-dotenv diff --git a/monitoring-app/README.md b/monitoring-app/README.md index 713063c..3e33966 100644 --- a/monitoring-app/README.md +++ b/monitoring-app/README.md @@ -12,13 +12,12 @@ This project provides a minimal FastAPI backend and React-based frontend for rea ### Running -Install dependencies and start: +Create the conda environment from the repository root and start the server: ```bash +conda env create -f ../../environment.yml # run once +conda activate myscripts cd backend -python3 -m venv venv -. venv/bin/activate -pip install -r requirements.txt uvicorn main:app --reload ``` @@ -28,7 +27,8 @@ uvicorn main:app --reload ## Security Notes -- Change `SECRET_KEY`, `ADMIN_USER`, and `ADMIN_PASS` in `.env`. +- Copy `backend/.env.example` to `backend/.env` and change `SECRET_KEY`, + `ADMIN_USER`, and `ADMIN_PASS`. - Use HTTPS termination in production. This is a starting point for a full-featured monitoring solution. diff --git a/monitoring-app/backend/.env b/monitoring-app/backend/.env.example similarity index 100% rename from monitoring-app/backend/.env rename to monitoring-app/backend/.env.example diff --git a/scripts/README.md b/scripts/README.md index 06fe3af..dce137f 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -4,6 +4,12 @@ This directory contains small utility scripts for working with AI models. Each script is saved with a descriptive name and `.py` extension so they can be run using Python. +The API-based scripts expect the relevant keys to be provided as environment +variables: + +- `ANTHROPIC_API_KEY` for `claude_call.py` +- `GROQ_API_KEY` for the Groq examples + ## Scripts ### `claude_call.py` diff --git a/scripts/claude_call.py b/scripts/claude_call.py index b70b5c6..742d03c 100644 --- a/scripts/claude_call.py +++ b/scripts/claude_call.py @@ -18,7 +18,7 @@ def generate_messages(section: str) -> List[dict]: } ] -client: anthropic.Anthropic = anthropic.Anthropic(api_key=) +client: anthropic.Anthropic = anthropic.Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY", "")) print("Generating policy outline...") @@ -60,10 +60,10 @@ def generate_messages(section: str) -> List[dict]: word_document.add_paragraph("\n") html_sections.append(markdown(detailed_info)) -docx_file_path = "e.docx" +docx_file_path = "output.docx" with open(docx_file_path, "wb") as doc_file: word_document.save(doc_file) -html_file_path = ".html" +html_file_path = "output.html" with open(html_file_path, "w") as html_file: html_file.write("\n".join(html_sections)) diff --git a/scripts/groq_simple_chatbot.py b/scripts/groq_simple_chatbot.py index 24c05cd..7ab21d3 100644 --- a/scripts/groq_simple_chatbot.py +++ b/scripts/groq_simple_chatbot.py @@ -1,15 +1,15 @@ from groq import Groq +import os - -# Initialize the Groq API -client= Groq(api_key="") +# Initialize the Groq API using an environment variable +client = Groq(api_key=os.getenv("GROQ_API_KEY", "")) # Initialize the conversation list conversation = [ {"role": "system", "content": "You are a helpful assistant."}, ] -# Function to interact with GPT-3 +# Function to interact with the Groq model def chat_with_groq(prompt, conversation): model_engine = "mixtral-8x7b-32768" diff --git a/scripts/read_mp3_summary.py b/scripts/read_mp3_summary.py index 671c05f..0566ffd 100644 --- a/scripts/read_mp3_summary.py +++ b/scripts/read_mp3_summary.py @@ -1,19 +1,15 @@ from faster_whisper import WhisperModel from groq import Groq +import os -def open_file(filepath): - with open(filepath, 'r', encoding='utf-8') as infile: - return infile.read() - -API_KEY = open_file('groqapikey.txt') -client = Groq(api_key=API_KEY) +client = Groq(api_key=os.getenv("GROQ_API_KEY", "")) def transcribe_audio(audio_path, model_size="medium"): model = WhisperModel(model_size, device="cpu") segments, _ = model.transcribe(audio_path) return " ".join([segment.text for segment in segments]) -audio_file_path = "/path/to/your/mp3" # Replace with your audio file path +audio_file_path = os.getenv("AUDIO_FILE", "/path/to/your/mp3") transcribed_text = transcribe_audio(audio_file_path) with open("transcription.txt", "w") as file: file.write(transcribed_text)