Narayana02 commited on
Commit
ce3722c
·
verified ·
1 Parent(s): b911c93

Upload 2 files

Browse files
Files changed (2) hide show
  1. requirements.txt +6 -0
  2. task.py +167 -0
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+
2
+
3
+ streamlit
4
+ openai
5
+ pydub
6
+ requests
task.py ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import openai
3
+ from pydub import AudioSegment
4
+ import io
5
+ import time
6
+
7
+ # Set your OpenAI API key
8
+ openai.api_key = "YOUR_API_KEY"
9
+
10
+ # Function to summarize the transcript into medical sections
11
+ def medical_summary(transcript):
12
+ prompt = f"""
13
+ Organize the following medical transcript into the predefined sections:
14
+
15
+ Sections:
16
+ 1. Medical Specialty
17
+ 2. CHIEF COMPLAINT
18
+ 3. Purpose of visit
19
+ 4. HISTORY and Physical
20
+ - PAST MEDICAL HISTORY
21
+ - PAST SURGICAL HISTORY
22
+ - ALLERGIES History
23
+ - Social History
24
+ - REVIEW OF SYSTEMS
25
+ 5. PHYSICAL EXAMINATION
26
+ - GENERAL
27
+ - Vitals
28
+ - ENT
29
+ - Head
30
+ - Neck
31
+ - Chest
32
+ - Heart
33
+ - Abdomen
34
+ - Pelvic
35
+ - Extremities
36
+
37
+ Transcript:
38
+ {transcript}
39
+
40
+ Provide a structured summary in the above format.
41
+ """
42
+ try:
43
+ response = openai.ChatCompletion.create(
44
+ model="gpt-4", # Use gpt-3.5-turbo if GPT-4 is unavailable
45
+ messages=[
46
+ {"role": "system", "content": "You are a helpful medical assistant."},
47
+ {"role": "user", "content": prompt}
48
+ ],
49
+ temperature=0.5,
50
+ max_tokens=3000 # Adjust max_tokens based on the expected size of the summary
51
+ )
52
+ structured_summary = response['choices'][0]['message']['content'].strip()
53
+ return structured_summary
54
+ except Exception as e:
55
+ return f"An error occurred: {e}"
56
+
57
+ # Function to convert audio to text using OpenAI's Whisper or any suitable service
58
+ def transcribe_audio(audio_file):
59
+ audio = AudioSegment.from_file(audio_file)
60
+ audio = audio.set_channels(1).set_frame_rate(16000) # Convert to mono and set appropriate frame rate
61
+
62
+ buffer = io.BytesIO()
63
+ audio.export(buffer, format="wav")
64
+ buffer.seek(0)
65
+
66
+ # Here, you would normally call the transcription API or process the file
67
+ # Example (assuming transcription API integration):
68
+ # response = openai.Audio.transcribe(model="whisper-1", file=buffer)
69
+
70
+ return "Patient complains of chest pain, shortness of breath, and dizziness. He has a history of hypertension."
71
+
72
+ # Streamlit UI
73
+ def main():
74
+ # Custom CSS to improve UI aesthetics
75
+ st.markdown("""
76
+ <style>
77
+ body {
78
+ font-family: 'Arial', sans-serif;
79
+ background-color: #f4f4f9;
80
+ }
81
+ .title {
82
+ font-size: 36px;
83
+ color: #1E2A47;
84
+ font-weight: 600;
85
+ text-align: center;
86
+ padding-top: 30px;
87
+ padding-bottom: 10px;
88
+ }
89
+ .subheader {
90
+ font-size: 24px;
91
+ color: #2F4F9A;
92
+ text-align: center;
93
+ margin-bottom: 20px;
94
+ }
95
+ .card {
96
+ background-color: #ffffff;
97
+ border-radius: 8px;
98
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
99
+ padding: 20px;
100
+ margin-bottom: 30px;
101
+ }
102
+ .button {
103
+ background-color: #4CAF50;
104
+ color: white;
105
+ padding: 12px 20px;
106
+ font-size: 16px;
107
+ border-radius: 8px;
108
+ border: none;
109
+ cursor: pointer;
110
+ transition: background-color 0.3s ease;
111
+ }
112
+ .button:hover {
113
+ background-color: #45a049;
114
+ }
115
+ .error {
116
+ color: red;
117
+ font-weight: bold;
118
+ text-align: center;
119
+ }
120
+ .footer {
121
+ text-align: center;
122
+ margin-top: 40px;
123
+ color: #555;
124
+ }
125
+ </style>
126
+ """, unsafe_allow_html=True)
127
+
128
+ # Title and subtitle
129
+ st.markdown('<div class="title">Medical Transcription Dashboard</div>', unsafe_allow_html=True)
130
+ st.markdown('<div class="subheader">Upload an audio file or enter the transcript to generate a medical summary</div>', unsafe_allow_html=True)
131
+
132
+ # Layout: Input Area in Card
133
+ with st.container():
134
+ st.markdown('<div class="card">', unsafe_allow_html=True)
135
+
136
+ # Audio upload and text input options
137
+ audio_file = st.file_uploader("Upload an audio file (wav, mp3, etc.)", type=["wav", "mp3"], label_visibility="collapsed")
138
+ transcript_text = st.text_area("Or, enter the transcript manually:", height=200)
139
+
140
+ # Show "Generate Medical Summary" button
141
+ if st.button("Generate Medical Summary", key="generate", use_container_width=True):
142
+ if audio_file:
143
+ # Show loading spinner while processing
144
+ with st.spinner('Transcribing audio...'):
145
+ transcript = transcribe_audio(audio_file)
146
+ time.sleep(2) # Simulate delay
147
+ st.write(f"Transcript: {transcript}")
148
+ elif transcript_text:
149
+ transcript = transcript_text
150
+ else:
151
+ st.markdown('<div class="error">Please upload an audio file or enter a transcript.</div>', unsafe_allow_html=True)
152
+
153
+ if transcript:
154
+ # Show loading spinner while generating summary
155
+ with st.spinner('Generating Medical Summary...'):
156
+ time.sleep(2) # Simulate processing time
157
+ summary = medical_summary(transcript)
158
+ st.markdown("### Medical Summary:")
159
+ st.write(summary)
160
+
161
+ st.markdown('</div>', unsafe_allow_html=True)
162
+
163
+ # Footer
164
+ st.markdown('<div class="footer">Developed with ❤️ by Your Company</div>', unsafe_allow_html=True)
165
+
166
+ if __name__ == "__main__":
167
+ main()