Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 &
|
| 8 |
-
st.set_page_config(page_title="Abyssinia Scribe
|
| 9 |
|
| 10 |
-
# ChatGPT
|
| 11 |
st.markdown("""
|
| 12 |
<style>
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
color: #
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
box-shadow: 0
|
|
|
|
|
|
|
| 23 |
}
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
font-size: 0.9em;
|
| 30 |
-
font-style: italic;
|
| 31 |
}
|
| 32 |
</style>
|
| 33 |
""", unsafe_allow_html=True)
|
| 34 |
|
| 35 |
# API Initialization
|
| 36 |
-
|
| 37 |
-
client = genai.Client(api_key=api_key)
|
| 38 |
|
| 39 |
-
# --- 2.
|
| 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("ποΈ
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
audio_file = st.audio_input("Record Live Encounter")
|
| 50 |
|
| 51 |
-
|
| 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("
|
| 58 |
|
| 59 |
if generate_btn:
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
# FIX: Correctly formatting the input for the 2026 SDK
|
| 63 |
if audio_file:
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 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("
|
| 76 |
try:
|
| 77 |
-
# Gemini 3.0 Flash
|
| 78 |
response = client.models.generate_content(
|
| 79 |
model="gemini-3-flash-preview",
|
| 80 |
config=types.GenerateContentConfig(
|
| 81 |
-
system_instruction="Create a
|
| 82 |
-
temperature=0.
|
| 83 |
),
|
| 84 |
-
contents=
|
| 85 |
)
|
| 86 |
|
| 87 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
now = datetime.now()
|
| 89 |
-
|
| 90 |
-
formatted_time = now.strftime("%I:%M %p")
|
| 91 |
|
| 92 |
-
#
|
| 93 |
st.markdown(f"""
|
| 94 |
-
<div class="
|
| 95 |
-
{
|
| 96 |
-
<div class="
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
</div>
|
| 101 |
</div>
|
| 102 |
""", unsafe_allow_html=True)
|
| 103 |
|
| 104 |
-
st.download_button("
|
| 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}")
|
|
|
|
|
|
|
|
|
|
|
|