Alesmikes commited on
Commit
a0e6ca5
·
verified ·
1 Parent(s): 0628735

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -81
app.py CHANGED
@@ -2,86 +2,26 @@ import streamlit as 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
- "Nahraj pacientův projev.")
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.transcribe("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)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  from audiorecorder import audiorecorder
3
  import openai
4
  import os
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
+ # Nastavení klíče API pro OpenAI
7
+ openai.api_key = os.environ['OPENAI_API_KEY']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
+ def transcribe(audio_data):
10
+ """
11
+ Transkribuje audio data pomocí Whisper API.
12
+ """
13
+ response = openai.Audio.transcribe("whisper-1", audio_data, filename='1.mp3')
14
+ return response["text"]
15
+
16
+ # Streamlit aplikace
17
+ st.title("Audio Transkriptor")
18
+
19
+ # Nahrávání audia
20
+ st.markdown("Nahrajte svůj hlasový záznam.")
21
+ audio_data = audiorecorder("Record", "Stop")
22
+
23
+ # Zpracování a zobrazení transkripce
24
+ if audio_data is not None and len(audio_data) > 0:
25
+ with st.spinner('Probíhá transkripce...'):
26
+ transcript = transcribe(audio_data.tobytes())
27
+ st.text_area("Transkript", value=transcript, height=300)