dawit45 commited on
Commit
1ec00b2
Β·
verified Β·
1 Parent(s): 8b0740e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -68
app.py CHANGED
@@ -4,108 +4,108 @@ from datetime import datetime
4
  from google import genai
5
  from google.genai import types
6
 
7
- # --- 1. PAGE CONFIG & STYLING ---
8
- st.set_page_config(page_title="Abyssinia Scribe Pro", page_icon="πŸ“", layout="wide")
9
 
10
- # ChatGPT-Style Dark Mode Theme for the Output Note
11
  st.markdown("""
12
  <style>
13
- .chatgpt-note {
14
- background-color: #0d1117;
15
- color: #c9d1d9;
16
- padding: 30px;
17
- border-radius: 10px;
18
- font-family: 'Fira Code', 'Courier New', monospace;
19
- line-height: 1.7;
20
- border: 1px solid #30363d;
21
- white-space: pre-wrap;
22
- box-shadow: 0 10px 30px rgba(0,0,0,0.5);
 
 
23
  }
24
- .scribe-sig {
25
- margin-top: 25px;
26
- padding-top: 15px;
27
- border-top: 1px solid #30363d;
28
- color: #8b949e;
 
 
 
 
 
 
 
 
 
 
 
29
  font-size: 0.9em;
30
- font-style: italic;
31
  }
32
  </style>
33
  """, unsafe_allow_html=True)
34
 
35
  # API Initialization
36
- api_key = os.environ.get("GOOGLE_API_KEY")
37
- client = genai.Client(api_key=api_key)
38
 
39
- # --- 2. APP INTERFACE ---
40
  st.title("πŸ₯ Abyssinia Intelligence Scribe")
41
- st.markdown("Professional Clinical Documentation & SOAP Note Engine")
42
 
43
  col1, col2 = st.columns([1, 1], gap="large")
44
 
45
  with col1:
46
- st.subheader("πŸŽ™οΈ Capture Consultation")
47
-
48
- # Microphone Recording Component
49
- audio_file = st.audio_input("Record Live Encounter")
50
 
51
- # Manual Text Backup
52
- text_input = st.text_area("Or paste consultation notes here:", height=150)
53
-
54
- generate_btn = st.button("Generate Final SOAP Note", type="primary")
55
 
56
  with col2:
57
- st.subheader("πŸ“„ Clinical Record")
58
 
59
  if generate_btn:
60
- input_parts = []
61
-
62
- # FIX: Correctly formatting the input for the 2026 SDK
63
  if audio_file:
64
- # We read the raw bytes from the Streamlit UploadedFile object
65
- audio_bytes = audio_file.read()
66
- input_parts.append(
67
- types.Part.from_bytes(data=audio_bytes, mime_type="audio/wav")
68
- )
69
- elif text_input:
70
- input_parts.append(types.Part.from_text(text=text_input))
71
-
72
- if not input_parts:
73
- st.warning("Please provide audio or text input.")
74
  else:
75
- with st.spinner("Abyssinia AI is generating the clinical record..."):
76
  try:
77
- # Gemini 3.0 Flash Processing
78
  response = client.models.generate_content(
79
  model="gemini-3-flash-preview",
80
  config=types.GenerateContentConfig(
81
- system_instruction="Create a formal medical SOAP note. Use professional formatting.",
82
- temperature=0.1 # Very low for high accuracy
83
  ),
84
- contents=input_parts
85
  )
86
 
87
- # 3. Accurate Signature Date
 
 
 
 
88
  now = datetime.now()
89
- formatted_date = now.strftime("%A, %B %d, %Y")
90
- formatted_time = now.strftime("%I:%M %p")
91
 
92
- # Constructing the "Attractive" HTML output
93
  st.markdown(f"""
94
- <div class="chatgpt-note">
95
- {response.text}
96
- <div class="scribe-sig">
97
- β€” Electronically generated by Abyssinia Intelligence Scribe<br>
98
- β€” Timestamp: {formatted_date} at {formatted_time}<br>
99
- β€” Reference: ABY-{now.strftime('%H%M%S')}
100
- </div>
101
  </div>
102
  """, unsafe_allow_html=True)
103
 
104
- st.download_button("Download Document", response.text, file_name=f"Clinical_Note_{now.strftime('%Y%m%d')}.txt")
105
-
106
  except Exception as e:
107
- st.error(f"Scribe Error: {e}")
108
-
109
- # --- 3. FOOTER ---
110
- st.markdown("---")
111
- st.caption("Abyssinia Intelligence | 2026 Healthcare Scribe Edition")
 
4
  from google import genai
5
  from google.genai import types
6
 
7
+ # --- 1. PAGE CONFIG & MODERN CSS ---
8
+ st.set_page_config(page_title="Abyssinia Scribe", page_icon="πŸ₯", layout="wide")
9
 
10
+ # Custom CSS for "ChatGPT Style" Output - Clean Sans-Serif & Modern Spacing
11
  st.markdown("""
12
  <style>
13
+ /* ChatGPT-style Container */
14
+ .chat-gpt-style {
15
+ background-color: #ffffff;
16
+ color: #343541;
17
+ padding: 40px;
18
+ border-radius: 12px;
19
+ font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
20
+ line-height: 1.6;
21
+ border: 1px solid #e5e5e5;
22
+ box-shadow: 0 4px 24px rgba(0,0,0,0.08);
23
+ max-width: 800px;
24
+ margin: auto;
25
  }
26
+ /* Clinical Headers */
27
+ .note-section-header {
28
+ color: #10a37f; /* ChatGPT Green accent */
29
+ font-weight: 600;
30
+ font-size: 1.1em;
31
+ margin-top: 20px;
32
+ margin-bottom: 8px;
33
+ text-transform: uppercase;
34
+ letter-spacing: 0.5px;
35
+ }
36
+ /* Accurate Signature */
37
+ .clinical-sig {
38
+ margin-top: 40px;
39
+ padding-top: 20px;
40
+ border-top: 1px solid #f0f0f0;
41
+ color: #6e6e80;
42
  font-size: 0.9em;
 
43
  }
44
  </style>
45
  """, unsafe_allow_html=True)
46
 
47
  # API Initialization
48
+ client = genai.Client(api_key=os.environ.get("GOOGLE_API_KEY"))
 
49
 
50
+ # --- 2. THE UI ---
51
  st.title("πŸ₯ Abyssinia Intelligence Scribe")
 
52
 
53
  col1, col2 = st.columns([1, 1], gap="large")
54
 
55
  with col1:
56
+ st.subheader("πŸŽ™οΈ Input Consultation")
57
+ audio_file = st.audio_input("Record Conversation")
58
+ text_backup = st.text_area("Or type/paste notes here:", height=250)
 
59
 
60
+ generate_btn = st.button("Finalize Scribe Report", type="primary")
 
 
 
61
 
62
  with col2:
63
+ st.subheader("πŸ“ Final Medical Note")
64
 
65
  if generate_btn:
66
+ # Prepare content parts
67
+ parts = []
 
68
  if audio_file:
69
+ parts.append(types.Part.from_bytes(data=audio_file.read(), mime_type="audio/wav"))
70
+ elif text_backup:
71
+ parts.append(types.Part.from_text(text=text_backup))
72
+
73
+ if not parts:
74
+ st.error("Error: No consultation data detected.")
 
 
 
 
75
  else:
76
+ with st.spinner("Generating document..."):
77
  try:
78
+ # Request structured data from Gemini 3.0 Flash
79
  response = client.models.generate_content(
80
  model="gemini-3-flash-preview",
81
  config=types.GenerateContentConfig(
82
+ system_instruction="Create a detailed, structured medical SOAP note. Format sections clearly.",
83
+ temperature=0.2
84
  ),
85
+ contents=parts
86
  )
87
 
88
+ # Formatting text to look "ChatGPT attractive" rather than code-like
89
+ formatted_output = response.text.replace("### ", "<div class='note-section-header'>")
90
+ formatted_output = formatted_output.replace("\n", "<br>")
91
+
92
+ # Get Local Ethiopia/Server Time
93
  now = datetime.now()
94
+ timestamp = now.strftime("%d %B %Y at %H:%M")
 
95
 
96
+ # Rendering the HTML
97
  st.markdown(f"""
98
+ <div class="chat-gpt-style">
99
+ {formatted_output}
100
+ <div class="clinical-sig">
101
+ <b>Digitally Authenticated:</b> Abyssinia AI Scribe Engine<br>
102
+ <b>Finalized on:</b> {timestamp}<br>
103
+ <b>Reference ID:</b> ABY-{now.strftime('%m%d-%H%M')}
104
+ </div>
105
  </div>
106
  """, unsafe_allow_html=True)
107
 
108
+ st.download_button("Export Clinical Note", response.text)
109
+
110
  except Exception as e:
111
+ st.error(f"Scribe Error: {e}")