Categories
Tools

Gradio Automatic Speech Recognition

pip install torch transformers torchaudio gradio
import gradio as gr
from transformers import pipeline
import numpy as np

transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-base.en")

def transcribe(audio):
    # Check if audio input exists
    if audio is None:
        return "Please record some audio"
        
    sr, y = audio
    
    # Convert to mono if stereo
    if y.ndim > 1:
        y = y.mean(axis=1)
        
    y = y.astype(np.float32)
    y /= np.max(np.abs(y))

    return transcriber({"sampling_rate": sr, "raw": y})["text"]  

demo = gr.Interface(
    transcribe,
    gr.Audio(sources="microphone", type="numpy"),  # Specify type as numpy
    "text",
)

demo.launch()

Realtime Streaming (not working)

import gradio as gr
from transformers import pipeline
import numpy as np

transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-base.en")

def transcribe(stream, new_chunk):
    if new_chunk is None:
        return None, ""
        
    sr, y = new_chunk
    
    # Convert to mono if stereo
    if y.ndim > 1:
        y = y.mean(axis=1)
        
    y = y.astype(np.float32)
    y /= np.max(np.abs(y)) + 1e-7  # Safe normalization

    # Initialize or update stream
    if stream is not None:
        stream = np.concatenate([stream, y])
    else:
        stream = y
        
    # Keep only last 5 seconds to prevent memory issues
    max_length = sr * 5
    if len(stream) > max_length:
        stream = stream[-max_length:]
        
    try:
        text = transcriber({"sampling_rate": sr, "raw": stream})["text"]
        return stream, text
    except Exception as e:
        print(f"Transcription error: {e}")
        return stream, ""

demo = gr.Interface(
    fn=transcribe,
    inputs=[
        "state",
        gr.Audio(sources=["microphone"], streaming=True, type="numpy")
    ],
    outputs=[
        "state",
        "text"
    ],
    live=True
)

if __name__ == "__main__":
    demo.queue().launch()
Categories
Tools

Omni Parser

Download model script

download.sh

#!/bin/bash

# Base URL for downloading model files
BASE_URL="https://huggingface.co/microsoft/OmniParser/resolve/main"

# Define folder structure and create folders
mkdir -p weights/icon_detect
mkdir -p weights/icon_caption_florence
mkdir -p weights/icon_caption_blip2

# Declare an associative array of required files with paths
declare -A model_files=(
  ["weights/icon_detect/model.safetensors"]="$BASE_URL/icon_detect/model.safetensors"
  ["weights/icon_detect/model.yaml"]="$BASE_URL/icon_detect/model.yaml"
  ["weights/icon_caption_florence/model.safetensors"]="$BASE_URL/icon_caption_florence/model.safetensors"
  ["weights/icon_caption_florence/config.json"]="$BASE_URL/icon_caption_florence/config.json"
  ["weights/icon_caption_blip2/model.safetensors"]="$BASE_URL/icon_caption_blip2/model.safetensors"
  ["weights/icon_caption_blip2/config.json"]="$BASE_URL/icon_caption_blip2/config.json"
)

# Download each file into its specified directory
for file_path in "${!model_files[@]}"; do
  wget -O "$file_path" "${model_files[$file_path]}"
done

echo "All required model and configuration files downloaded and organised."

# Run the conversion script if necessary files are present
if [ -f "weights/icon_detect/model.safetensors" ] && [ -f "weights/icon_detect/model.yaml" ]; then
  python weights/convert_safetensor_to_pt.py
  echo "Conversion to best.pt completed."
else
  echo "Error: Required files for conversion not found."
fi
bash download.sh

Python code

app.py

# 1. Import libraries

from utils import get_som_labeled_img, check_ocr_box, get_caption_model_processor, get_yolo_model
import torch
from ultralytics import YOLO
from PIL import Image
import base64
import matplotlib.pyplot as plt
import io
import json
from rich import print

# 2. Configuration

device = 'cuda'
som_model = get_yolo_model(model_path='weights/icon_detect/best.pt')
som_model.to(device)
print('model to {}'.format(device))
caption_model_processor = get_caption_model_processor(model_name="florence2", model_name_or_path="weights/icon_caption_florence", device=device)

image_path = 'imgs/windows_multitab.png'
image = Image.open(image_path)
image_rgb = image.convert('RGB')

draw_bbox_config = {
    'text_scale': 0.8,
    'text_thickness': 2,
    'text_padding': 3,
    'thickness': 3,
}
BOX_TRESHOLD = 0.03

# 3. Get labeled image and results
ocr_bbox_rslt, is_goal_filtered = check_ocr_box(
    image_path, 
    display_img=False, 
    output_bb_format='xyxy', 
    goal_filtering=None, 
    easyocr_args={'paragraph': False, 'text_threshold': 0.9}
)
text, ocr_bbox = ocr_bbox_rslt

dino_labeled_img, label_coordinates, parsed_content_list = get_som_labeled_img(
    image_path, 
    som_model, 
    BOX_TRESHOLD=BOX_TRESHOLD, 
    output_coord_in_ratio=False, 
    ocr_bbox=ocr_bbox, 
    draw_bbox_config=draw_bbox_config, 
    caption_model_processor=caption_model_processor, 
    ocr_text=text, 
    use_local_semantics=True, 
    iou_threshold=0.1
)

decoded_image = Image.open(io.BytesIO(base64.b64decode(dino_labeled_img)))
decoded_image.save("labeled_image_output.png")
print(parsed_content_list)
python app.py
Categories
Local Ollama

AI Agents Ollama n8n

npx n8n
brew install postgresql@14
ollama pull llama3.2
Categories
Tools

BitNet Installation Linux

# 1. System Updates and Dependencies
sudo apt-get update
sudo apt-get install -y build-essential
sudo apt-get install -y libstdc++-12-dev
sudo apt-get install -y clang llvm
sudo apt-get install -y libc++-dev libc++abi-dev
sudo apt-get install -y llvm-14 llvm-14-dev
sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"

# 2. Conda Environment Setup
conda create -n bitnet-cpp python=3.9 -y
conda activate bitnet-cpp

# 3. Clone Repository
git clone --recursive https://github.com/microsoft/BitNet.git
cd BitNet

# 4. Python Dependencies
pip install -r requirements.txt
pip install cmake

# 5. Download Model
huggingface-cli download HF1BitLLM/Llama3-8B-1.58-100B-tokens --local-dir models/Llama3-8B-1.58-100B-tokens

# 6. Run Setup
python setup_env.py -md models/Llama3-8B-1.58-100B-tokens -q i2_s

# 7. Run Inference
python run_inference.py -m models/Llama3-8B-1.58-100B-tokens/ggml-model-i2_s.gguf -p "Daniel went back to the the the garden. Mary travelled to the kitchen. Sandra journeyed to the kitchen. Sandra went to the hallway. John went to the bedroom. Mary went back to the garden. Where is Mary?\nAnswer:" -n 6 -temp 0
Categories
Ollama

n8n Setup Ollama – Expose to Public

Setup PostgreSQL

brew install postgresql@14
❯ psql -U postgres

psql (14.13 (Homebrew))
Type "help" for help.

postgres=# SHOW config_file;
                   config_file                   
-------------------------------------------------
 /opt/homebrew/var/postgresql@14/postgresql.conf

Edit /opt/homebrew/var/postgresql@14/postgresql.conf

code /opt/homebrew/var/postgresql@14/postgresql.conf

And add

listen_addresses = '*'

Edit /opt/homebrew/var/postgresql@14/pg_hba.conf

code /opt/homebrew/var/postgresql@14/pg_hba.conf

And add

host    all             all             0.0.0.0/0               md5

Ollama setup

brew install ollama
launchctl setenv OLLAMA_HOST 0.0.0.0:11434

Then restart Ollama

Categories
LLM

Anthropic Claude Computer Use

export ANTHROPIC_API_KEY=xxxxxxx
docker run \
    -e ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY \
    -v $HOME/.anthropic:/home/computeruse/.anthropic \
    -p 5900:5900 \
    -p 8501:8501 \
    -p 6080:6080 \
    -p 8080:8080 \
    -it ghcr.io/anthropics/anthropic-quickstarts:computer-use-demo-latest
Categories
AI Agents OpenAI

OpenAI Swarm 100% Local – Ollama LM Studio

Ollama

ollama pull llama3.2
export OPENAI_API_KEY=fake-key
export OPENAI_MODEL_NAME=llama3.2
export OPENAI_BASE_URL=http://localhost:11434/v1
pip install git+https://github.com/openai/swarm.git duckduckgo-search
from duckduckgo_search import DDGS
from swarm import Swarm, Agent
from datetime import datetime

current_date = datetime.now().strftime("%Y-%m")

# Initialize Swarm client
client = Swarm()

# 1. Create Internet Search Tool

def get_news_articles(topic):
    print(f"Running DuckDuckGo news search for {topic}...")
    
    # DuckDuckGo search
    ddg_api = DDGS()
    results = ddg_api.text(f"{topic} {current_date}", max_results=5)
    if results:
        news_results = "\n\n".join([f"Title: {result['title']}\nURL: {result['href']}\nDescription: {result['body']}" for result in results])
        return news_results
    else:
        return f"Could not find news results for {topic}."
    
# 2. Create AI Agents

# News Agent to fetch news
news_agent = Agent(
    name="News Assistant",
    instructions="You provide the latest news articles for a given topic using DuckDuckGo search.",
    functions=[get_news_articles],
    model="llama3.2"
)

# Editor Agent to edit news
editor_agent = Agent(
    name="Editor Assistant",
    instructions="Rewrite and give me as news article ready for publishing. Each News story in separate section.",
    model="llama3.2"
)

# 3. Create workflow

def run_news_workflow(topic):
    print("Running news Agent workflow...")
    
    # Step 1: Fetch news
    news_response = client.run(
        agent=news_agent,
        messages=[{"role": "user", "content": f"Get me the news about {topic} on {current_date}"}],
    )
    
    raw_news = news_response.messages[-1]["content"]
    
    # Step 2: Pass news to editor for final review
    edited_news_response = client.run(
        agent=editor_agent,
        messages=[{"role": "user", "content": raw_news }],
    )
    
    return edited_news_response.messages[-1]["content"]

# Example of running the news workflow for a given topic
print(run_news_workflow("AI"))

LM Studio

export OPENAI_BASE_URL=http://localhost:1234/v1
Categories
API

API Authentication: A Quick Guide

When integrating with APIs, handling authentication is a crucial step to ensure secure communication between clients and servers. Depending on the API provider, different types of authentication methods are supported. Here’s a breakdown of the common authentication types, their associated fields, and configuration options you may encounter when working with APIs.

1. OAuth Authentication:

OAuth is one of the most widely used authentication mechanisms, providing delegated access without sharing credentials directly. It allows users to grant limited access to their resources on one site to another site without exposing their credentials.

  • Fields:
  • Client ID
  • Client Secret
  • Authorization URL
  • Token URL
  • Scope
  • Token Exchange Method:
    • Default (POST request)
    • Basic Authorization Header

2. API Key Authentication:

API Key authentication is a simpler form of authentication that involves sending a secret key with each request. It is often used for server-to-server communication or in situations where OAuth is unnecessarily complex.

  • Fields:
  • API Key
  • Auth Type:
    • Basic
    • Bearer
    • Custom
    • Custom Header Name (e.g., X-Api-Key)

3. None (No Authentication):

In some cases, APIs do not require any authentication. While less secure, it may be suitable for public endpoints or internal systems.

  • Fields:
  • No additional fields

By understanding these options, you can select and configure the appropriate authentication method for your API integration, ensuring both security and ease of access.

Categories
Praison AI

Praison AI Call Dockerfile

# Use an official Python runtime as a parent image
FROM python:3.11-slim

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set work directory
WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    && rm -rf /var/lib/apt/lists/*

# Install PraisonAI with the 'call' extra and ensure it's the latest version
RUN pip install --no-cache-dir --upgrade "praisonai[call]"

# Expose the port the app runs on
EXPOSE 8090

# Run the application
CMD ["praisonai", "call"]
Categories
Testing

Country Calling ISO Code

Country NameCodeCountry Code
United StatesUS+1
AfghanistanAF+93
Åland IslandsAX+358
AlbaniaAL+355
AlgeriaDZ+213
American SamoaAS+1
AndorraAD+376
AngolaAO+244
AnguillaAI+1
Antigua & BarbudaAG+1
ArgentinaAR+54
ArmeniaAM+374
ArubaAW+297
AustraliaAU+61
AustriaAT+43
AzerbaijanAZ+994
BahamasBS+1
BahrainBH+973
BangladeshBD+880
BarbadosBB+1
BelarusBY+375
BelgiumBE+32
BelizeBZ+501
BeninBJ+229
BermudaBM+1
BhutanBT+975
BoliviaBO+591
Bosnia & HerzegovinaBA+387
BotswanaBW+267
BrazilBR+55
British Indian Ocean TerritoryIO+246
British Virgin IslandsVG+1
BruneiBN+673
BulgariaBG+359
Burkina FasoBF+226
BurundiBI+257
CambodiaKH+855
CameroonCM+237
CanadaCA+1
Cape VerdeCV+238
Cayman IslandsKY+1
Central African RepublicCF+236
ChadTD+235
ChileCL+56
ChinaCN+86
Christmas IslandCX+61
Cocos (Keeling) IslandsCC+61
ColombiaCO+57
ComorosKM+269
Cook IslandsCK+682
Costa RicaCR+506
CroatiaHR+385
CubaCU+53
CuraçaoCW+599
CyprusCY+357
CzechiaCZ+420
DR CongoCD+243
DenmarkDK+45
DjiboutiDJ+253
DominicaDM+1
Dominican RepublicDO+1
EcuadorEC+593
EgyptEG+20
El SalvadorSV+503
Equatorial GuineaGQ+240
EritreaER+291
EstoniaEE+372
EthiopiaET+251
Falkland IslandsFK+500
Faroe IslandsFO+298
FijiFJ+679
FinlandFI+358
FranceFR+33
French GuianaGF+594
French PolynesiaPF+689
GabonGA+241
GambiaGM+220
GeorgiaGE+995
GermanyDE+49
GhanaGH+233
GibraltarGI+350
GreeceGR+30
GreenlandGL+299
GrenadaGD+1
GuadeloupeGP+590
GuamGU+1
GuatemalaGT+502
GuernseyGG+44
GuineaGN+224
Guinea-BissauGW+245
GuyanaGY+592
HaitiHT+509
HondurasHN+504
Hong KongHK+852
HungaryHU+36
IcelandIS+354
IndiaIN+91
IndonesiaID+62
IranIR+98
IraqIQ+964
IrelandIE+353
Isle of ManIM+44
IsraelIL+972
ItalyIT+39
Ivory CoastCI+225
JamaicaJM+1
JapanJP+81
JerseyJE+44
JordanJO+962
KazakhstanKZ+7
KenyaKE+254
KiribatiKI+686
KosovoXK+383
KuwaitKW+965
KyrgyzstanKG+996
LaosLA+856
LatviaLV+371
LebanonLB+961
LesothoLS+266
LiberiaLR+231
LibyaLY+218
LiechtensteinLI+423
LithuaniaLT+370
LuxembourgLU+352
MacauMO+853
MacedoniaMK+389
MadagascarMG+261
MalawiMW+265
MalaysiaMY+60
MaldivesMV+960
MaliML+223
MaltaMT+356
Marshall IslandsMH+692
MartiniqueMQ+596
MauritaniaMR+222
MauritiusMU+230
MayotteYT+262
MexicoMX+52
MicronesiaFM+691
MoldovaMD+373
MonacoMC+377
MongoliaMN+976
MontenegroME+382
MontserratMS+1
MoroccoMA+212
MozambiqueMZ+258
MyanmarMM+95
NamibiaNA+264
NauruNR+674
NepalNP+977
NetherlandsNL+31
New CaledoniaNC+687
New ZealandNZ+64
NicaraguaNI+505
NigerNE+227
NigeriaNG+234
NiueNU+683
Norfolk IslandNF+672
North KoreaKP+850
Northern Mariana IslandsMP+1
NorwayNO+47
OmanOM+968
PakistanPK+92
PalauPW+680
PalestinePS+970
PanamaPA+507
Papua New GuineaPG+675
ParaguayPY+595
PeruPE+51
PhilippinesPH+63
Pitcairn IslandsPN+64
PolandPL+48
PortugalPT+351
Puerto RicoPR+1