Francesco commited on
Commit
6295354
0 Parent(s):

first version

Browse files
Files changed (4) hide show
  1. .gitignore +162 -0
  2. app.py +67 -0
  3. prompts/patient.prompt +12 -0
  4. requirements.txt +5 -0
.gitignore ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ours
2
+ .env
3
+ # Byte-compiled / optimized / DLL files
4
+ __pycache__/
5
+ *.py[cod]
6
+ *$py.class
7
+
8
+ # C extensions
9
+ *.so
10
+
11
+ # Distribution / packaging
12
+ .Python
13
+ build/
14
+ develop-eggs/
15
+ dist/
16
+ downloads/
17
+ eggs/
18
+ .eggs/
19
+ lib/
20
+ lib64/
21
+ parts/
22
+ sdist/
23
+ var/
24
+ wheels/
25
+ share/python-wheels/
26
+ *.egg-info/
27
+ .installed.cfg
28
+ *.egg
29
+ MANIFEST
30
+
31
+ # PyInstaller
32
+ # Usually these files are written by a python script from a template
33
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
34
+ *.manifest
35
+ *.spec
36
+
37
+ # Installer logs
38
+ pip-log.txt
39
+ pip-delete-this-directory.txt
40
+
41
+ # Unit test / coverage reports
42
+ htmlcov/
43
+ .tox/
44
+ .nox/
45
+ .coverage
46
+ .coverage.*
47
+ .cache
48
+ nosetests.xml
49
+ coverage.xml
50
+ *.cover
51
+ *.py,cover
52
+ .hypothesis/
53
+ .pytest_cache/
54
+ cover/
55
+
56
+ # Translations
57
+ *.mo
58
+ *.pot
59
+
60
+ # Django stuff:
61
+ *.log
62
+ local_settings.py
63
+ db.sqlite3
64
+ db.sqlite3-journal
65
+
66
+ # Flask stuff:
67
+ instance/
68
+ .webassets-cache
69
+
70
+ # Scrapy stuff:
71
+ .scrapy
72
+
73
+ # Sphinx documentation
74
+ docs/_build/
75
+
76
+ # PyBuilder
77
+ .pybuilder/
78
+ target/
79
+
80
+ # Jupyter Notebook
81
+ .ipynb_checkpoints
82
+
83
+ # IPython
84
+ profile_default/
85
+ ipython_config.py
86
+
87
+ # pyenv
88
+ # For a library or package, you might want to ignore these files since the code is
89
+ # intended to run in multiple environments; otherwise, check them in:
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
+ # poetry
100
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
101
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
102
+ # commonly ignored for libraries.
103
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
104
+ #poetry.lock
105
+
106
+ # pdm
107
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
108
+ #pdm.lock
109
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
110
+ # in version control.
111
+ # https://pdm.fming.dev/#use-with-ide
112
+ .pdm.toml
113
+
114
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
115
+ __pypackages__/
116
+
117
+ # Celery stuff
118
+ celerybeat-schedule
119
+ celerybeat.pid
120
+
121
+ # SageMath parsed files
122
+ *.sage.py
123
+
124
+ # Environments
125
+ .env
126
+ .venv
127
+ env/
128
+ venv/
129
+ ENV/
130
+ env.bak/
131
+ venv.bak/
132
+
133
+ # Spyder project settings
134
+ .spyderproject
135
+ .spyproject
136
+
137
+ # Rope project settings
138
+ .ropeproject
139
+
140
+ # mkdocs documentation
141
+ /site
142
+
143
+ # mypy
144
+ .mypy_cache/
145
+ .dmypy.json
146
+ dmypy.json
147
+
148
+ # Pyre type checker
149
+ .pyre/
150
+
151
+ # pytype static type analyzer
152
+ .pytype/
153
+
154
+ # Cython debug symbols
155
+ cython_debug/
156
+
157
+ # PyCharm
158
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
159
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
160
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
161
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
162
+ #.idea/
app.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+
3
+ from dotenv import load_dotenv
4
+ import torch
5
+ load_dotenv()
6
+
7
+ from langchain.chains import LLMChain
8
+ from langchain.prompts import PromptTemplate
9
+ from langchain.chat_models import ChatOpenAI
10
+ import gradio as gr
11
+ from elevenlabs import generate, play
12
+ from pathlib import Path
13
+
14
+ import whisper
15
+
16
+ model = whisper.load_model("base", device="cuda")
17
+
18
+
19
+ prompt = PromptTemplate(
20
+ input_variables=["user_input"],
21
+ template=Path("prompts/patient.prompt").read_text(),
22
+ )
23
+
24
+ llm = ChatOpenAI(temperature=0.7)
25
+
26
+ chain = LLMChain(llm=llm, prompt=prompt)
27
+
28
+
29
+ def run_text_prompt(message, chat_history):
30
+ bot_message = chain.run(user_input=message)
31
+
32
+ # audio = generate(text=bot_message, voice="Bella")
33
+
34
+ # play(audio, notebook=True)
35
+
36
+ chat_history.append((message, bot_message))
37
+ return "", chat_history
38
+
39
+
40
+ def run_audio_prompt(audio, chat_history):
41
+ if audio is None:
42
+ return None, chat_history
43
+
44
+ message_transcription = model.transcribe(audio)["text"]
45
+ _, chat_history = run_text_prompt(message_transcription, chat_history)
46
+ return None, chat_history
47
+
48
+
49
+ with gr.Blocks() as demo:
50
+ gr.Markdown("""
51
+ Name: Emma Thompson
52
+ Age: 28
53
+ Present complain: Abdominal pain
54
+ Matched Condition: Gastritis
55
+ """)
56
+ chatbot = gr.Chatbot()
57
+
58
+ msg = gr.Textbox()
59
+ msg.submit(run_text_prompt, [msg, chatbot], [msg, chatbot])
60
+
61
+ with gr.Row():
62
+ audio = gr.Audio(source="microphone", type="filepath")
63
+
64
+ send_audio_button = gr.Button("Send Audio", interactive=True)
65
+ send_audio_button.click(run_audio_prompt, [audio, chatbot], [audio, chatbot])
66
+
67
+ demo.launch(debug=True)
prompts/patient.prompt ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ You will act like a patient with a given persona and a present complain. I will act as a doctor trying to understand your condition by asking question. Please reply based on your complain.
2
+ Your persona is:
3
+
4
+ Name: Emma Thompson
5
+ Age: 28
6
+ Present complain: Abdominal pain
7
+ Matched Condition: Gastritis
8
+
9
+ Please, send only one reply
10
+
11
+ Doctor: {user_input}
12
+ Patient:
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio
2
+ openai
3
+ elevenlabs
4
+ openai-whisper
5
+ python-dotenv