modified the env

This commit is contained in:
Gormery Kombo Wanjiru
2024-02-12 21:22:40 +00:00
parent 41f7d73acd
commit 36e41673bf
20 changed files with 585 additions and 581 deletions

View File

@@ -1,44 +1,44 @@
{ {
"name": "ollama-docker", "name": "ollama-docker",
"dockerComposeFile": ["../docker-compose.yml"], "dockerComposeFile": ["../docker-compose.yml"],
"service": "app", "service": "app",
"workspaceFolder": "/code", "workspaceFolder": "/code",
"customizations": { "customizations": {
"vscode": { "vscode": {
"extensions": [ "extensions": [
"ms-python.python", "ms-python.python",
"ms-python.vscode-pylance", "ms-python.vscode-pylance",
"ms-python.autopep8", "ms-python.autopep8",
"ms-python.debugpy", "ms-python.debugpy",
"ms-python.isort", "ms-python.isort",
"donjayamanne.python-environment-manager", "donjayamanne.python-environment-manager",
"donjayamanne.python-extension-pack", "donjayamanne.python-extension-pack",
"etmoffat.pip-packages", "etmoffat.pip-packages",
"aaron-bond.better-comments", "aaron-bond.better-comments",
"formulahendry.auto-rename-tag", "formulahendry.auto-rename-tag",
"formulahendry.code-runner", "formulahendry.code-runner",
"github.copilot", "github.copilot",
"github.vscode-pull-request-github", "github.vscode-pull-request-github",
"ms-azuretools.vscode-docker", "ms-azuretools.vscode-docker",
"ms-vscode-remote.remote-containers", "ms-vscode-remote.remote-containers",
"ms-vscode-remote.remote-ssh", "ms-vscode-remote.remote-ssh",
"ms-vscode-remote.vscode-remote-extensionpack", "ms-vscode-remote.vscode-remote-extensionpack",
"ms-toolsai.jupyter", "ms-toolsai.jupyter",
"ritwickdey.liveserver", "ritwickdey.liveserver",
"visualstudioexptteam.vscodeintellicode", "visualstudioexptteam.vscodeintellicode",
"vscode-icons-team.vscode-icons", "vscode-icons-team.vscode-icons",
"esbenp.prettier-vscode", "esbenp.prettier-vscode",
"jpotterm.simple-vim" "jpotterm.simple-vim"
], ],
"settings": { "settings": {
"python.pythonPath": "/usr/local/bin/python", "python.pythonPath": "/usr/local/bin/python",
"python.linting.pylintEnabled": false, "python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true, "python.linting.flake8Enabled": true,
"python.linting.flake8Args": ["--max-line-length=88"], "python.linting.flake8Args": ["--max-line-length=88"],
"python.formatting.provider": "ms-python.python", "python.formatting.provider": "ms-python.python",
"editor.formatOnSave": true "editor.formatOnSave": true
} }
} }
}, },
"postCreateCommand": "pip install -r requirements.txt" "postCreateCommand": "pip install -r requirements.txt"
} }

View File

@@ -1,5 +1,5 @@
# flyctl launch added from .gitignore # flyctl launch added from .gitignore
**\.dist **\.dist
**\.vscode **\.vscode
src\__pycache__ src\__pycache__
fly.toml fly.toml

6
.gitignore vendored
View File

@@ -1,4 +1,4 @@
.dist .dist
/src/__pycache__ /src/__pycache__
venv/ venv/
ollama/ ollama/

View File

@@ -1,28 +1,28 @@
{ {
"recommendations": [ "recommendations": [
"ms-python.python", "ms-python.python",
"ms-python.vscode-pylance", "ms-python.vscode-pylance",
"ms-python.autopep8", "ms-python.autopep8",
"ms-python.debugpy", "ms-python.debugpy",
"ms-python.isort", "ms-python.isort",
"donjayamanne.python-environment-manager", "donjayamanne.python-environment-manager",
"donjayamanne.python-extension-pack", "donjayamanne.python-extension-pack",
"etmoffat.pip-packages", "etmoffat.pip-packages",
"aaron-bond.better-comments", "aaron-bond.better-comments",
"formulahendry.auto-rename-tag", "formulahendry.auto-rename-tag",
"formulahendry.code-runner", "formulahendry.code-runner",
"github.copilot", "github.copilot",
"github.vscode-pull-request-github", "github.vscode-pull-request-github",
"ms-azuretools.vscode-docker", "ms-azuretools.vscode-docker",
"ms-vscode-remote.remote-containers", "ms-vscode-remote.remote-containers",
"ms-vscode-remote.remote-ssh", "ms-vscode-remote.remote-ssh",
"ms-vscode-remote.vscode-remote-extensionpack", "ms-vscode-remote.vscode-remote-extensionpack",
"ms-toolsai.jupyter", "ms-toolsai.jupyter",
"ritwickdey.liveserver", "ritwickdey.liveserver",
"visualstudioexptteam.vscodeintellicode", "visualstudioexptteam.vscodeintellicode",
"vscode-icons-team.vscode-icons", "vscode-icons-team.vscode-icons",
"esbenp.prettier-vscode" "esbenp.prettier-vscode"
] ]
} }

View File

@@ -1,5 +1,5 @@
{ {
"python.languageServer": "Pylance", "python.languageServer": "Pylance",
"python.analysis.extraPaths": ["../"], "python.analysis.extraPaths": ["../"],
"python.formatting.provider": "prettier", "python.formatting.provider": "prettier",
} }

View File

@@ -1,13 +1,17 @@
FROM python:3.11-slim FROM python:3.11-slim
WORKDIR /code WORKDIR /code
COPY ./requirements.txt ./ COPY ./requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt RUN apt-get update && apt-get install git -y && apt-get install curl -y
COPY ./src ./src RUN curl -fsSL https://ollama.com/install.sh | sh
EXPOSE 8000 RUN pip install --no-cache-dir -r requirements.txt
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"] COPY ./src ./src
EXPOSE 8000
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]

190
README.md
View File

@@ -1,96 +1,96 @@
# Ollama Docker Compose Setup # Ollama Docker Compose Setup
Welcome to the Ollama Docker Compose Setup! This project simplifies the deployment of Ollama using Docker Compose, making it easy to run Ollama with all its dependencies in a containerized environment. Welcome to the Ollama Docker Compose Setup! This project simplifies the deployment of Ollama using Docker Compose, making it easy to run Ollama with all its dependencies in a containerized environment.
## Getting Started ## Getting Started
### Prerequisites ### Prerequisites
Make sure you have the following prerequisites installed on your machine: Make sure you have the following prerequisites installed on your machine:
- Docker - Docker
- Docker Compose - Docker Compose
#### GPU Support (Optional) #### GPU Support (Optional)
If you have a GPU and want to leverage its power within a Docker container, follow these steps to install the NVIDIA Container Toolkit: If you have a GPU and want to leverage its power within a Docker container, follow these steps to install the NVIDIA Container Toolkit:
```bash ```bash
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \ curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
&& curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \ && curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \ sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
sudo apt-get update sudo apt-get update
sudo apt-get install -y nvidia-container-toolkit sudo apt-get install -y nvidia-container-toolkit
# Configure NVIDIA Container Toolkit # Configure NVIDIA Container Toolkit
sudo nvidia-ctk runtime configure --runtime=docker sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker sudo systemctl restart docker
# Test GPU integration # Test GPU integration
docker run --gpus all nvidia/cuda:11.5.2-base-ubuntu20.04 nvidia-smi docker run --gpus all nvidia/cuda:11.5.2-base-ubuntu20.04 nvidia-smi
``` ```
### Configuration ### Configuration
1. Clone the Docker Compose repository: 1. Clone the Docker Compose repository:
```bash ```bash
git clone https://github.com/valiantlynx/ollama-docker.git git clone https://github.com/valiantlynx/ollama-docker.git
``` ```
2. Change to the project directory: 2. Change to the project directory:
```bash ```bash
cd ollama-docker cd ollama-docker
``` ```
## Usage ## Usage
Start Ollama and its dependencies using Docker Compose: Start Ollama and its dependencies using Docker Compose:
if gpu is configured if gpu is configured
```bash ```bash
docker-compose -f docker-compose-ollama-gpu.yaml up -d docker-compose -f docker-compose-ollama-gpu.yaml up -d
``` ```
else else
```bash ```bash
docker-compose up -d docker-compose up -d
``` ```
Visit [http://localhost:3000](http://localhost:3000) in your browser to access Ollama-webui. Visit [http://localhost:3000](http://localhost:3000) in your browser to access Ollama-webui.
### Model Installation ### Model Installation
Navigate to settings -> model and install a model (e.g., llama2). This may take a couple of minutes, but afterward, you can use it just like ChatGPT. Navigate to settings -> model and install a model (e.g., llama2). This may take a couple of minutes, but afterward, you can use it just like ChatGPT.
### Explore Langchain and Ollama ### Explore Langchain and Ollama
You can explore Langchain and Ollama within the project. A third container named **app** has been created for this purpose. Inside, you'll find some examples. You can explore Langchain and Ollama within the project. A third container named **app** has been created for this purpose. Inside, you'll find some examples.
### Devcontainer and Virtual Environment ### Devcontainer and Virtual Environment
The **app** container serves as a devcontainer, allowing you to boot into it for experimentation. Additionally, the run.sh file contains code to set up a virtual environment if you prefer not to use Docker for your development environment. The **app** container serves as a devcontainer, allowing you to boot into it for experimentation. Additionally, the run.sh file contains code to set up a virtual environment if you prefer not to use Docker for your development environment.
## Stop and Cleanup ## Stop and Cleanup
To stop the containers and remove the network: To stop the containers and remove the network:
```bash ```bash
docker-compose down docker-compose down
``` ```
## Contributing ## Contributing
We welcome contributions! If you'd like to contribute to the Ollama Docker Compose Setup, please follow our [Contribution Guidelines](CONTRIBUTING.md). We welcome contributions! If you'd like to contribute to the Ollama Docker Compose Setup, please follow our [Contribution Guidelines](CONTRIBUTING.md).
## License ## License
This project is licensed under the [MIT License](LICENSE). Feel free to use, modify, and distribute it according to the terms of the license. Just give me a mention and some credit This project is licensed under the [MIT License](LICENSE). Feel free to use, modify, and distribute it according to the terms of the license. Just give me a mention and some credit
## Contact ## Contact
If you have any questions or concerns, please contact us at [vantlynxz@gmail.com](mailto:vantlynxz@gmail.com). If you have any questions or concerns, please contact us at [vantlynxz@gmail.com](mailto:vantlynxz@gmail.com).
Enjoy using Ollama with Docker Compose! 🐳🚀 Enjoy using Ollama with Docker Compose! 🐳🚀

View File

@@ -1,35 +1,35 @@
version: '3.8' version: '3.8'
services: services:
ollama: ollama:
volumes: volumes:
- ./ollama/ollama:/root/.ollama - ./ollama/ollama:/root/.ollama
container_name: ollama container_name: ollama
pull_policy: always pull_policy: always
tty: true tty: true
restart: unless-stopped restart: unless-stopped
image: ollama/ollama:latest image: ollama/ollama:latest
ports: ports:
- 11434:11434 - 11434:11434
deploy: deploy:
resources: resources:
reservations: reservations:
devices: devices:
- driver: nvidia - driver: nvidia
count: 1 count: 1
capabilities: [gpu] capabilities: [gpu]
ollama-webui: ollama-webui:
image: ghcr.io/ollama-webui/ollama-webui:main image: ghcr.io/ollama-webui/ollama-webui:main
container_name: ollama-webui container_name: ollama-webui
volumes: volumes:
- ./ollama/ollama-webui:/app/backend/data - ./ollama/ollama-webui:/app/backend/data
depends_on: depends_on:
- ollama - ollama
ports: ports:
- 3000:8080 - 3000:8080
environment: environment:
- '/ollama/api=http://ollama:11434/api' - '/ollama/api=http://ollama:11434/api'
extra_hosts: extra_hosts:
- host.docker.internal:host-gateway - host.docker.internal:host-gateway
restart: unless-stopped restart: unless-stopped

View File

@@ -1,52 +1,52 @@
version: '3.8' version: '3.8'
services: services:
app: app:
build: . build: .
ports: ports:
- 8000:8000 - 8000:8000
- 5678:5678 - 5678:5678
volumes: volumes:
- .:/code - .:/code
command: uvicorn src.main:app --host 0.0.0.0 --port 8000 --reload command: uvicorn src.main:app --host 0.0.0.0 --port 8000 --reload
restart: always restart: always
depends_on: depends_on:
- ollama - ollama
- llama-webui - llama-webui
networks: networks:
- ollama-docker - ollama-docker
ollama: ollama:
image: ollama/ollama:latest image: ollama/ollama:latest
ports: ports:
- 11434:11434 - 11434:11434
volumes: volumes:
- .:/code - .:/code
- ./ollama/ollama:/root/.ollama - ./ollama/ollama:/root/.ollama
container_name: ollama container_name: ollama
pull_policy: always pull_policy: always
tty: true tty: true
restart: always restart: always
networks: networks:
- ollama-docker - ollama-docker
llama-webui: llama-webui:
image: ghcr.io/ollama-webui/ollama-webui:main image: ghcr.io/ollama-webui/ollama-webui:main
container_name: ollama-webui container_name: ollama-webui
volumes: volumes:
- ./ollama/ollama-webui:/app/backend/data - ./ollama/ollama-webui:/app/backend/data
depends_on: depends_on:
- ollama - ollama
ports: ports:
- 3000:8080 - 3000:8080
environment: environment:
- '/ollama/api=http://ollama:11434/api' - '/ollama/api=http://ollama:11434/api'
extra_hosts: extra_hosts:
- host.docker.internal:host-gateway - host.docker.internal:host-gateway
restart: unless-stopped restart: unless-stopped
networks: networks:
- ollama-docker - ollama-docker
networks: networks:
ollama-docker: ollama-docker:
external: false external: false

View File

@@ -1,17 +1,17 @@
# fly.toml app configuration file generated for breath-first-search on 2023-10-17T03:52:02+02:00 # fly.toml app configuration file generated for breath-first-search on 2023-10-17T03:52:02+02:00
# #
# See https://fly.io/docs/reference/configuration/ for information about how to use this file. # See https://fly.io/docs/reference/configuration/ for information about how to use this file.
# #
app = "ollama-docker" app = "ollama-docker"
primary_region = "arn" primary_region = "arn"
[env] [env]
PORT = "8000" PORT = "8000"
[http_service] [http_service]
internal_port = 8000 internal_port = 8000
force_https = true force_https = true
auto_stop_machines = true auto_stop_machines = true
auto_start_machines = true auto_start_machines = true
min_machines_running = 0 min_machines_running = 0

View File

@@ -1,6 +1,6 @@
FROM llama2 FROM llama2
PARAMETER temperature 0.8 PARAMETER temperature 0.8
SYSTEM You are a financial assistant, you help classify expenses SYSTEM You are a financial assistant, you help classify expenses
and income from bank transactions and income from bank transactions

View File

@@ -1,10 +1,10 @@
fastapi fastapi
uvicorn uvicorn
debugpy debugpy
langchain-community langchain-community
langchain langchain
langchainhub langchainhub
gpt4all gpt4all
chromadb chromadb
requests requests
beautifulsoup4 beautifulsoup4

14
run.bat
View File

@@ -1,7 +1,7 @@
call python -m venv venv call python -m venv venv
call venv\Scripts\activate call venv\Scripts\activate
call python -m pip install --upgrade pip call python -m pip install --upgrade pip
call pip install -r requirements.txt call pip install -r requirements.txt
call python signal-processing.py call python signal-processing.py

10
run.sh
View File

@@ -1,5 +1,5 @@
python -m venv venv python -m venv venv
source venv/Scripts/activate source venv/Scripts/activate
pip install -r requirements.txt pip install -r requirements.txt
python src/test.py python src/test.py

View File

@@ -1,8 +1,8 @@
# run using docker # run using docker
docker build -t ollama-docker-image . docker build -t ollama-docker-image .
docker run --name ollama-docker-container -d -p 11434:11434 -p 8000:8000 -v $(pwd):/code ollama-docker-image docker run --name ollama-docker-container -d -p 11434:11434 -p 8000:8000 -v $(pwd):/code ollama-docker-image
#connect to turborepo #connect to turborepo
git subtree add --prefix=apps/ollama-docker https://github.com/valiantlynx/ollama-docker.git main --squash git subtree add --prefix=apps/ollama-docker https://github.com/valiantlynx/ollama-docker.git main --squash
git subtree pull --prefix=apps/ollama-docker https://github.com/valiantlynx/ollama-docker.git main --squash git subtree pull --prefix=apps/ollama-docker https://github.com/valiantlynx/ollama-docker.git main --squash
git subtree push --prefix=apps/ollama-docker https://github.com/valiantlynx/ollama-docker.git main git subtree push --prefix=apps/ollama-docker https://github.com/valiantlynx/ollama-docker.git main

View File

@@ -1,23 +1,23 @@
from langchain.llms import Ollama from langchain.llms import Ollama
from langchain.callbacks.manager import CallbackManager from langchain.callbacks.manager import CallbackManager
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
llm = Ollama(model="llama2-uncensored", llm = Ollama(model="llama2-uncensored",
# callback_manager = CallbackManager([StreamingStdOutCallbackHandler()]), # callback_manager = CallbackManager([StreamingStdOutCallbackHandler()]),
temperature=0.9, temperature=0.9,
) )
from langchain.prompts import PromptTemplate from langchain.prompts import PromptTemplate
prompt = PromptTemplate( prompt = PromptTemplate(
input_variables=["topic"], input_variables=["topic"],
template="Give me 5 interesting facts about {topic}?", template="Give me 5 interesting facts about {topic}?",
) )
from langchain.chains import LLMChain from langchain.chains import LLMChain
chain = LLMChain(llm=llm, chain = LLMChain(llm=llm,
prompt=prompt, prompt=prompt,
verbose=False) verbose=False)
# Run the chain only specifying the input variable. # Run the chain only specifying the input variable.
print(chain.run("the moon")) print(chain.run("the moon"))

View File

@@ -1,123 +1,123 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/daisyui@3.7.3/dist/full.css" rel="stylesheet" type="text/css"> <link href="https://cdn.jsdelivr.net/npm/daisyui@3.7.3/dist/full.css" rel="stylesheet" type="text/css">
<script src="https://cdn.tailwindcss.com"></script> <script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/htmx.org"></script> <script src="https://unpkg.com/htmx.org"></script>
<script src="https://unpkg.com/htmx.org/dist/ext/client-side-templates.js"></script> <script src="https://unpkg.com/htmx.org/dist/ext/client-side-templates.js"></script>
<script src="https://cdn.jsdelivr.net/npm/nunjucks@3.2.4/browser/nunjucks.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/nunjucks@3.2.4/browser/nunjucks.min.js"></script>
<script> <script>
// CORS workaround // CORS workaround
document.addEventListener("htmx:configRequest", (evt) => { document.addEventListener("htmx:configRequest", (evt) => {
evt.detail.headers = []; evt.detail.headers = [];
}); });
</script> </script>
<title>Whisper Magic Chat</title> <title>Whisper Magic Chat</title>
</head> </head>
<body class="bg-gradient-to-r from-blue-600 via-purple-600 to-pink-600 font-sans"> <body class="bg-gradient-to-r from-blue-600 via-purple-600 to-pink-600 font-sans">
<header class="bg-opacity-90 backdrop-filter backdrop-blur-lg py-6"> <header class="bg-opacity-90 backdrop-filter backdrop-blur-lg py-6">
<div class="container mx-auto flex justify-between items-center"> <div class="container mx-auto flex justify-between items-center">
<h1 class="text-3xl md:text-4xl lg:text-5xl font-extrabold text-white">Whisper Magic Chat</h1> <h1 class="text-3xl md:text-4xl lg:text-5xl font-extrabold text-white">Whisper Magic Chat</h1>
<nav> <nav>
<ul class="flex space-x-4"> <ul class="flex space-x-4">
<li><a href="/" class="hover:text-gray-300 text-white">Home</a></li> <li><a href="/" class="hover:text-gray-300 text-white">Home</a></li>
<li><a href="#features" class="hover:text-gray-300 text-white">Features</a></li> <li><a href="#features" class="hover:text-gray-300 text-white">Features</a></li>
<li><a href="/docs" class="hover:text-gray-300 text-white">Docs</a></li> <li><a href="/docs" class="hover:text-gray-300 text-white">Docs</a></li>
</ul> </ul>
</nav> </nav>
</div> </div>
</header> </header>
<section id="hero" class="bg-gray-900 text-white py-16"> <section id="hero" class="bg-gray-900 text-white py-16">
<div class="container mx-auto text-center"> <div class="container mx-auto text-center">
<h2 class="text-4xl lg:text-5xl font-semibold mb-4">Unleash the Magic of Your Voice</h2> <h2 class="text-4xl lg:text-5xl font-semibold mb-4">Unleash the Magic of Your Voice</h2>
<p class="text-lg lg:text-xl text-gray-300 leading-7 mb-8">Transform your voice into something enchanting with <p class="text-lg lg:text-xl text-gray-300 leading-7 mb-8">Transform your voice into something enchanting with
Whisper Magic API. Experience the future of automatic speech recognition with unparalleled accuracy and speed.</p> Whisper Magic API. Experience the future of automatic speech recognition with unparalleled accuracy and speed.</p>
<a href="#transcribe" <a href="#transcribe"
class="bg-blue-500 text-white px-8 py-3 rounded-full hover:bg-blue-700 transition duration-300">Get class="bg-blue-500 text-white px-8 py-3 rounded-full hover:bg-blue-700 transition duration-300">Get
Started</a> Started</a>
</div> </div>
</section> </section>
<section id="transcribe" class="bg-gray-100 py-16" hx-ext="client-side-templates"> <section id="transcribe" class="bg-gray-100 py-16" hx-ext="client-side-templates">
<div class="container mx-auto text-center"> <div class="container mx-auto text-center">
<h2 class="text-3xl lg:text-4xl font-semibold mb-6 text-gray-800">Whisper Magic Transcription</h2> <h2 class="text-3xl lg:text-4xl font-semibold mb-6 text-gray-800">Whisper Magic Transcription</h2>
<p class="text-lg lg:text-xl text-gray-700 mb-6">Upload an audio file to transcribe and experience the magic of <p class="text-lg lg:text-xl text-gray-700 mb-6">Upload an audio file to transcribe and experience the magic of
Whisper.</p> Whisper.</p>
<form hx-post="/transcribe" hx-trigger="submit" hx-swap="outerHTML" enctype="multipart/form-data" <form hx-post="/transcribe" hx-trigger="submit" hx-swap="outerHTML" enctype="multipart/form-data"
class="flex flex-col items-center space-y-4" nunjucks-template="chat" _='on htmx:xhr:progress(loaded, total) set #progress.value to (loaded/total)*100'> class="flex flex-col items-center space-y-4" nunjucks-template="chat" _='on htmx:xhr:progress(loaded, total) set #progress.value to (loaded/total)*100'>
<input type="file" name="files" class="p-4 border border-gray-300 rounded"> <input type="file" name="files" class="p-4 border border-gray-300 rounded">
<button type="submit" <button type="submit"
class="bg-blue-500 text-white px-8 py-3 rounded-full hover:bg-blue-700 transition duration-300">Transcribe</button> class="bg-blue-500 text-white px-8 py-3 rounded-full hover:bg-blue-700 transition duration-300">Transcribe</button>
<progress id='progress' value='0' max='100' class="w-full h-4 bg-blue-200 rounded-full"></progress> <progress id='progress' value='0' max='100' class="w-full h-4 bg-blue-200 rounded-full"></progress>
<!-- HTMX and Nunjucks templates --> <!-- HTMX and Nunjucks templates -->
<template id="chat"> <template id="chat">
<!-- totalItems --> <!-- totalItems -->
{% if results == 1 %} {% if results == 1 %}
<i class="text-gray-500 mb-4"> Found {{ results.length }} files.</i> <i class="text-gray-500 mb-4"> Found {{ results.length }} files.</i>
{% endif %} {% endif %}
<!-- items --> <!-- items -->
{% for chat in results %} {% for chat in results %}
<div class="block mb-8 mx-auto max-w-md bg-white rounded-lg p-4 shadow-md hover:shadow-lg"> <div class="block mb-8 mx-auto max-w-md bg-white rounded-lg p-4 shadow-md hover:shadow-lg">
<div class="flex items-center"> <div class="flex items-center">
<div class="w-10 h-10 rounded-full overflow-hidden mr-4"> <div class="w-10 h-10 rounded-full overflow-hidden mr-4">
<img alt="Whisper Magic transcription icon" <img alt="Whisper Magic transcription icon"
src="https://api.dicebear.com/7.x/adventurer/svg?seed={{ chat.filename }}" src="https://api.dicebear.com/7.x/adventurer/svg?seed={{ chat.filename }}"
class="object-cover w-full h-full"> class="object-cover w-full h-full">
</div> </div>
<div> <div>
<span class="text-blue-500 font-bold">Whisper:</span> <span class="text-blue-500 font-bold">Whisper:</span>
<time class="text-xs opacity-50 block">{{ chat.filename | truncate(10, true, "")}}</time> <time class="text-xs opacity-50 block">{{ chat.filename | truncate(10, true, "")}}</time>
</div> </div>
</div> </div>
<div class="mt-4">{{ chat.transcript }}</div> <div class="mt-4">{{ chat.transcript }}</div>
<div class="mt-4 text-blue-500 hover:underline"> <div class="mt-4 text-blue-500 hover:underline">
<a href="javascript:location.reload(true);" rel="noopener noreferrer">Retry?</a> <a href="javascript:location.reload(true);" rel="noopener noreferrer">Retry?</a>
</div> </div>
</div> </div>
{% endfor %} {% endfor %}
</template> </template>
</form> </form>
</div> </div>
</section> </section>
<section id="features" class="bg-gray-800 text-white py-16"> <section id="features" class="bg-gray-800 text-white py-16">
<div class="container mx-auto text-center"> <div class="container mx-auto text-center">
<h2 class="text-3xl lg:text-4xl font-semibold mb-12">Enchanting Features</h2> <h2 class="text-3xl lg:text-4xl font-semibold mb-12">Enchanting Features</h2>
<div class="grid grid-cols-1 md:grid-cols-3 gap-8"> <div class="grid grid-cols-1 md:grid-cols-3 gap-8">
<!-- Feature 1 --> <!-- Feature 1 -->
<div class="p-8 bg-white bg-opacity-70 rounded-lg shadow-md"> <div class="p-8 bg-white bg-opacity-70 rounded-lg shadow-md">
<h3 class="text-2xl font-semibold mb-4 text-gray-800">Voice Transformation</h3> <h3 class="text-2xl font-semibold mb-4 text-gray-800">Voice Transformation</h3>
<p class="text-gray-700">Turn your voice into a symphony of magical sounds. Choose from a variety of <p class="text-gray-700">Turn your voice into a symphony of magical sounds. Choose from a variety of
enchanting transformations.</p> enchanting transformations.</p>
</div> </div>
<!-- Feature 2 --> <!-- Feature 2 -->
<div class="p-8 bg-white bg-opacity-70 rounded-lg shadow-md"> <div class="p-8 bg-white bg-opacity-70 rounded-lg shadow-md">
<h3 class="text-2xl font-semibold mb-4 text-gray-800">Whisper Recognition</h3> <h3 class="text-2xl font-semibold mb-4 text-gray-800">Whisper Recognition</h3>
<p class="text-gray-700">Whisper Magic recognizes whispers with unparalleled precision, making it perfect for <p class="text-gray-700">Whisper Magic recognizes whispers with unparalleled precision, making it perfect for
ASMR applications.</p> ASMR applications.</p>
</div> </div>
<!-- Feature 3 --> <!-- Feature 3 -->
<div class="p-8 bg-white bg-opacity-70 rounded-lg shadow-md"> <div class="p-8 bg-white bg-opacity-70 rounded-lg shadow-md">
<h3 class="text-2xl font-semibold mb-4 text-gray-800">Real-time Spell Casting</h3> <h3 class="text-2xl font-semibold mb-4 text-gray-800">Real-time Spell Casting</h3>
<p class="text-gray-700">Cast spells using your voice in real-time. Experience the magic as your words come to <p class="text-gray-700">Cast spells using your voice in real-time. Experience the magic as your words come to
life.</p> life.</p>
</div> </div>
</div> </div>
</div> </div>
</section> </section>
<footer class="bg-gray-900 text-white py-6"> <footer class="bg-gray-900 text-white py-6">
<div class="container mx-auto text-center"> <div class="container mx-auto text-center">
<p>&copy; 2024 Whisper Magic. All Rights Reserved.</p> <p>&copy; 2024 Whisper Magic. All Rights Reserved.</p>
</div> </div>
</footer> </footer>
</body> </body>
</html> </html>

View File

@@ -1,28 +1,28 @@
from fastapi import FastAPI from fastapi import FastAPI
from fastapi.responses import HTMLResponse from fastapi.responses import HTMLResponse
from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.cors import CORSMiddleware
import debugpy import debugpy
from typing import List from typing import List
app = FastAPI() app = FastAPI()
# Allow all origins for CORS (you can customize this based on your requirements) # Allow all origins for CORS (you can customize this based on your requirements)
origins = ["*"] origins = ["*"]
# Configure CORS middleware # Configure CORS middleware
app.add_middleware( app.add_middleware(
CORSMiddleware, CORSMiddleware,
allow_origins=origins, allow_origins=origins,
allow_credentials=True, allow_credentials=True,
allow_methods=["*"], allow_methods=["*"],
allow_headers=["*"], allow_headers=["*"],
) )
debugpy.listen(("0.0.0.0", 5678)) debugpy.listen(("0.0.0.0", 5678))
@app.get("/", response_class=HTMLResponse) @app.get("/", response_class=HTMLResponse)
async def read_root(): async def read_root():
# Read the content of your HTML file # Read the content of your HTML file
with open("./src/index.html", "r") as file: with open("./src/index.html", "r") as file:
html_content = file.read() html_content = file.read()
return HTMLResponse(content=html_content) return HTMLResponse(content=html_content)

View File

@@ -1,71 +1,71 @@
# Load web page # Load web page
import argparse import argparse
from langchain.document_loaders import WebBaseLoader from langchain.document_loaders import WebBaseLoader
from langchain.text_splitter import RecursiveCharacterTextSplitter from langchain.text_splitter import RecursiveCharacterTextSplitter
# Embed and store # Embed and store
from langchain.vectorstores import Chroma from langchain.vectorstores import Chroma
from langchain.embeddings import GPT4AllEmbeddings from langchain.embeddings import GPT4AllEmbeddings
from langchain.embeddings import OllamaEmbeddings # We can also try Ollama embeddings from langchain.embeddings import OllamaEmbeddings # We can also try Ollama embeddings
from langchain.llms import Ollama from langchain.llms import Ollama
from langchain.callbacks.manager import CallbackManager from langchain.callbacks.manager import CallbackManager
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
def main(): def main():
parser = argparse.ArgumentParser(description='Filter out URL argument.') parser = argparse.ArgumentParser(description='Filter out URL argument.')
parser.add_argument('--url', type=str, default='https://valiantlynx.com', required=True, help='The URL to filter out.') parser.add_argument('--url', type=str, default='https://valiantlynx.com', required=True, help='The URL to filter out.')
args = parser.parse_args() args = parser.parse_args()
url = args.url url = args.url
print(f"using URL: {url}") print(f"using URL: {url}")
loader = WebBaseLoader(url) loader = WebBaseLoader(url)
data = loader.load() data = loader.load()
# Split into chunks # Split into chunks
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1500, chunk_overlap=100) text_splitter = RecursiveCharacterTextSplitter(chunk_size=1500, chunk_overlap=100)
all_splits = text_splitter.split_documents(data) all_splits = text_splitter.split_documents(data)
print(f"Split into {len(all_splits)} chunks") print(f"Split into {len(all_splits)} chunks")
vectorstore = Chroma.from_documents(documents=all_splits, vectorstore = Chroma.from_documents(documents=all_splits,
embedding=GPT4AllEmbeddings()) embedding=GPT4AllEmbeddings())
# Retrieve # Retrieve
# question = "What are the latest headlines on {url}?" # question = "What are the latest headlines on {url}?"
# docs = vectorstore.similarity_search(question) # docs = vectorstore.similarity_search(question)
print(f"Loaded {len(data)} documents") print(f"Loaded {len(data)} documents")
# print(f"Retrieved {len(docs)} documents") # print(f"Retrieved {len(docs)} documents")
# RAG prompt # RAG prompt
from langchain import hub from langchain import hub
QA_CHAIN_PROMPT = hub.pull("rlm/rag-prompt-llama") QA_CHAIN_PROMPT = hub.pull("rlm/rag-prompt-llama")
# LLM # LLM
llm = Ollama(model="llama2-uncensored", llm = Ollama(model="llama2-uncensored",
verbose=True, verbose=True,
callback_manager=CallbackManager([StreamingStdOutCallbackHandler()])) callback_manager=CallbackManager([StreamingStdOutCallbackHandler()]))
print(f"Loaded LLM model {llm.model}") print(f"Loaded LLM model {llm.model}")
# QA chain # QA chain
from langchain.chains import RetrievalQA from langchain.chains import RetrievalQA
qa_chain = RetrievalQA.from_chain_type( qa_chain = RetrievalQA.from_chain_type(
llm, llm,
retriever=vectorstore.as_retriever(), retriever=vectorstore.as_retriever(),
chain_type_kwargs={"prompt": QA_CHAIN_PROMPT}, chain_type_kwargs={"prompt": QA_CHAIN_PROMPT},
) )
# Ask a question # Ask a question
question = f"summarize what this blog is trying to say? {url}?" question = f"summarize what this blog is trying to say? {url}?"
result = qa_chain({"query": question}) result = qa_chain({"query": question})
# print(result) # print(result)
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@@ -1,10 +1,10 @@
from langchain.llms import Ollama from langchain.llms import Ollama
from langchain.callbacks.manager import CallbackManager from langchain.callbacks.manager import CallbackManager
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
llm = Ollama( llm = Ollama(
base_url="http://localhost:11434", base_url="http://localhost:11434",
model="llama2-uncensored", model="llama2-uncensored",
callback_manager = CallbackManager([StreamingStdOutCallbackHandler()])) callback_manager = CallbackManager([StreamingStdOutCallbackHandler()]))
llm("hello:") llm("hello:")