initial commit

This commit is contained in:
Gormery Kombo Wanjiru
2024-02-04 23:37:19 +01:00
commit 8c73f7a34b
20 changed files with 418 additions and 0 deletions

View File

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

5
.dockerignore Normal file
View File

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

4
.gitignore vendored Normal file
View File

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

1
.vscode/Bookmark.bcat vendored Normal file
View File

@@ -0,0 +1 @@
[{"Group":"This is a sample~","Time":"","FileAndPath":[{"Tag":"Welcome use bookmark","Path":"","Start":"0.0","End":"0.0","Time":""}]}]

1
.vscode/CatStatus.bcat vendored Normal file
View File

@@ -0,0 +1 @@
0

28
.vscode/extensions.json vendored Normal file
View File

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

5
.vscode/settings.json vendored Normal file
View File

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

13
Dockerfile Normal file
View File

@@ -0,0 +1,13 @@
FROM python:3.11-slim
WORKDIR /code
COPY ./requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY ./src ./src
EXPOSE 8000
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]

62
README.md Normal file
View File

@@ -0,0 +1,62 @@
# 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.
## Getting Started
To get started with the Ollama Docker Compose Setup, follow the steps below:
### Prerequisites
Make sure you have the following prerequisites installed on your machine:
- [Docker](https://www.docker.com/)
- [Docker Compose](https://docs.docker.com/compose/)
### Configuration
1. Clone the Docker Compose repository:
```bash
git clone https://github.com/valiantlynx/ollama-docker.git
```
2. Change to the project directory:
```bash
cd ollama-docker
mkdir ollama/ollama
mkdir ollama/ollama-webui
```
### Usage
Start Ollama and its dependencies using Docker Compose:
```bash
docker-compose up -d
```
Visit [http://localhost:3000](http://localhost:3000) in your browser to access Ollama.
### Stop and Cleanup
To stop the containers and remove the network:
```bash
docker-compose down
```
## Contributing
We welcome contributions! If you'd like to contribute to the Ollama Docker Compose Setup, please follow our [Contribution Guidelines](CONTRIBUTING.md).
## 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.
## Contact
If you have any questions or concerns, please contact us at [contact@ollama.com](mailto:contact@ollama.com).
Enjoy using Ollama with Docker Compose! 🐳🚀

52
docker-compose.yml Normal file
View File

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

17
fly.toml Normal file
View File

@@ -0,0 +1,17 @@
# 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.
#
app = "ollama-docker"
primary_region = "arn"
[env]
PORT = "8000"
[http_service]
internal_port = 8000
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0

6
model_file Normal file
View File

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

4
requirements.txt Normal file
View File

@@ -0,0 +1,4 @@
fastapi
uvicorn
debugpy
langchain_community

7
run.bat Normal file
View File

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

5
run.sh Normal file
View File

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

8
setup.sh Normal file
View File

@@ -0,0 +1,8 @@
# run using docker
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
#connect to turborepo
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 push --prefix=apps/ollama-docker https://github.com/valiantlynx/ollama-docker.git main

View File

@@ -0,0 +1,4 @@
from langchain_community.llms import Ollama
llm = Ollama(model="llama2")
llm.invoke("The first man on the moon was ...")

123
src/index.html Normal file
View File

@@ -0,0 +1,123 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<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">
<script src="https://cdn.tailwindcss.com"></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://cdn.jsdelivr.net/npm/nunjucks@3.2.4/browser/nunjucks.min.js"></script>
<script>
// CORS workaround
document.addEventListener("htmx:configRequest", (evt) => {
evt.detail.headers = [];
});
</script>
<title>Whisper Magic Chat</title>
</head>
<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">
<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>
<nav>
<ul class="flex space-x-4">
<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="/docs" class="hover:text-gray-300 text-white">Docs</a></li>
</ul>
</nav>
</div>
</header>
<section id="hero" class="bg-gray-900 text-white py-16">
<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>
<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>
<a href="#transcribe"
class="bg-blue-500 text-white px-8 py-3 rounded-full hover:bg-blue-700 transition duration-300">Get
Started</a>
</div>
</section>
<section id="transcribe" class="bg-gray-100 py-16" hx-ext="client-side-templates">
<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>
<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>
<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'>
<input type="file" name="files" class="p-4 border border-gray-300 rounded">
<button type="submit"
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>
<!-- HTMX and Nunjucks templates -->
<template id="chat">
<!-- totalItems -->
{% if results == 1 %}
<i class="text-gray-500 mb-4"> Found {{ results.length }} files.</i>
{% endif %}
<!-- items -->
{% 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="flex items-center">
<div class="w-10 h-10 rounded-full overflow-hidden mr-4">
<img alt="Whisper Magic transcription icon"
src="https://api.dicebear.com/7.x/adventurer/svg?seed={{ chat.filename }}"
class="object-cover w-full h-full">
</div>
<div>
<span class="text-blue-500 font-bold">Whisper:</span>
<time class="text-xs opacity-50 block">{{ chat.filename | truncate(10, true, "")}}</time>
</div>
</div>
<div class="mt-4">{{ chat.transcript }}</div>
<div class="mt-4 text-blue-500 hover:underline">
<a href="javascript:location.reload(true);" rel="noopener noreferrer">Retry?</a>
</div>
</div>
{% endfor %}
</template>
</form>
</div>
</section>
<section id="features" class="bg-gray-800 text-white py-16">
<div class="container mx-auto text-center">
<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">
<!-- Feature 1 -->
<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>
<p class="text-gray-700">Turn your voice into a symphony of magical sounds. Choose from a variety of
enchanting transformations.</p>
</div>
<!-- Feature 2 -->
<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>
<p class="text-gray-700">Whisper Magic recognizes whispers with unparalleled precision, making it perfect for
ASMR applications.</p>
</div>
<!-- Feature 3 -->
<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>
<p class="text-gray-700">Cast spells using your voice in real-time. Experience the magic as your words come to
life.</p>
</div>
</div>
</div>
</section>
<footer class="bg-gray-900 text-white py-6">
<div class="container mx-auto text-center">
<p>&copy; 2024 Whisper Magic. All Rights Reserved.</p>
</div>
</footer>
</body>
</html>

28
src/main.py Normal file
View File

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

View File

@@ -0,0 +1 @@
Ollama(model="llama2",