neuralleap commited on
Commit
72f3c46
·
verified ·
1 Parent(s): 80f6f41

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import google.generativeai as genai
3
+ import base64
4
+ import io
5
+ from PIL import Image
6
+ import os
7
+ import json
8
+
9
+ # Configure Google Cloud credentials (replace with your actual API key or setup)
10
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
11
+
12
+ # Select the Gemini Pro Vision model
13
+ model = genai.GenerativeModel('gemini-pro-vision')
14
+
15
+ # Prompt definition
16
+ prompt = """
17
+ You are analyzing a medical document or an application form from patient.
18
+ Extract the following fields as JSON:
19
+ - Position applied for
20
+ - Office/Ministry
21
+ - Duty station
22
+ - First name(s)
23
+ - Surname
24
+ - Date of birth
25
+ - Gender
26
+ - Citizenship
27
+ - Postal Address
28
+ - Residential Address
29
+ - Email
30
+ - Phone number (mobile)
31
+ """
32
+
33
+ def process_image(image: Image.Image):
34
+ buffered = io.BytesIO()
35
+ image.save(buffered, format="JPEG")
36
+ base64_image = base64.b64encode(buffered.getvalue()).decode()
37
+
38
+ contents = [
39
+ genai.Part.from_text(prompt),
40
+ genai.Part.from_data(base64.b64decode(base64_image), mime_type="image/jpeg")
41
+ ]
42
+ response = model.generate_content(contents)
43
+ return response.text
44
+
45
+ # Gradio interface
46
+ demo = gr.Interface(
47
+ fn=process_image,
48
+ inputs=gr.Image(type="pil"),
49
+ outputs="textbox",
50
+ title="Healthelic Form Data Extractor (Doc Scaner)",
51
+ description="Upload a scanned medical form to extract key fields."
52
+ )
53
+
54
+ if __name__ == "__main__":
55
+ demo.launch()