Add application file
Browse files- .gitignore +134 -0
- app.py +49 -0
- environment.yml +27 -0
.gitignore
ADDED
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# other
|
2 |
+
data/
|
3 |
+
flagged/
|
4 |
+
gradio_cached_examples/
|
5 |
+
|
6 |
+
# Byte-compiled / optimized / DLL files
|
7 |
+
__pycache__/
|
8 |
+
*.py[cod]
|
9 |
+
*$py.class
|
10 |
+
|
11 |
+
# C extensions
|
12 |
+
*.so
|
13 |
+
|
14 |
+
# Distribution / packaging
|
15 |
+
.Python
|
16 |
+
build/
|
17 |
+
develop-eggs/
|
18 |
+
dist/
|
19 |
+
downloads/
|
20 |
+
eggs/
|
21 |
+
.eggs/
|
22 |
+
lib/
|
23 |
+
lib64/
|
24 |
+
parts/
|
25 |
+
sdist/
|
26 |
+
var/
|
27 |
+
wheels/
|
28 |
+
pip-wheel-metadata/
|
29 |
+
share/python-wheels/
|
30 |
+
*.egg-info/
|
31 |
+
.installed.cfg
|
32 |
+
*.egg
|
33 |
+
MANIFEST
|
34 |
+
|
35 |
+
# PyInstaller
|
36 |
+
# Usually these files are written by a python script from a template
|
37 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
38 |
+
*.manifest
|
39 |
+
*.spec
|
40 |
+
|
41 |
+
# Installer logs
|
42 |
+
pip-log.txt
|
43 |
+
pip-delete-this-directory.txt
|
44 |
+
|
45 |
+
# Unit test / coverage reports
|
46 |
+
htmlcov/
|
47 |
+
.tox/
|
48 |
+
.nox/
|
49 |
+
.coverage
|
50 |
+
.coverage.*
|
51 |
+
.cache
|
52 |
+
nosetests.xml
|
53 |
+
coverage.xml
|
54 |
+
*.cover
|
55 |
+
*.py,cover
|
56 |
+
.hypothesis/
|
57 |
+
.pytest_cache/
|
58 |
+
|
59 |
+
# Translations
|
60 |
+
*.mo
|
61 |
+
*.pot
|
62 |
+
|
63 |
+
# Django stuff:
|
64 |
+
*.log
|
65 |
+
local_settings.py
|
66 |
+
db.sqlite3
|
67 |
+
db.sqlite3-journal
|
68 |
+
|
69 |
+
# Flask stuff:
|
70 |
+
instance/
|
71 |
+
.webassets-cache
|
72 |
+
|
73 |
+
# Scrapy stuff:
|
74 |
+
.scrapy
|
75 |
+
|
76 |
+
# Sphinx documentation
|
77 |
+
docs/_build/
|
78 |
+
|
79 |
+
# PyBuilder
|
80 |
+
target/
|
81 |
+
|
82 |
+
# Jupyter Notebook
|
83 |
+
.ipynb_checkpoints
|
84 |
+
|
85 |
+
# IPython
|
86 |
+
profile_default/
|
87 |
+
ipython_config.py
|
88 |
+
|
89 |
+
# pyenv
|
90 |
+
.python-version
|
91 |
+
|
92 |
+
# pipenv
|
93 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
94 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
95 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
96 |
+
# install all needed dependencies.
|
97 |
+
#Pipfile.lock
|
98 |
+
|
99 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
100 |
+
__pypackages__/
|
101 |
+
|
102 |
+
# Celery stuff
|
103 |
+
celerybeat-schedule
|
104 |
+
celerybeat.pid
|
105 |
+
|
106 |
+
# SageMath parsed files
|
107 |
+
*.sage.py
|
108 |
+
|
109 |
+
# Environments
|
110 |
+
.env
|
111 |
+
.venv
|
112 |
+
env/
|
113 |
+
venv/
|
114 |
+
ENV/
|
115 |
+
env.bak/
|
116 |
+
venv.bak/
|
117 |
+
|
118 |
+
# Spyder project settings
|
119 |
+
.spyderproject
|
120 |
+
.spyproject
|
121 |
+
|
122 |
+
# Rope project settings
|
123 |
+
.ropeproject
|
124 |
+
|
125 |
+
# mkdocs documentation
|
126 |
+
/site
|
127 |
+
|
128 |
+
# mypy
|
129 |
+
.mypy_cache/
|
130 |
+
.dmypy.json
|
131 |
+
dmypy.json
|
132 |
+
|
133 |
+
# Pyre type checker
|
134 |
+
.pyre/
|
app.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
+
from dotenv import load_dotenv, find_dotenv
|
4 |
+
import openai
|
5 |
+
from revChatGPT.V3 import Chatbot
|
6 |
+
|
7 |
+
load_dotenv(find_dotenv())
|
8 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
9 |
+
|
10 |
+
def transcribe(audio_file):
|
11 |
+
# print(audio_file)
|
12 |
+
prompt = "Umm, let me think like, hmm... Okay, here's what I'm, like, thinking. The author of this tool is Somto Muotoe. Contributors: Ireoluwa Enoch Adedugbe; Abiola Aderiye"
|
13 |
+
with open(audio_file, "rb") as f:
|
14 |
+
|
15 |
+
response = openai.Audio.transcribe("whisper-1", f, prompt=prompt)
|
16 |
+
text = response['text']
|
17 |
+
print(text)
|
18 |
+
return text
|
19 |
+
|
20 |
+
def chat_with_gpt(prompt):
|
21 |
+
chatbot = Chatbot(api_key=os.getenv("OPENAI_API_KEY"))
|
22 |
+
return chatbot.ask(prompt)
|
23 |
+
|
24 |
+
def transcribe_and_chat(audio_file):
|
25 |
+
text = transcribe(audio_file)
|
26 |
+
gpt_response = chat_with_gpt(text)
|
27 |
+
return text, gpt_response
|
28 |
+
|
29 |
+
|
30 |
+
app = gr.Interface(
|
31 |
+
fn=transcribe_and_chat,
|
32 |
+
inputs=[
|
33 |
+
gr.Audio(source="microphone", type="filepath"),
|
34 |
+
# gr.Textbox(lines=2, label="Prompt"),
|
35 |
+
],
|
36 |
+
outputs=[
|
37 |
+
gr.Textbox(lines=2, label="Transcription"),
|
38 |
+
gr.Textbox(lines=2, label="Response"),
|
39 |
+
],
|
40 |
+
|
41 |
+
title="Voice Chat with GPT-4",
|
42 |
+
description="Chat with GPT-4 Using your Voice!",
|
43 |
+
# article="<h1>Voice Chat with GPT-4</h1><p>Chat with GPT-4 Using your Voice!</p>",
|
44 |
+
# examples=["Hi, how are you?", "Is the earth the only planet with living things?"],
|
45 |
+
cache_examples=True
|
46 |
+
|
47 |
+
)
|
48 |
+
|
49 |
+
app.launch(server_port=8080, share=True)
|
environment.yml
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: voice-gpt
|
2 |
+
channels:
|
3 |
+
- pytorch
|
4 |
+
- nvidia
|
5 |
+
- conda-forge
|
6 |
+
dependencies:
|
7 |
+
- pip
|
8 |
+
- python=3.9.12
|
9 |
+
- pandas
|
10 |
+
- requests
|
11 |
+
- matplotlib
|
12 |
+
- seaborn
|
13 |
+
- pytorch
|
14 |
+
- torchvision
|
15 |
+
- torchaudio
|
16 |
+
- pytorch-cuda=11.7
|
17 |
+
- transformers
|
18 |
+
- python-dotenv
|
19 |
+
- openai
|
20 |
+
- ffmpeg
|
21 |
+
- nltk
|
22 |
+
- pip:
|
23 |
+
- openai-whisper
|
24 |
+
- faster-whisper
|
25 |
+
- gradio==3.9
|
26 |
+
- revChatGPT
|
27 |
+
- tiktoken
|