mrmarvelous commited on
Commit
4171e63
1 Parent(s): 3f66d40

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #project to identify injury and tell me medicine
2
+
3
+ import google.generativeai as genai
4
+ from pathlib import Path
5
+ import gradio as gr
6
+
7
+ generation_config = {
8
+ "temperature" : 0,
9
+ "top_p" : 1,
10
+ "top_k" : 32,
11
+ "max_outuput_tokens":4096,
12
+ }
13
+
14
+ safety_settings = [
15
+ {
16
+ "category": "HARM_CATEGORY_HARASSMENT",
17
+ "threshold": "BLOCK_MEDIUM_AND_ABOVE"
18
+ },
19
+ {
20
+ "category": "HARM_CATEGORY_HATE_SPEECH",
21
+ "threshold": "BLOCK_MEDIUM_AND_ABOVE"
22
+ },
23
+ {
24
+ "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
25
+ "threshold": "BLOCK_MEDIUM_AND_ABOVE"
26
+ }
27
+ ]
28
+
29
+ genai.configure(api_key = "AIzaSyCi0mbXfp0uEBZpK7n-YnqR9tXT0tyXSM0")
30
+
31
+ model = genai.GenerativeModel(model_name = "gemini-pro-vision",
32
+ generation_config = generation_config,
33
+ safety_settings = safety_settings)
34
+
35
+ input_prompt = """This image shows a person with an injury or visible symptoms on the body. Please analyze the image along with the prompted messege and identify the possible injury. Based on your analysis, suggest appropraite first aid measures that can be taken to address the injury. And also provide useful website links (Indian links only) which are valid and existing and which can give more information regarding the first aid for the injury and also Ensure the target website links are publicly accessible and not blocked by firewalls or login requirements. And also provide contact information of the helpline for the next steps. And constrain the response to India. The prompted message is"""
36
+
37
+ def upload_file(files,text_input):
38
+ file_paths = [file.name for file in files]
39
+ if file_paths:
40
+ response = generate_gemini_response(input_prompt,text_input,file_paths[0])
41
+ return file_paths[0],response
42
+
43
+ with gr.Blocks() as demo:
44
+ header = gr.Label("Please let us know about your injury ")
45
+ text_input = gr.Textbox(label = "Explain a bit more about your injury")
46
+ image_output = gr.Image()
47
+ upload_gr.UploadButton("Click to upload an image of the injury",
48
+ file_types = ["image"],
49
+ file_count = "multiple")
50
+
51
+ file_output = gr.Textbox(label = "First Aid process")
52
+ combined_output = [image_output,file_output]
53
+
54
+ upload_button.upload(upload_file,[upload_button,text_input],combined_output)
55
+
56
+ demo.launch(debug = True)