Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,45 +2,86 @@ import streamlit as st
|
|
2 |
from audiorecorder import audiorecorder
|
3 |
import openai
|
4 |
import os
|
5 |
-
import tempfile
|
6 |
-
|
7 |
-
# Nastavení OpenAI klíče
|
8 |
openai.api_key = os.environ['OPENAI_API_KEY']
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
if 'vignette' not in st.session_state:
|
26 |
st.session_state['vignette'] = ''
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
if 'length' not in st.session_state:
|
29 |
st.session_state['length'] = 0
|
30 |
|
31 |
-
|
32 |
-
st.title("AI
|
33 |
-
st.markdown(
|
|
|
34 |
st.divider()
|
35 |
|
36 |
-
# Nahrávání audia
|
37 |
audio = audiorecorder("Record", "Stop")
|
38 |
|
39 |
-
|
40 |
-
if len(audio) != st.session_state['length']:
|
41 |
st.session_state['length'] = len(audio)
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
-
|
46 |
-
st.
|
|
|
|
2 |
from audiorecorder import audiorecorder
|
3 |
import openai
|
4 |
import os
|
|
|
|
|
|
|
5 |
openai.api_key = os.environ['OPENAI_API_KEY']
|
6 |
|
7 |
+
|
8 |
+
def get_completion(messages, model="gpt-3.5-turbo"):
|
9 |
+
response = openai.ChatCompletion.create(
|
10 |
+
model=model,
|
11 |
+
messages=messages,
|
12 |
+
temperature=0)
|
13 |
+
return response.choices[0].message["content"]
|
14 |
+
|
15 |
+
|
16 |
+
def transcribe(audio_path):
|
17 |
+
audio_file = open(audio_path, "rb")
|
18 |
+
transcript = openai.Audio.transcribe("whisper-1", audio_file, filename = '1.mp3')
|
19 |
+
return transcript["text"]
|
20 |
+
|
21 |
+
|
22 |
+
def get_ddx(vignette):
|
23 |
+
messages_ddx = [
|
24 |
+
{'role': 'system', 'content': 'Jste nástroj AI asistenta lékaře. Napište sadu příkazů pro pacienta k odlišení mezi stavy. Napište pouze příkazy a zdůvodnění. Nepište žádné další informace. Nepište žádný úvod.'},
|
25 |
+
{'role': 'user', 'content': vignette}]
|
26 |
+
ddx = get_completion(messages_ddx)
|
27 |
+
return ddx
|
28 |
+
|
29 |
+
|
30 |
+
def get_orders(vignette, ddx):
|
31 |
+
messages_orders = [
|
32 |
+
{'role': 'system', 'content': 'Jste nástroj AI asistenta lékaře. Napište sadu příkazů pro pacienta k odlišení mezi stavy. Napište pouze příkazy a zdůvodnění. Nepište žádné další informace. Nepište žádný úvod.'},
|
33 |
+
{'role': 'user', 'content': f'Informace o pacientovi: {vignette}. Rozdílné diagnózy: {ddx}'}]
|
34 |
+
orders = get_completion(messages_orders)
|
35 |
+
return orders
|
36 |
+
|
37 |
+
|
38 |
if 'vignette' not in st.session_state:
|
39 |
st.session_state['vignette'] = ''
|
40 |
|
41 |
+
if 'ddx' not in st.session_state:
|
42 |
+
st.session_state['ddx'] = ''
|
43 |
+
|
44 |
+
if 'orders' not in st.session_state:
|
45 |
+
st.session_state['orders'] = ''
|
46 |
+
|
47 |
if 'length' not in st.session_state:
|
48 |
st.session_state['length'] = 0
|
49 |
|
50 |
+
|
51 |
+
st.title("AI loop for healthcare providers")
|
52 |
+
st.markdown(
|
53 |
+
"Record your patient presentation and get the differential diagnoses and orders.")
|
54 |
st.divider()
|
55 |
|
|
|
56 |
audio = audiorecorder("Record", "Stop")
|
57 |
|
58 |
+
|
59 |
+
if (len(audio) != st.session_state['length']):
|
60 |
st.session_state['length'] = len(audio)
|
61 |
+
# wav_file = open("audio.mp3", "wb")
|
62 |
+
# wav_file.write(audio.tobytes())
|
63 |
+
transcript = openai.Audio.translate_raw("whisper-1", audio.tobytes(), filename = '1.mp3')
|
64 |
+
transcript["text"]
|
65 |
+
st.session_state['vignette'] += transcript["text"]
|
66 |
+
|
67 |
+
|
68 |
+
st.session_state['vignette'] = st.text_area(
|
69 |
+
"Vignette", value=st.session_state['vignette'])
|
70 |
+
|
71 |
+
|
72 |
+
if st.button("Get DDX and Orders"):
|
73 |
+
vignette = st.session_state['vignette']
|
74 |
+
ddx = get_ddx(vignette)
|
75 |
+
st.session_state['ddx'] = ddx
|
76 |
+
st.session_state['orders'] = get_orders(vignette, ddx)
|
77 |
+
|
78 |
+
|
79 |
+
col1, col2 = st.columns(2)
|
80 |
+
|
81 |
+
with col1:
|
82 |
+
st.markdown(
|
83 |
+
f"**DDX**\n\n{st.session_state['ddx']}", unsafe_allow_html=True)
|
84 |
|
85 |
+
with col2:
|
86 |
+
st.markdown(
|
87 |
+
f"**ORDERS**\n\n{st.session_state['orders']}", unsafe_allow_html=True)
|