textToSQL commited on
Commit
0e621c0
0 Parent(s):

Duplicate from textToSQL/doctor_visit

Browse files
Files changed (4) hide show
  1. .gitattributes +31 -0
  2. README.md +14 -0
  3. app.py +130 -0
  4. requirements.txt +4 -0
.gitattributes ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ftz filter=lfs diff=lfs merge=lfs -text
6
+ *.gz filter=lfs diff=lfs merge=lfs -text
7
+ *.h5 filter=lfs diff=lfs merge=lfs -text
8
+ *.joblib filter=lfs diff=lfs merge=lfs -text
9
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
10
+ *.model filter=lfs diff=lfs merge=lfs -text
11
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
12
+ *.npy filter=lfs diff=lfs merge=lfs -text
13
+ *.npz filter=lfs diff=lfs merge=lfs -text
14
+ *.onnx filter=lfs diff=lfs merge=lfs -text
15
+ *.ot filter=lfs diff=lfs merge=lfs -text
16
+ *.parquet filter=lfs diff=lfs merge=lfs -text
17
+ *.pickle filter=lfs diff=lfs merge=lfs -text
18
+ *.pkl filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pt filter=lfs diff=lfs merge=lfs -text
21
+ *.pth filter=lfs diff=lfs merge=lfs -text
22
+ *.rar filter=lfs diff=lfs merge=lfs -text
23
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
24
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
25
+ *.tflite filter=lfs diff=lfs merge=lfs -text
26
+ *.tgz filter=lfs diff=lfs merge=lfs -text
27
+ *.wasm filter=lfs diff=lfs merge=lfs -text
28
+ *.xz filter=lfs diff=lfs merge=lfs -text
29
+ *.zip filter=lfs diff=lfs merge=lfs -text
30
+ *.zst filter=lfs diff=lfs merge=lfs -text
31
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Openai Whisper Live Transcribe
3
+ emoji: 🎙
4
+ colorFrom: yellow
5
+ colorTo: gray
6
+ sdk: gradio
7
+ sdk_version: 3.3.1
8
+ app_file: app.py
9
+ pinned: false
10
+ license: mit
11
+ duplicated_from: textToSQL/doctor_visit
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import whisper
2
+ import gradio as gr
3
+ import openai
4
+ import os
5
+
6
+ openai.api_key = os.environ["OPENAI_API_KEY"]
7
+
8
+ model = whisper.load_model("small")
9
+
10
+
11
+ def transcribe(audio):
12
+ model = whisper.load_model("base")
13
+ result = model.transcribe(audio)
14
+ return result["text"]
15
+
16
+ # def transcribe(audio):
17
+
18
+ # #time.sleep(3)
19
+ # # load audio and pad/trim it to fit 30 seconds
20
+ # audio = whisper.load_audio(audio)
21
+ # audio = whisper.pad_or_trim(audio)
22
+
23
+ # # make log-Mel spectrogram and move to the same device as the model
24
+ # mel = whisper.log_mel_spectrogram(audio).to(model.device)
25
+
26
+ # # detect the spoken language
27
+ # _, probs = model.detect_language(mel)
28
+ # print(f"Detected language: {max(probs, key=probs.get)}")
29
+
30
+ # # decode the audio
31
+ # options = whisper.DecodingOptions(fp16 = False)
32
+ # result = whisper.decode(model, mel, options)
33
+ # return result.text
34
+
35
+
36
+ def process_text(input_text):
37
+ # Apply your function here to process the input text
38
+ output_text = input_text.upper()
39
+ return output_text
40
+
41
+ def get_completion(prompt, model='gpt-3.5-turbo'):
42
+ messages = [
43
+ {"role": "system", "content": """You are a world class nurse practitioner. You are provided with the transcription of a patient's recording in a non-English language prior to doctor's visit. \
44
+ Extract the following information from the transcription, replace curly brackets with relevant extracted information, and present in English as follows, one category per line: \
45
+
46
+ Demographic information: {name, age, gender, address, phone number}
47
+
48
+ Medical history: {chronic health conditions, any past surgery, any hospitalization, current medications}
49
+
50
+ Symptoms: {current symptoms, when did they start, how did they progress}
51
+
52
+ Allergies: {any known allergies, any allergic reaction to medications}
53
+
54
+ Family history: {any family members with chronic health condition, anyone in the family with a hereditary condition?}
55
+
56
+ Lifestyle factors: {typical diet, how often you exercise, smoking, drinking alcohol}
57
+
58
+ Psychosocial factors: {stress, anxiety, any mental health condition}
59
+
60
+ Review of systems: {any issues with vision or hearing, digestive issues, any problems with skin or nails, any problems with joints or muscles}
61
+
62
+ All information in the report needs to be in English only.
63
+
64
+ Only use the information from the provided transcription. Do not make up stuff. If information is not available just put "N/A" next to the relevant line.
65
+ """
66
+ },
67
+ {"role": "user", "content": prompt}
68
+ ]
69
+ response = openai.ChatCompletion.create(
70
+ model = model,
71
+ messages = messages,
72
+ temperature = 0,
73
+
74
+ )
75
+ return response.choices[0].message['content']
76
+
77
+ with gr.Blocks() as demo:
78
+
79
+ gr.Markdown("""
80
+ # Meet your doctor <br>
81
+
82
+ This is to make life of non-English speaking patients easier.
83
+ Describe your complaints and symptoms in your native language , have it emailed to your doctor prior to your visit.
84
+ Information that is useful to include: your name, age, gender, address, phone number, medical history, symptoms, allergies, family medical history, lifestyle factors.
85
+ Have it all recorded, transcribed, and presented in a standard form.
86
+ """)
87
+
88
+
89
+ title = "Chat with NP"
90
+ audio = gr.Audio(source="microphone", type="filepath")
91
+
92
+ b1 = gr.Button("Transcribe audio")
93
+ b2 = gr.Button("Prepare a report in English")
94
+ b3 = gr.Button("Email report to your doctor")
95
+
96
+
97
+ text1 = gr.Textbox(lines=5)
98
+ text2 = gr.Textbox(lines=5)
99
+
100
+ prompt = text1
101
+
102
+
103
+
104
+ b1.click(transcribe, inputs=audio, outputs=text1)
105
+ b2.click(get_completion, inputs=text1, outputs=text2)
106
+
107
+
108
+ # b1.click(transcribe, inputs=audio, outputs=text1)
109
+ # b2.click(get_completion, inputs=prompt, outputs=text2)
110
+
111
+
112
+
113
+ demo.launch()
114
+
115
+ #demo.launch(share=True, auth=("username", "password"))
116
+
117
+ # In this example, the process_text function just converts the input text to uppercase, but you can replace it with your desired function. The Gradio Blocks interface will have two buttons: "Transcribe audio" and "Process text". The first button transcribes the audio and fills the first textbox, and the second button processes the text from the first textbox and fills the second textbox.
118
+
119
+
120
+ # gr.Interface(
121
+ # title = 'OpenAI Whisper ASR Gradio Web UI',
122
+ # fn=transcribe,
123
+ # inputs=[
124
+ # gr.inputs.Audio(source="microphone", type="filepath")
125
+ # ],
126
+ # outputs=[
127
+ # "textbox"
128
+ # ],
129
+
130
+ # live=True).launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ tensorflow
2
+ openai
3
+ git+https://github.com/openai/whisper.git
4
+ gradio==3.14.0