Spaces:
Build error
Build error
Deploy AI Doctor Assistant
Browse files- .gitignore +171 -0
- LICENSE +21 -0
- app.py +7 -0
- brain_of_the_doctor.py +47 -0
- catract.png +0 -0
- env_variables.txt +0 -0
- requirements.txt +64 -0
- voice_of_the_doctor.py +91 -0
- voice_of_the_patient.py +67 -0
.gitignore
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Byte-compiled / optimized / DLL files
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.py[cod]
|
| 4 |
+
*$py.class
|
| 5 |
+
|
| 6 |
+
# C extensions
|
| 7 |
+
*.so
|
| 8 |
+
|
| 9 |
+
# Distribution / packaging
|
| 10 |
+
.Python
|
| 11 |
+
build/
|
| 12 |
+
develop-eggs/
|
| 13 |
+
dist/
|
| 14 |
+
downloads/
|
| 15 |
+
eggs/
|
| 16 |
+
.eggs/
|
| 17 |
+
lib/
|
| 18 |
+
lib64/
|
| 19 |
+
parts/
|
| 20 |
+
sdist/
|
| 21 |
+
var/
|
| 22 |
+
wheels/
|
| 23 |
+
share/python-wheels/
|
| 24 |
+
*.egg-info/
|
| 25 |
+
.installed.cfg
|
| 26 |
+
*.egg
|
| 27 |
+
MANIFEST
|
| 28 |
+
|
| 29 |
+
# PyInstaller
|
| 30 |
+
# Usually these files are written by a python script from a template
|
| 31 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
| 32 |
+
*.manifest
|
| 33 |
+
*.spec
|
| 34 |
+
|
| 35 |
+
# Installer logs
|
| 36 |
+
pip-log.txt
|
| 37 |
+
pip-delete-this-directory.txt
|
| 38 |
+
|
| 39 |
+
# Unit test / coverage reports
|
| 40 |
+
htmlcov/
|
| 41 |
+
.tox/
|
| 42 |
+
.nox/
|
| 43 |
+
.coverage
|
| 44 |
+
.coverage.*
|
| 45 |
+
.cache
|
| 46 |
+
nosetests.xml
|
| 47 |
+
coverage.xml
|
| 48 |
+
*.cover
|
| 49 |
+
*.py,cover
|
| 50 |
+
.hypothesis/
|
| 51 |
+
.pytest_cache/
|
| 52 |
+
cover/
|
| 53 |
+
|
| 54 |
+
# Translations
|
| 55 |
+
*.mo
|
| 56 |
+
*.pot
|
| 57 |
+
|
| 58 |
+
# Django stuff:
|
| 59 |
+
*.log
|
| 60 |
+
local_settings.py
|
| 61 |
+
db.sqlite3
|
| 62 |
+
db.sqlite3-journal
|
| 63 |
+
|
| 64 |
+
# Flask stuff:
|
| 65 |
+
instance/
|
| 66 |
+
.webassets-cache
|
| 67 |
+
|
| 68 |
+
# Scrapy stuff:
|
| 69 |
+
.scrapy
|
| 70 |
+
|
| 71 |
+
# Sphinx documentation
|
| 72 |
+
docs/_build/
|
| 73 |
+
|
| 74 |
+
# PyBuilder
|
| 75 |
+
.pybuilder/
|
| 76 |
+
target/
|
| 77 |
+
|
| 78 |
+
# Jupyter Notebook
|
| 79 |
+
.ipynb_checkpoints
|
| 80 |
+
|
| 81 |
+
# IPython
|
| 82 |
+
profile_default/
|
| 83 |
+
ipython_config.py
|
| 84 |
+
|
| 85 |
+
# pyenv
|
| 86 |
+
# For a library or package, you might want to ignore these files since the code is
|
| 87 |
+
# intended to run in multiple environments; otherwise, check them in:
|
| 88 |
+
# .python-version
|
| 89 |
+
|
| 90 |
+
# pipenv
|
| 91 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
| 92 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
| 93 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
| 94 |
+
# install all needed dependencies.
|
| 95 |
+
#Pipfile.lock
|
| 96 |
+
|
| 97 |
+
# UV
|
| 98 |
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
| 99 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
| 100 |
+
# commonly ignored for libraries.
|
| 101 |
+
#uv.lock
|
| 102 |
+
|
| 103 |
+
# poetry
|
| 104 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
| 105 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
| 106 |
+
# commonly ignored for libraries.
|
| 107 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
| 108 |
+
#poetry.lock
|
| 109 |
+
|
| 110 |
+
# pdm
|
| 111 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
| 112 |
+
#pdm.lock
|
| 113 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
| 114 |
+
# in version control.
|
| 115 |
+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
| 116 |
+
.pdm.toml
|
| 117 |
+
.pdm-python
|
| 118 |
+
.pdm-build/
|
| 119 |
+
|
| 120 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
| 121 |
+
__pypackages__/
|
| 122 |
+
|
| 123 |
+
# Celery stuff
|
| 124 |
+
celerybeat-schedule
|
| 125 |
+
celerybeat.pid
|
| 126 |
+
|
| 127 |
+
# SageMath parsed files
|
| 128 |
+
*.sage.py
|
| 129 |
+
|
| 130 |
+
# Environments
|
| 131 |
+
.env
|
| 132 |
+
.venv
|
| 133 |
+
env/
|
| 134 |
+
venv/
|
| 135 |
+
ENV/
|
| 136 |
+
env.bak/
|
| 137 |
+
venv.bak/
|
| 138 |
+
|
| 139 |
+
# Spyder project settings
|
| 140 |
+
.spyderproject
|
| 141 |
+
.spyproject
|
| 142 |
+
|
| 143 |
+
# Rope project settings
|
| 144 |
+
.ropeproject
|
| 145 |
+
|
| 146 |
+
# mkdocs documentation
|
| 147 |
+
/site
|
| 148 |
+
|
| 149 |
+
# mypy
|
| 150 |
+
.mypy_cache/
|
| 151 |
+
.dmypy.json
|
| 152 |
+
dmypy.json
|
| 153 |
+
|
| 154 |
+
# Pyre type checker
|
| 155 |
+
.pyre/
|
| 156 |
+
|
| 157 |
+
# pytype static type analyzer
|
| 158 |
+
.pytype/
|
| 159 |
+
|
| 160 |
+
# Cython debug symbols
|
| 161 |
+
cython_debug/
|
| 162 |
+
|
| 163 |
+
# PyCharm
|
| 164 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
| 165 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
| 166 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
| 167 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
| 168 |
+
#.idea/
|
| 169 |
+
|
| 170 |
+
# PyPI configuration file
|
| 171 |
+
.pypirc
|
LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2025 SALONI SINGH
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
app.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
def greet(name):
|
| 4 |
+
return "Hello " + name + "!!"
|
| 5 |
+
|
| 6 |
+
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 7 |
+
demo.launch()
|
brain_of_the_doctor.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# setup groq api key
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
| 6 |
+
# print(GROQ_API_KEY)
|
| 7 |
+
|
| 8 |
+
#step 2- convert image to required format
|
| 9 |
+
|
| 10 |
+
import base64
|
| 11 |
+
|
| 12 |
+
def encode_image(image_path):
|
| 13 |
+
image_file=open(image_path, "rb")
|
| 14 |
+
return base64.b64encode(image_file.read()).decode('utf-8')
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
#step 3- Setup Multimodal LLM
|
| 18 |
+
from groq import Groq
|
| 19 |
+
|
| 20 |
+
client = Groq()
|
| 21 |
+
model = "llama-3.2-90b-vision-preview"
|
| 22 |
+
query="Is there something wrong with my eye?"
|
| 23 |
+
|
| 24 |
+
def analyze_image_with_query(query, model, encoded_image):
|
| 25 |
+
client=Groq()
|
| 26 |
+
messages=[
|
| 27 |
+
{
|
| 28 |
+
"role": "user",
|
| 29 |
+
"content": [
|
| 30 |
+
{
|
| 31 |
+
"type": "text",
|
| 32 |
+
"text": query
|
| 33 |
+
},
|
| 34 |
+
{
|
| 35 |
+
"type": "image_url",
|
| 36 |
+
"image_url": {
|
| 37 |
+
"url": f"data:image/jpeg;base64,{encoded_image}",
|
| 38 |
+
},
|
| 39 |
+
},
|
| 40 |
+
],
|
| 41 |
+
}]
|
| 42 |
+
chat_completion=client.chat.completions.create(
|
| 43 |
+
messages=messages,
|
| 44 |
+
model=model
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
return chat_completion.choices[0].message.content
|
catract.png
ADDED
|
env_variables.txt
ADDED
|
Binary file (10.2 kB). View file
|
|
|
requirements.txt
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
-i https://pypi.org/simple
|
| 2 |
+
aiofiles==23.2.1; python_version >= '3.7'
|
| 3 |
+
annotated-types==0.7.0; python_version >= '3.8'
|
| 4 |
+
anyio==4.8.0; python_version >= '3.9'
|
| 5 |
+
certifi==2024.12.14; python_version >= '3.6'
|
| 6 |
+
charset-normalizer==3.4.1; python_version >= '3.7'
|
| 7 |
+
click==8.1.8; python_version >= '3.7'
|
| 8 |
+
distro==1.9.0; python_version >= '3.6'
|
| 9 |
+
elevenlabs==1.50.3; python_version >= '3.8' and python_version < '4.0'
|
| 10 |
+
fastapi==0.115.6; python_version >= '3.8'
|
| 11 |
+
ffmpy==0.5.0; python_version >= '3.8' and python_version < '4.0'
|
| 12 |
+
filelock==3.16.1; python_version >= '3.8'
|
| 13 |
+
fsspec==2024.12.0; python_version >= '3.8'
|
| 14 |
+
gradio==5.12.0; python_version >= '3.10'
|
| 15 |
+
gradio-client==1.5.4; python_version >= '3.10'
|
| 16 |
+
groq==0.15.0; python_version >= '3.8'
|
| 17 |
+
gtts==2.5.4; python_version >= '3.7'
|
| 18 |
+
h11==0.14.0; python_version >= '3.7'
|
| 19 |
+
httpcore==1.0.7; python_version >= '3.8'
|
| 20 |
+
httpx==0.28.1; python_version >= '3.8'
|
| 21 |
+
huggingface-hub==0.27.1; python_full_version >= '3.8.0'
|
| 22 |
+
idna==3.10; python_version >= '3.6'
|
| 23 |
+
jinja2==3.1.5; python_version >= '3.7'
|
| 24 |
+
markdown-it-py==3.0.0; python_version >= '3.8'
|
| 25 |
+
markupsafe==2.1.5; python_version >= '3.7'
|
| 26 |
+
mdurl==0.1.2; python_version >= '3.7'
|
| 27 |
+
numpy==2.2.1; python_version >= '3.10'
|
| 28 |
+
orjson==3.10.14; python_version >= '3.8'
|
| 29 |
+
packaging==24.2; python_version >= '3.8'
|
| 30 |
+
pandas==2.2.3; python_version >= '3.9'
|
| 31 |
+
pillow==11.1.0; python_version >= '3.9'
|
| 32 |
+
pyaudio==0.2.14
|
| 33 |
+
pydantic==2.10.5; python_version >= '3.8'
|
| 34 |
+
pydantic-core==2.27.2; python_version >= '3.8'
|
| 35 |
+
pydub==0.25.1
|
| 36 |
+
pygments==2.19.1; python_version >= '3.8'
|
| 37 |
+
python-dateutil==2.9.0.post0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
|
| 38 |
+
python-multipart==0.0.20; python_version >= '3.8'
|
| 39 |
+
pytz==2024.2
|
| 40 |
+
pyyaml==6.0.2; python_version >= '3.8'
|
| 41 |
+
requests==2.32.3; python_version >= '3.8'
|
| 42 |
+
rich==13.9.4; python_full_version >= '3.8.0'
|
| 43 |
+
ruff==0.9.1; sys_platform != 'emscripten'
|
| 44 |
+
safehttpx==0.1.6; python_version >= '3.10'
|
| 45 |
+
semantic-version==2.10.0; python_version >= '2.7'
|
| 46 |
+
shellingham==1.5.4; python_version >= '3.7'
|
| 47 |
+
six==1.17.0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
|
| 48 |
+
sniffio==1.3.1; python_version >= '3.7'
|
| 49 |
+
speechrecognition==3.13.0; python_version >= '3.9'
|
| 50 |
+
starlette==0.41.3; sys_platform != 'emscripten'
|
| 51 |
+
tomlkit==0.13.2; python_version >= '3.8'
|
| 52 |
+
tqdm==4.67.1; python_version >= '3.7'
|
| 53 |
+
typer==0.15.1; sys_platform != 'emscripten'
|
| 54 |
+
typing-extensions==4.12.2; python_version >= '3.8'
|
| 55 |
+
tzdata==2024.2; python_version >= '2'
|
| 56 |
+
urllib3==2.3.0; python_version >= '3.9'
|
| 57 |
+
uvicorn==0.34.0; sys_platform != 'emscripten'
|
| 58 |
+
websockets==14.1; python_version >= '3.9'
|
| 59 |
+
python-dotenv
|
| 60 |
+
streamlit
|
| 61 |
+
pydub
|
| 62 |
+
requests
|
| 63 |
+
openai
|
| 64 |
+
gunicorn
|
voice_of_the_doctor.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# step1 - > setup text to speech -TTS-Model (gTTS and ElevenLabs)
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
from gtts import gTTS
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def text_to_speech_with_gtts_old(input_text, output_filepath):
|
| 8 |
+
language = "en"
|
| 9 |
+
|
| 10 |
+
audioobj = gTTS(text=input_text, lang=language, slow=False)
|
| 11 |
+
audioobj.save(output_filepath)
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
input_text = "Hi this is SALONI SINGH, HOPE YOU ARE DOING WELL !"
|
| 15 |
+
text_to_speech_with_gtts_old(input_text=input_text, output_filepath="gtts_testing.mp3")
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
# Step1b: Setup Text to Speech–TTS–model with ElevenLabs
|
| 19 |
+
import elevenlabs
|
| 20 |
+
from elevenlabs.client import ElevenLabs
|
| 21 |
+
|
| 22 |
+
ELEVENLABS_API_KEY = os.getenv("ELEVENLABS_API_KEY")
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def text_to_speech_with_elevenlabs_old(input_text, output_filepath):
|
| 26 |
+
client = ElevenLabs(api_key=ELEVENLABS_API_KEY)
|
| 27 |
+
audio = client.generate(
|
| 28 |
+
text=input_text,
|
| 29 |
+
voice="Rachel",
|
| 30 |
+
output_format="mp3_22050_32",
|
| 31 |
+
model="eleven_turbo_v2",
|
| 32 |
+
)
|
| 33 |
+
elevenlabs.save(audio, output_filepath)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
#text_to_speech_with_elevenlabs_old(input_text, output_filepath="elevenlabs_testing.mp3")
|
| 37 |
+
|
| 38 |
+
# Step2: Use Model for Text output to Voice
|
| 39 |
+
import subprocess
|
| 40 |
+
import platform
|
| 41 |
+
|
| 42 |
+
def text_to_speech_with_gtts(input_text, output_filepath):
|
| 43 |
+
language="en"
|
| 44 |
+
|
| 45 |
+
audioobj= gTTS(
|
| 46 |
+
text=input_text,
|
| 47 |
+
lang=language,
|
| 48 |
+
slow=False
|
| 49 |
+
)
|
| 50 |
+
audioobj.save(output_filepath)
|
| 51 |
+
os_name = platform.system()
|
| 52 |
+
try:
|
| 53 |
+
if os_name == "Darwin": # macOS
|
| 54 |
+
subprocess.run(['afplay', output_filepath])
|
| 55 |
+
elif os_name == "Windows": # Windows
|
| 56 |
+
subprocess.run(['powershell', '-c', f'(New-Object Media.SoundPlayer "{output_filepath}").PlaySync();'])
|
| 57 |
+
elif os_name == "Linux": # Linux
|
| 58 |
+
subprocess.run(['aplay', output_filepath]) # Alternative: use 'mpg123' or 'ffplay'
|
| 59 |
+
else:
|
| 60 |
+
raise OSError("Unsupported operating system")
|
| 61 |
+
except Exception as e:
|
| 62 |
+
print(f"An error occurred while trying to play the audio: {e}")
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
input_text="Hi this a Good Day, Good Monney!"
|
| 66 |
+
# text_to_speech_with_gtts(input_text=input_text, output_filepath="gtts_testing_autoplay.mp3")
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def text_to_speech_with_elevenlabs(input_text, output_filepath):
|
| 70 |
+
client=ElevenLabs(api_key=ELEVENLABS_API_KEY)
|
| 71 |
+
audio=client.generate(
|
| 72 |
+
text= input_text,
|
| 73 |
+
voice= "Aria",
|
| 74 |
+
output_format= "mp3_22050_32",
|
| 75 |
+
model= "eleven_turbo_v2"
|
| 76 |
+
)
|
| 77 |
+
elevenlabs.save(audio, output_filepath)
|
| 78 |
+
os_name = platform.system()
|
| 79 |
+
try:
|
| 80 |
+
if os_name == "Darwin": # macOS
|
| 81 |
+
subprocess.run(['afplay', output_filepath])
|
| 82 |
+
elif os_name == "Windows": # Windows
|
| 83 |
+
subprocess.run(['powershell', '-c', f'(New-Object Media.SoundPlayer "{output_filepath}").PlaySync();'])
|
| 84 |
+
elif os_name == "Linux": # Linux
|
| 85 |
+
subprocess.run(['aplay', output_filepath]) # Alternative: use 'mpg123' or 'ffplay'
|
| 86 |
+
else:
|
| 87 |
+
raise OSError("Unsupported operating system")
|
| 88 |
+
except Exception as e:
|
| 89 |
+
print(f"An error occurred while trying to play the audio: {e}")
|
| 90 |
+
|
| 91 |
+
# text_to_speech_with_elevenlabs(input_text, output_filepath="elevenlabs_testing_autoplay.mp3")
|
voice_of_the_patient.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
#Step1: Setup Audio recorder (ffmpeg & portaudio)
|
| 3 |
+
# ffmpeg, portaudio, pyaudio
|
| 4 |
+
import logging
|
| 5 |
+
import speech_recognition as sr
|
| 6 |
+
from pydub import AudioSegment
|
| 7 |
+
from io import BytesIO
|
| 8 |
+
|
| 9 |
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 10 |
+
|
| 11 |
+
def record_audio(file_path, timeout=20, phrase_time_limit=None):
|
| 12 |
+
"""
|
| 13 |
+
Simplified function to record audio from the microphone and save it as an MP3 file.
|
| 14 |
+
|
| 15 |
+
Args:
|
| 16 |
+
file_path (str): Path to save the recorded audio file.
|
| 17 |
+
timeout (int): Maximum time to wait for a phrase to start (in seconds).
|
| 18 |
+
phrase_time_lfimit (int): Maximum time for the phrase to be recorded (in seconds).
|
| 19 |
+
"""
|
| 20 |
+
recognizer = sr.Recognizer()
|
| 21 |
+
|
| 22 |
+
try:
|
| 23 |
+
with sr.Microphone() as source:
|
| 24 |
+
logging.info("Adjusting for ambient noise...")
|
| 25 |
+
recognizer.adjust_for_ambient_noise(source, duration=1)
|
| 26 |
+
logging.info("Start speaking now...")
|
| 27 |
+
|
| 28 |
+
# Record the audio
|
| 29 |
+
audio_data = recognizer.listen(source, timeout=timeout, phrase_time_limit=phrase_time_limit)
|
| 30 |
+
logging.info("Recording complete.")
|
| 31 |
+
|
| 32 |
+
# Convert the recorded audio to an MP3 file
|
| 33 |
+
wav_data = audio_data.get_wav_data()
|
| 34 |
+
audio_segment = AudioSegment.from_wav(BytesIO(wav_data))
|
| 35 |
+
audio_segment.export(file_path, format="mp3", bitrate="128k")
|
| 36 |
+
|
| 37 |
+
logging.info(f"Audio saved to {file_path}")
|
| 38 |
+
|
| 39 |
+
except Exception as e:
|
| 40 |
+
logging.error(f"An error occurred: {e}")
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
# step 2-> setup speech to text-sst -model for transcription.
|
| 44 |
+
audio_filepath="patient_voice_test_for_patient.mp3"
|
| 45 |
+
# record_audio(file_path=audio_filepath)
|
| 46 |
+
|
| 47 |
+
#Step2: Setup Speech to text–STT–model for transcription
|
| 48 |
+
import os
|
| 49 |
+
from groq import Groq
|
| 50 |
+
|
| 51 |
+
GROQ_API_KEY=os.getenv("GROQ_API_KEY")
|
| 52 |
+
stt_model="whisper-large-v3"
|
| 53 |
+
|
| 54 |
+
def transcribe_with_groq(stt_model, audio_filepath, GROQ_API_KEY):
|
| 55 |
+
client=Groq(api_key=GROQ_API_KEY)
|
| 56 |
+
|
| 57 |
+
audio_file=open(audio_filepath, "rb")
|
| 58 |
+
transcription=client.audio.transcriptions.create(
|
| 59 |
+
model=stt_model,
|
| 60 |
+
file=audio_file,
|
| 61 |
+
language="en"
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
return transcription.text
|
| 65 |
+
|
| 66 |
+
# ans = transcribe_with_groq(stt_model, audio_filepath, GROQ_API_KEY)
|
| 67 |
+
# print(ans)
|