From 36e41673bf32593ff82ae64d226d1aa0f4376729 Mon Sep 17 00:00:00 2001 From: Gormery Kombo Wanjiru Date: Mon, 12 Feb 2024 21:22:40 +0000 Subject: [PATCH] modified the env --- .devcontainer/devcontainer.json | 88 ++++++------ .dockerignore | 10 +- .gitignore | 6 +- .vscode/extensions.json | 54 +++---- .vscode/settings.json | 8 +- Dockerfile | 30 ++-- README.md | 190 ++++++++++++------------ docker-compose-ollama-gpu.yaml | 68 ++++----- docker-compose.yml | 104 +++++++------- fly.toml | 34 ++--- model_file | 12 +- requirements.txt | 18 +-- run.bat | 14 +- run.sh | 10 +- setup.sh | 16 +-- src/basic_chain.py | 46 +++--- src/index.html | 246 ++++++++++++++++---------------- src/main.py | 54 +++---- src/rag.py | 140 +++++++++--------- src/test.py | 18 +-- 20 files changed, 585 insertions(+), 581 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index b9baa04..1684850 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,44 +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" -} +{ + "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" +} diff --git a/.dockerignore b/.dockerignore index a57a296..d48361a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,5 @@ -# flyctl launch added from .gitignore -**\.dist -**\.vscode -src\__pycache__ -fly.toml +# flyctl launch added from .gitignore +**\.dist +**\.vscode +src\__pycache__ +fly.toml diff --git a/.gitignore b/.gitignore index 67b9890..3ea829d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -.dist -/src/__pycache__ -venv/ +.dist +/src/__pycache__ +venv/ ollama/ \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 6102f6f..a5a8c97 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,28 +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" - ] -} - +{ + "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" + ] +} + \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 00d6496..192bd08 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,5 @@ -{ - "python.languageServer": "Pylance", - "python.analysis.extraPaths": ["../"], - "python.formatting.provider": "prettier", +{ + "python.languageServer": "Pylance", + "python.analysis.extraPaths": ["../"], + "python.formatting.provider": "prettier", } \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 4e61306..3c9fcb4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,17 @@ -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"] +FROM python:3.11-slim + +WORKDIR /code + +COPY ./requirements.txt ./ + +RUN apt-get update && apt-get install git -y && apt-get install curl -y + +RUN curl -fsSL https://ollama.com/install.sh | sh + +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"] diff --git a/README.md b/README.md index de4eda6..770c6b2 100644 --- a/README.md +++ b/README.md @@ -1,96 +1,96 @@ -# 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 - -### Prerequisites - -Make sure you have the following prerequisites installed on your machine: - -- Docker -- Docker Compose - -#### 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: - -```bash -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 | \ - 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 apt-get update -sudo apt-get install -y nvidia-container-toolkit - -# Configure NVIDIA Container Toolkit -sudo nvidia-ctk runtime configure --runtime=docker -sudo systemctl restart docker - -# Test GPU integration -docker run --gpus all nvidia/cuda:11.5.2-base-ubuntu20.04 nvidia-smi -``` - -### 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 - ``` - -## Usage - -Start Ollama and its dependencies using Docker Compose: - -if gpu is configured -```bash -docker-compose -f docker-compose-ollama-gpu.yaml up -d -``` - -else -```bash -docker-compose up -d -``` - -Visit [http://localhost:3000](http://localhost:3000) in your browser to access Ollama-webui. - -### 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. - -### 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. - -### 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. - -## 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. Just give me a mention and some credit - -## Contact - -If you have any questions or concerns, please contact us at [vantlynxz@gmail.com](mailto:vantlynxz@gmail.com). - +# 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 + +### Prerequisites + +Make sure you have the following prerequisites installed on your machine: + +- Docker +- Docker Compose + +#### 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: + +```bash +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 | \ + 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 apt-get update +sudo apt-get install -y nvidia-container-toolkit + +# Configure NVIDIA Container Toolkit +sudo nvidia-ctk runtime configure --runtime=docker +sudo systemctl restart docker + +# Test GPU integration +docker run --gpus all nvidia/cuda:11.5.2-base-ubuntu20.04 nvidia-smi +``` + +### 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 + ``` + +## Usage + +Start Ollama and its dependencies using Docker Compose: + +if gpu is configured +```bash +docker-compose -f docker-compose-ollama-gpu.yaml up -d +``` + +else +```bash +docker-compose up -d +``` + +Visit [http://localhost:3000](http://localhost:3000) in your browser to access Ollama-webui. + +### 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. + +### 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. + +### 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. + +## 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. Just give me a mention and some credit + +## Contact + +If you have any questions or concerns, please contact us at [vantlynxz@gmail.com](mailto:vantlynxz@gmail.com). + Enjoy using Ollama with Docker Compose! 🐳🚀 \ No newline at end of file diff --git a/docker-compose-ollama-gpu.yaml b/docker-compose-ollama-gpu.yaml index 59b2715..fd9fe37 100644 --- a/docker-compose-ollama-gpu.yaml +++ b/docker-compose-ollama-gpu.yaml @@ -1,35 +1,35 @@ -version: '3.8' - -services: - ollama: - volumes: - - ./ollama/ollama:/root/.ollama - container_name: ollama - pull_policy: always - tty: true - restart: unless-stopped - image: ollama/ollama:latest - ports: - - 11434:11434 - deploy: - resources: - reservations: - devices: - - driver: nvidia - count: 1 - capabilities: [gpu] - - ollama-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 +version: '3.8' + +services: + ollama: + volumes: + - ./ollama/ollama:/root/.ollama + container_name: ollama + pull_policy: always + tty: true + restart: unless-stopped + image: ollama/ollama:latest + ports: + - 11434:11434 + deploy: + resources: + reservations: + devices: + - driver: nvidia + count: 1 + capabilities: [gpu] + + ollama-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 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 42ee2fe..da7ddd6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,52 +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 - +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 + diff --git a/fly.toml b/fly.toml index 27da8b3..0319f4c 100644 --- a/fly.toml +++ b/fly.toml @@ -1,17 +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 +# 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 diff --git a/model_file b/model_file index 6aff2d3..0fb92ca 100644 --- a/model_file +++ b/model_file @@ -1,6 +1,6 @@ -FROM llama2 - -PARAMETER temperature 0.8 - -SYSTEM You are a financial assistant, you help classify expenses -and income from bank transactions +FROM llama2 + +PARAMETER temperature 0.8 + +SYSTEM You are a financial assistant, you help classify expenses +and income from bank transactions diff --git a/requirements.txt b/requirements.txt index 2dfcfd8..723fdb2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,10 @@ -fastapi -uvicorn -debugpy -langchain-community -langchain -langchainhub -gpt4all -chromadb -requests +fastapi +uvicorn +debugpy +langchain-community +langchain +langchainhub +gpt4all +chromadb +requests beautifulsoup4 \ No newline at end of file diff --git a/run.bat b/run.bat index 934c3b4..357dd17 100644 --- a/run.bat +++ b/run.bat @@ -1,7 +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 +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 diff --git a/run.sh b/run.sh index a17de61..3af3a1a 100644 --- a/run.sh +++ b/run.sh @@ -1,5 +1,5 @@ -python -m venv venv -source venv/Scripts/activate -pip install -r requirements.txt -python src/test.py - +python -m venv venv +source venv/Scripts/activate +pip install -r requirements.txt +python src/test.py + diff --git a/setup.sh b/setup.sh index f188dc4..83883f2 100644 --- a/setup.sh +++ b/setup.sh @@ -1,8 +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 +# 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 diff --git a/src/basic_chain.py b/src/basic_chain.py index 0175467..2a81527 100644 --- a/src/basic_chain.py +++ b/src/basic_chain.py @@ -1,23 +1,23 @@ -from langchain.llms import Ollama -from langchain.callbacks.manager import CallbackManager -from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler - -llm = Ollama(model="llama2-uncensored", - # callback_manager = CallbackManager([StreamingStdOutCallbackHandler()]), - temperature=0.9, - ) - -from langchain.prompts import PromptTemplate - -prompt = PromptTemplate( - input_variables=["topic"], - template="Give me 5 interesting facts about {topic}?", -) - -from langchain.chains import LLMChain -chain = LLMChain(llm=llm, - prompt=prompt, - verbose=False) - -# Run the chain only specifying the input variable. -print(chain.run("the moon")) +from langchain.llms import Ollama +from langchain.callbacks.manager import CallbackManager +from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler + +llm = Ollama(model="llama2-uncensored", + # callback_manager = CallbackManager([StreamingStdOutCallbackHandler()]), + temperature=0.9, + ) + +from langchain.prompts import PromptTemplate + +prompt = PromptTemplate( + input_variables=["topic"], + template="Give me 5 interesting facts about {topic}?", +) + +from langchain.chains import LLMChain +chain = LLMChain(llm=llm, + prompt=prompt, + verbose=False) + +# Run the chain only specifying the input variable. +print(chain.run("the moon")) diff --git a/src/index.html b/src/index.html index e7d28e2..88ea430 100644 --- a/src/index.html +++ b/src/index.html @@ -1,123 +1,123 @@ - - - - - - - - - - - - - Whisper Magic Chat - - - - -
-
-

Whisper Magic Chat

- -
-
- -
-
-

Unleash the Magic of Your Voice

-

Transform your voice into something enchanting with - Whisper Magic API. Experience the future of automatic speech recognition with unparalleled accuracy and speed.

- Get - Started -
-
- -
-
-

Whisper Magic Transcription

-

Upload an audio file to transcribe and experience the magic of - Whisper.

- -
- - - - - -
-
-
- -
-
-

Enchanting Features

-
- -
-

Voice Transformation

-

Turn your voice into a symphony of magical sounds. Choose from a variety of - enchanting transformations.

-
- -
-

Whisper Recognition

-

Whisper Magic recognizes whispers with unparalleled precision, making it perfect for - ASMR applications.

-
- -
-

Real-time Spell Casting

-

Cast spells using your voice in real-time. Experience the magic as your words come to - life.

-
-
-
-
- - - - - + + + + + + + + + + + + + Whisper Magic Chat + + + + +
+
+

Whisper Magic Chat

+ +
+
+ +
+
+

Unleash the Magic of Your Voice

+

Transform your voice into something enchanting with + Whisper Magic API. Experience the future of automatic speech recognition with unparalleled accuracy and speed.

+ Get + Started +
+
+ +
+
+

Whisper Magic Transcription

+

Upload an audio file to transcribe and experience the magic of + Whisper.

+ +
+ + + + + +
+
+
+ +
+
+

Enchanting Features

+
+ +
+

Voice Transformation

+

Turn your voice into a symphony of magical sounds. Choose from a variety of + enchanting transformations.

+
+ +
+

Whisper Recognition

+

Whisper Magic recognizes whispers with unparalleled precision, making it perfect for + ASMR applications.

+
+ +
+

Real-time Spell Casting

+

Cast spells using your voice in real-time. Experience the magic as your words come to + life.

+
+
+
+
+ + + + + diff --git a/src/main.py b/src/main.py index f3f268a..08eeddb 100644 --- a/src/main.py +++ b/src/main.py @@ -1,28 +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() - +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) \ No newline at end of file diff --git a/src/rag.py b/src/rag.py index 9686e80..1efbe56 100644 --- a/src/rag.py +++ b/src/rag.py @@ -1,71 +1,71 @@ -# Load web page -import argparse - -from langchain.document_loaders import WebBaseLoader -from langchain.text_splitter import RecursiveCharacterTextSplitter - -# Embed and store -from langchain.vectorstores import Chroma -from langchain.embeddings import GPT4AllEmbeddings -from langchain.embeddings import OllamaEmbeddings # We can also try Ollama embeddings - -from langchain.llms import Ollama -from langchain.callbacks.manager import CallbackManager -from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler - -def main(): - 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.') - - args = parser.parse_args() - url = args.url - print(f"using URL: {url}") - - loader = WebBaseLoader(url) - data = loader.load() - - # Split into chunks - text_splitter = RecursiveCharacterTextSplitter(chunk_size=1500, chunk_overlap=100) - all_splits = text_splitter.split_documents(data) - print(f"Split into {len(all_splits)} chunks") - - vectorstore = Chroma.from_documents(documents=all_splits, - embedding=GPT4AllEmbeddings()) - - # Retrieve - # question = "What are the latest headlines on {url}?" - # docs = vectorstore.similarity_search(question) - - print(f"Loaded {len(data)} documents") - # print(f"Retrieved {len(docs)} documents") - - # RAG prompt - from langchain import hub - QA_CHAIN_PROMPT = hub.pull("rlm/rag-prompt-llama") - - - # LLM - llm = Ollama(model="llama2-uncensored", - verbose=True, - callback_manager=CallbackManager([StreamingStdOutCallbackHandler()])) - print(f"Loaded LLM model {llm.model}") - - # QA chain - from langchain.chains import RetrievalQA - qa_chain = RetrievalQA.from_chain_type( - llm, - retriever=vectorstore.as_retriever(), - chain_type_kwargs={"prompt": QA_CHAIN_PROMPT}, - - ) - - # Ask a question - question = f"summarize what this blog is trying to say? {url}?" - result = qa_chain({"query": question}) - - # print(result) - - - -if __name__ == "__main__": +# Load web page +import argparse + +from langchain.document_loaders import WebBaseLoader +from langchain.text_splitter import RecursiveCharacterTextSplitter + +# Embed and store +from langchain.vectorstores import Chroma +from langchain.embeddings import GPT4AllEmbeddings +from langchain.embeddings import OllamaEmbeddings # We can also try Ollama embeddings + +from langchain.llms import Ollama +from langchain.callbacks.manager import CallbackManager +from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler + +def main(): + 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.') + + args = parser.parse_args() + url = args.url + print(f"using URL: {url}") + + loader = WebBaseLoader(url) + data = loader.load() + + # Split into chunks + text_splitter = RecursiveCharacterTextSplitter(chunk_size=1500, chunk_overlap=100) + all_splits = text_splitter.split_documents(data) + print(f"Split into {len(all_splits)} chunks") + + vectorstore = Chroma.from_documents(documents=all_splits, + embedding=GPT4AllEmbeddings()) + + # Retrieve + # question = "What are the latest headlines on {url}?" + # docs = vectorstore.similarity_search(question) + + print(f"Loaded {len(data)} documents") + # print(f"Retrieved {len(docs)} documents") + + # RAG prompt + from langchain import hub + QA_CHAIN_PROMPT = hub.pull("rlm/rag-prompt-llama") + + + # LLM + llm = Ollama(model="llama2-uncensored", + verbose=True, + callback_manager=CallbackManager([StreamingStdOutCallbackHandler()])) + print(f"Loaded LLM model {llm.model}") + + # QA chain + from langchain.chains import RetrievalQA + qa_chain = RetrievalQA.from_chain_type( + llm, + retriever=vectorstore.as_retriever(), + chain_type_kwargs={"prompt": QA_CHAIN_PROMPT}, + + ) + + # Ask a question + question = f"summarize what this blog is trying to say? {url}?" + result = qa_chain({"query": question}) + + # print(result) + + + +if __name__ == "__main__": main() \ No newline at end of file diff --git a/src/test.py b/src/test.py index 94bf55a..542c7b0 100644 --- a/src/test.py +++ b/src/test.py @@ -1,10 +1,10 @@ -from langchain.llms import Ollama -from langchain.callbacks.manager import CallbackManager -from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler - -llm = Ollama( - base_url="http://localhost:11434", - model="llama2-uncensored", - callback_manager = CallbackManager([StreamingStdOutCallbackHandler()])) - +from langchain.llms import Ollama +from langchain.callbacks.manager import CallbackManager +from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler + +llm = Ollama( + base_url="http://localhost:11434", + model="llama2-uncensored", + callback_manager = CallbackManager([StreamingStdOutCallbackHandler()])) + llm("hello:") \ No newline at end of file