saqib129 commited on
Commit
ad6e901
β€’
1 Parent(s): 3d6dc00

Medical Analysis Files

Browse files
Files changed (4) hide show
  1. .gitignore +1 -0
  2. grad_app.py +93 -0
  3. readme.md +32 -0
  4. requirements.txt +3 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .env
grad_app.py ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import tempfile
3
+ from dotenv import load_dotenv
4
+ import google.generativeai as genai
5
+ import gradio as gr
6
+ from google.generativeai.types import HarmCategory, HarmBlockThreshold
7
+
8
+ # Load environment variables
9
+ load_dotenv()
10
+
11
+ # Configure Google Gemini API
12
+ genai.configure(api_key=os.getenv('gemini_key'))
13
+
14
+ # Prompt template for detailed analysis
15
+ system_prompt = """
16
+ As a Highly Skilled medical practitioner specializing in image analysis, you are tasked with examining medical images for a renowned hospital.your expertise
17
+ is crucial in idetifying any anomalies, diseases or health issues that maybe present in the images.
18
+
19
+ Your Responsibilities:
20
+ 1. Detailed Analysis: Thoroughly analyze each image, focusing on identifying any abnormal findings.
21
+ 2. Finding reports: Document all observed anomalies or signs of diseases. Clearly articulate these findings in a Structured form.
22
+ 3. Recommendations and Next steps: Based on your analysis, suggest potential next steps, including further tests or treatment as applicable.
23
+ 4. if appropriate, recommend possible treatment options or interventions.
24
+
25
+ Important notes:
26
+ Scope of response: only respond if the image is related to human health.
27
+ Clarity of image: In cases where the image quality impedes clear analysis, note that certian aspects are 'Unable to be determind based on the provided image.'
28
+ """
29
+
30
+ # Configuration for the generative model
31
+ generation_config = {
32
+ "temperature": 1,
33
+ "top_p": 0.95,
34
+ "top_k": 64,
35
+ "max_output_tokens": 8192,
36
+ "response_mime_type": "text/plain",
37
+ }
38
+
39
+ def upload_to_gemini(path, mime_type=None):
40
+ """Uploads the given file to Gemini."""
41
+ file = genai.upload_file(path, mime_type=mime_type)
42
+ print(f"Uploaded file '{file.display_name}' as: {file.uri}")
43
+ return file
44
+
45
+ # Create the generative model
46
+ model = genai.GenerativeModel(
47
+ model_name="gemini-1.5-flash",
48
+ generation_config=generation_config,
49
+ safety_settings={
50
+ HarmCategory.HARM_CATEGORY_HATE_SPEECH: HarmBlockThreshold.BLOCK_NONE,
51
+ HarmCategory.HARM_CATEGORY_HARASSMENT: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE,
52
+ HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT: HarmBlockThreshold.BLOCK_NONE,
53
+ HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_NONE,
54
+ }
55
+ )
56
+
57
+ def analyze_image(image_path):
58
+ # Ensure the uploaded file is one of the allowed types
59
+ allowed_extensions = ['.png', '.jpg', '.jpeg', '.webp']
60
+ _, ext = os.path.splitext(image_path)
61
+ if ext.lower() not in allowed_extensions:
62
+ return "Unsupported file type. Please upload a PNG, JPG, JPEG, or WEBP image."
63
+
64
+ # Upload the image to Gemini
65
+ uploaded_file_info = upload_to_gemini(image_path, mime_type="image/png")
66
+
67
+ # Create a chat session with the model and send the image for analysis
68
+ chat_session = model.start_chat(
69
+ history=[
70
+ {
71
+ "role": "user",
72
+ "parts": [
73
+ uploaded_file_info,
74
+ system_prompt,
75
+ ],
76
+ },
77
+ ]
78
+ )
79
+
80
+ response = chat_session.send_message(system_prompt)
81
+ return response.text
82
+
83
+ # Gradio interface
84
+ iface = gr.Interface(
85
+ fn=analyze_image,
86
+ inputs=gr.Image(type="filepath"),
87
+ outputs=gr.Textbox(label="Analysis Results"),
88
+ title="πŸ‘¨β€βš•οΈ Vital Image πŸ“· Analytics",
89
+ description="Upload a medical image to get a detailed analysis.",
90
+ )
91
+
92
+ if __name__ == "__main__":
93
+ iface.launch()
readme.md ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Vital Image Analytics
2
+
3
+ Vital Image Analytics is an AI-powered application designed to assist healthcare professionals in analyzing medical images for diagnostic purposes. This README file provides an overview of the application, how to set it up, and how to use it effectively.
4
+
5
+ ## Features
6
+ - Advanced AI Analysis: Utilizes state-of-the-art AI models to provide detailed analysis of medical images.
7
+ - Comprehensive Reports: Generates reports including findings, recommendations, and next steps based on image analysis.
8
+ - User-Friendly Interface: Easy-to-use interface with seamless image uploading and instant results.
9
+ - Secure and Reliable: Built with robust security measures to protect patient data and ensure reliability.
10
+
11
+ ## Getting Started
12
+
13
+ 1) Clone the repository.
14
+ 2) Install dependencies
15
+ ```
16
+ pip install -r requirements.txt
17
+ ```
18
+
19
+ 3) SetUp environment variables:
20
+ - create a `.env` file in root directory
21
+ - add your gemini apu key
22
+ ``` GEMINI_API_KEY=your_gemini_api_key_here ```
23
+
24
+ ## Usage
25
+ Launch the application: ``` python grad_app.py ```
26
+
27
+ ![alt text](image.png)
28
+
29
+
30
+ ## Contact
31
+ For questions or inquiries about Vital Image Analytics, please contact at (saqibiqbal27772@gmail.com)
32
+
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ google
2
+ streamlit
3
+ dotenv