textToSQL commited on
Commit
7d80176
0 Parent(s):

Duplicate from textToSQL/talk_to_NP

Browse files
Files changed (4) hide show
  1. .gitattributes +31 -0
  2. README.md +14 -0
  3. app.py +124 -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/talk_to_NP
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 following a patient's visit. \
44
+ Extract the following information from the transcription, replace curly brackets with relevant extracted information, and present as follows, one category per line: \
45
+
46
+ Date of Visit: {}
47
+ Claimant: {}
48
+ Client/Employer: {}
49
+ Claim #: {}
50
+ DOI (Date of Injury): {}
51
+ Provider: {}
52
+ Diagnosis Treated: {}
53
+ Subjective findings: {}
54
+ Objective Findings: {}
55
+ Treatment plan: {}
56
+ Medications: {}
57
+ RTW (Return to Work) Status: {}
58
+ Restrictions: {}
59
+ NOV (Next Office Visit): {}
60
+
61
+ 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.
62
+ """
63
+ },
64
+ {"role": "user", "content": prompt}
65
+ ]
66
+ response = openai.ChatCompletion.create(
67
+ model = model,
68
+ messages = messages,
69
+ temperature = 0,
70
+
71
+ )
72
+ return response.choices[0].message['content']
73
+
74
+ with gr.Blocks() as demo:
75
+
76
+ gr.Markdown("""
77
+ # Chat with NP <br>
78
+
79
+ This is to make life of NPs easier.
80
+ Record post visit summary in natural language, press "transcribe audio", and then "prepare a report".
81
+ """)
82
+
83
+
84
+ title = "Chat with NP"
85
+ audio = gr.Audio(source="microphone", type="filepath")
86
+
87
+ b1 = gr.Button("Transcribe audio")
88
+ b2 = gr.Button("Prepare a report")
89
+
90
+
91
+ text1 = gr.Textbox(lines=5)
92
+ text2 = gr.Textbox(lines=5)
93
+
94
+ prompt = text1
95
+
96
+
97
+
98
+ b1.click(transcribe, inputs=audio, outputs=text1)
99
+ b2.click(get_completion, inputs=text1, outputs=text2)
100
+
101
+
102
+ # b1.click(transcribe, inputs=audio, outputs=text1)
103
+ # b2.click(get_completion, inputs=prompt, outputs=text2)
104
+
105
+
106
+
107
+ demo.launch()
108
+
109
+ #demo.launch(share=True, auth=("username", "password"))
110
+
111
+ # 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.
112
+
113
+
114
+ # gr.Interface(
115
+ # title = 'OpenAI Whisper ASR Gradio Web UI',
116
+ # fn=transcribe,
117
+ # inputs=[
118
+ # gr.inputs.Audio(source="microphone", type="filepath")
119
+ # ],
120
+ # outputs=[
121
+ # "textbox"
122
+ # ],
123
+
124
+ # 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