ManasviD commited on
Commit
cd67ab5
·
verified ·
1 Parent(s): a0023f3

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ import io
4
+ import base64
5
+ import pathlib
6
+ import textwrap
7
+ import os
8
+ os.environ['PORT1'] = '8080'
9
+ from IPython.display import display
10
+ from IPython.display import Markdown
11
+ import google.generativeai as genai
12
+ from PIL import Image
13
+
14
+ #apiKey = userdata.get('GOOGLE_API_KEY')
15
+
16
+ from dotenv import load_dotenv
17
+
18
+ load_dotenv()
19
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
20
+
21
+ def to_markdown(text):
22
+ text = text.replace('•', ' *')
23
+ return Markdown(textwrap.indent(text, '> ', predicate=lambda _: True))
24
+
25
+
26
+
27
+ model = genai.GenerativeModel('gemini-1.5-pro')
28
+
29
+
30
+
31
+
32
+ def generate_aid(image):
33
+ response = model.generate_content(["Analyze the uploaded image to identify the condition or injury. "
34
+ "Do not provide any information outside of medical diagnosis, treatment, or first-aid steps. "
35
+ "Do not provide any general information, non-medical advice, or off-topic responses."
36
+ "Provide a detailed response in the following structured format: "
37
+ "Condition Detected: Name of the condition or injury (e.g., Minor Burn, Bruise, Infection). "
38
+ "Severity Level: Mild, Moderate, or Severe (based on visual analysis). "
39
+ "Symptoms Identified: List the symptoms visible in the image (e.g., redness, swelling, bruising). "
40
+ "Immediate First-Aid Steps:Provide clear and actionable steps to address the condition. "
41
+ "When to Seek Medical Help: Mention signs that require professional attention (e.g., severe pain, signs of infection). "
42
+ "Preventive Tips (Optional) Suggest ways to prevent similar injuries in the future. "
43
+ "End with a reminder: 'Consult a healthcare professional if symptoms worsen or persist.'",
44
+ image])
45
+ return response.text
46
+
47
+ interface = gr.Interface(fn=generate_aid,
48
+ inputs=gr.Image(label="Upload or Capture Image", type="pil"),
49
+ outputs=gr.Textbox(label="QuickAid to the Rescue! 🚑",placeholder="Hang tight, your QuickAid guide is on its way..."),
50
+ title="QuickAid: Your Pocket First-Aid Companion",
51
+ description=("Please note that while the model works to offer the most accurate advice possible, the results may occasionally vary."
52
+ "To enhance accuracy, future updates will allow you to provide additional context such as age and highlight areas of concern in the image, A symptom checker and more user inputs will also be integrated to improve precision."
53
+ "For now, results might not be perfect, so it's always best to consult a healthcare professional if you're unsure or if symptoms persist."),
54
+ allow_flagging="never",
55
+ examples=["/content/B1.jpg", "/content/B2.jpg"])
56
+ interface.launch(debug = True)