Spaces:
Runtime error
Runtime error
added patient data
Browse files- app.py +18 -17
- data/patients.json +47 -0
- prompts/patient.prompt +5 -7
app.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 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
|
|
@@ -10,14 +9,15 @@ 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 |
|
|
@@ -25,9 +25,15 @@ 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 |
|
|
@@ -37,22 +43,17 @@ def run_text_prompt(message, chat_history):
|
|
| 37 |
return "", chat_history
|
| 38 |
|
| 39 |
|
| 40 |
-
def run_audio_prompt(audio, chat_history):
|
| 41 |
-
|
| 42 |
-
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 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()
|
|
|
|
| 1 |
from pathlib import Path
|
| 2 |
|
| 3 |
from dotenv import load_dotenv
|
|
|
|
| 4 |
load_dotenv()
|
| 5 |
|
| 6 |
from langchain.chains import LLMChain
|
|
|
|
| 9 |
import gradio as gr
|
| 10 |
from elevenlabs import generate, play
|
| 11 |
from pathlib import Path
|
| 12 |
+
import json
|
| 13 |
|
| 14 |
+
# import whisper
|
| 15 |
|
| 16 |
+
# model = whisper.load_model("base", device="cuda")
|
| 17 |
|
| 18 |
|
| 19 |
prompt = PromptTemplate(
|
| 20 |
+
input_variables=["patient", "user_input"],
|
| 21 |
template=Path("prompts/patient.prompt").read_text(),
|
| 22 |
)
|
| 23 |
|
|
|
|
| 25 |
|
| 26 |
chain = LLMChain(llm=llm, prompt=prompt)
|
| 27 |
|
| 28 |
+
with open("data/patients.json") as f:
|
| 29 |
+
patiens = json.load(f)
|
| 30 |
+
|
| 31 |
+
patient = patiens[0]
|
| 32 |
+
|
| 33 |
+
print(patient)
|
| 34 |
|
| 35 |
def run_text_prompt(message, chat_history):
|
| 36 |
+
bot_message = chain.run(patient=patient, user_input=message)
|
| 37 |
|
| 38 |
# audio = generate(text=bot_message, voice="Bella")
|
| 39 |
|
|
|
|
| 43 |
return "", chat_history
|
| 44 |
|
| 45 |
|
| 46 |
+
# def run_audio_prompt(audio, chat_history):
|
| 47 |
+
# if audio is None:
|
| 48 |
+
# return None, chat_history
|
| 49 |
|
| 50 |
+
# message_transcription = model.transcribe(audio)["text"]
|
| 51 |
+
# _, chat_history = run_text_prompt(message_transcription, chat_history)
|
| 52 |
+
# return None, chat_history
|
| 53 |
|
| 54 |
|
| 55 |
with gr.Blocks() as demo:
|
| 56 |
+
gr.Markdown(f"```json\n{json.dumps(patient)}```")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
chatbot = gr.Chatbot()
|
| 58 |
|
| 59 |
msg = gr.Textbox()
|
data/patients.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"presentingComplaint": "Abdominal pain",
|
| 4 |
+
"matchedCondition": "Gastritis",
|
| 5 |
+
"name": "Emma Thompson",
|
| 6 |
+
"age": 28,
|
| 7 |
+
"characterSummary": "Spirited graphic designer, curious, empathetic",
|
| 8 |
+
"levelOfUnderstanding": 2,
|
| 9 |
+
"rangeOfMedicalUnderstanding": "Limited knowledge of common illnesses"
|
| 10 |
+
},
|
| 11 |
+
{
|
| 12 |
+
"presentingComplaint": "Chest pain",
|
| 13 |
+
"matchedCondition": "Angina",
|
| 14 |
+
"name": "James Wilson",
|
| 15 |
+
"age": 45,
|
| 16 |
+
"characterSummary": "Seasoned entrepreneur, strategic, mentoring spirit",
|
| 17 |
+
"levelOfUnderstanding": 4,
|
| 18 |
+
"rangeOfMedicalUnderstanding": "Basic understanding of health and wellness"
|
| 19 |
+
},
|
| 20 |
+
{
|
| 21 |
+
"presentingComplaint": "Headache",
|
| 22 |
+
"matchedCondition": "Migraine",
|
| 23 |
+
"name": "Olivia Patel",
|
| 24 |
+
"age": 52,
|
| 25 |
+
"characterSummary": "Compassionate nurse, nurturing, animal lover",
|
| 26 |
+
"levelOfUnderstanding": 8,
|
| 27 |
+
"rangeOfMedicalUnderstanding": "Proficient in healthcare terminology"
|
| 28 |
+
},
|
| 29 |
+
{
|
| 30 |
+
"presentingComplaint": "Shortness of breath",
|
| 31 |
+
"matchedCondition": "Asthma",
|
| 32 |
+
"name": "Noah Collins",
|
| 33 |
+
"age": 36,
|
| 34 |
+
"characterSummary": "Adventurous thrill-seeker, introspective",
|
| 35 |
+
"levelOfUnderstanding": 2,
|
| 36 |
+
"rangeOfMedicalUnderstanding": "Limited understanding of medical issues"
|
| 37 |
+
},
|
| 38 |
+
{
|
| 39 |
+
"presentingComplaint": "Fever",
|
| 40 |
+
"matchedCondition": "Influenza",
|
| 41 |
+
"name": "Ava Mitchell",
|
| 42 |
+
"age": 19,
|
| 43 |
+
"characterSummary": "Ambitious computer science student, talented pianist",
|
| 44 |
+
"levelOfUnderstanding": 3,
|
| 45 |
+
"rangeOfMedicalUnderstanding": "Familiar with basic medical concepts"
|
| 46 |
+
}
|
| 47 |
+
]
|
prompts/patient.prompt
CHANGED
|
@@ -1,12 +1,10 @@
|
|
| 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.
|
| 2 |
-
Your persona is:
|
| 3 |
|
| 4 |
-
|
| 5 |
-
Age: 28
|
| 6 |
-
Present complain: Abdominal pain
|
| 7 |
-
Matched Condition: Gastritis
|
| 8 |
|
| 9 |
-
Please
|
|
|
|
|
|
|
| 10 |
|
| 11 |
Doctor: {user_input}
|
| 12 |
Patient:
|
|
|
|
| 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. Your persona is:
|
|
|
|
| 2 |
|
| 3 |
+
{patient}
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
Please reply using `presentingComplaint`. You should also use `characterSummary` to impersonate the patient. `levelOfUnderstanding` is between 0 and 10 and represent the level of the patient in medicine. A low number indicate somebody who is not familiar with medical terminology.
|
| 6 |
+
|
| 7 |
+
Send only one reply
|
| 8 |
|
| 9 |
Doctor: {user_input}
|
| 10 |
Patient:
|