pilayar commited on
Commit
b259aa8
·
verified ·
1 Parent(s): 599a0ca

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +78 -0
app.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ from google import genai
4
+ from google.genai import types
5
+ from pydantic import BaseModel, Field
6
+ from PIL import Image
7
+
8
+ # 1. Define the Data Structure (The "Schema")
9
+ # This tells the AI exactly which fields to find on the license.
10
+ class ProviderLicense(BaseModel):
11
+ provider_name: str = Field(description="Full name of the healthcare provider")
12
+ license_number: str = Field(description="The professional license number")
13
+ state: str = Field(description="The state where the license was issued")
14
+ expiration_date: str = Field(description="Format: YYYY-MM-DD")
15
+ is_valid: bool = Field(description="True if the license is not expired based on today's date")
16
+
17
+ # 2. Page Configuration
18
+ st.set_page_config(page_title="AI Credentialing Assistant", layout="wide")
19
+ st.title("🩺 Provider Credentialing AI")
20
+ st.markdown("Automated Intelligent Document Processing for Medical Licenses.")
21
+
22
+ # 3. Initialize Gemini Client
23
+ # Uses the 'Secret' you saved in Hugging Face Settings
24
+ api_key = os.environ.get("GEMINI_API_KEY")
25
+ if not api_key:
26
+ st.error("API Key not found. Please add GEMINI_API_KEY to your Space Secrets.")
27
+ st.stop()
28
+
29
+ client = genai.Client(api_key=api_key)
30
+
31
+ # 4. Sidebar - File Upload
32
+ st.sidebar.header("Document Upload")
33
+ uploaded_file = st.sidebar.file_uploader("Upload a medical license (JPG/PNG)", type=["jpg", "jpeg", "png"])
34
+
35
+ if uploaded_file:
36
+ # Create two columns for a professional dashboard look
37
+ col1, col2 = st.columns(2)
38
+
39
+ image = Image.open(uploaded_file)
40
+
41
+ with col1:
42
+ st.subheader("Document Preview")
43
+ st.image(image, use_container_width=True)
44
+
45
+ with col2:
46
+ st.subheader("Extracted Credentials")
47
+
48
+ with st.spinner("AI is analyzing the document..."):
49
+ try:
50
+ # The AI Logic
51
+ response = client.models.generate_content(
52
+ model="gemini-2.0-flash",
53
+ contents=["Extract the credentialing details from this document.", image],
54
+ config=types.GenerateContentConfig(
55
+ response_mime_type="application/json",
56
+ response_schema=ProviderLicense,
57
+ ),
58
+ )
59
+
60
+ # Retrieve the structured data
61
+ data = response.parsed
62
+
63
+ # Display results in a clean format
64
+ st.success("Extraction Complete")
65
+ st.metric("Provider Name", data.provider_name)
66
+ st.write(f"**License Number:** {data.license_number}")
67
+ st.write(f"**State:** {data.state}")
68
+ st.write(f"**Expires:** {data.expiration_date}")
69
+
70
+ if data.is_valid:
71
+ st.info("✅ Status: Valid/Active")
72
+ else:
73
+ st.warning("⚠️ Status: Expired or Invalid")
74
+
75
+ except Exception as e:
76
+ st.error(f"An error occurred: {e}")
77
+ else:
78
+ st.info("Please upload a document to begin the automated verification process.")