Musharraf11 commited on
Commit
f3b2863
1 Parent(s): e8780ac

Upload 2 files

Browse files
Files changed (2) hide show
  1. .env +1 -0
  2. app.py +67 -0
.env ADDED
@@ -0,0 +1 @@
 
 
1
+ GOOGLE_API_KEY="AIzaSyDs9p7qZMOl8XG_th5QPZ7ILgMlhzSxSBw"
app.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ##Importing All the modules
2
+ import streamlit as st
3
+ import os
4
+ from PIL import Image
5
+ import google.generativeai as genai
6
+ from dotenv import load_dotenv
7
+
8
+
9
+ # Load all environment Variables
10
+ load_dotenv()
11
+
12
+ ##Configuring the api key
13
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
14
+
15
+ ## Function to load Gemini Vison Pro Vision Model and Get response
16
+
17
+ def get_gemini_response(input,image,prompt):
18
+
19
+ ##Loading the desired Model
20
+ model= genai.GenerativeModel("gemini-pro-vision")
21
+ response=model.generate_content([input,image[0],prompt])
22
+ return response.text
23
+
24
+ ## Function to extract data from Image Uploaded
25
+ def input_image_setup(uploaded_file):
26
+ # Check if a file has been uploaded
27
+ if uploaded_file is not None:
28
+ # Read the file into bytes
29
+ bytes_data = uploaded_file.getvalue()
30
+
31
+ image_parts = [
32
+ {
33
+ "mime_type": uploaded_file.type, # Get the mime type of the uploaded file
34
+ "data": bytes_data
35
+ }
36
+ ]
37
+ return image_parts
38
+ else:
39
+ raise FileNotFoundError("No file uploaded")
40
+
41
+ # Initializing our Streamlit Prompt
42
+
43
+ st.set_page_config(page_title="Medical Prescription Extractor")
44
+
45
+ st.header("Prescription Analyzer")
46
+ input=st.text_input("Optional Hint for the Model (e.g., Extract dosage): ",key="input")
47
+ uploaded_file = st.file_uploader("Choose a Prescription Image...", type=["jpg", "jpeg", "png"])
48
+ image=""
49
+ if uploaded_file is not None:
50
+ image = Image.open(uploaded_file)
51
+ st.image(image, caption="Uploaded Prescription.", use_column_width=True)
52
+
53
+
54
+ submit=st.button("Analyze Prescription")
55
+
56
+ ## DEFINING A SYSTEM PROMPT
57
+
58
+ input_prompt = "You are a licensed medical professional trained to interpret prescriptions. You will receive prescription images as input and you will have to extract key information like dosage, strength, frequency, and medication name."
59
+
60
+ if submit:
61
+ image_data = input_image_setup(uploaded_file)
62
+ response = get_gemini_response(input,image_data,input_prompt)
63
+
64
+ st.subheader("Analysis by your model Gemini Pro Vision: ")
65
+ st.write(response)
66
+
67
+ st.balloons()