vinayakarsh commited on
Commit
a502bea
·
verified ·
1 Parent(s): 5fc203b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -19
app.py CHANGED
@@ -1,45 +1,36 @@
1
- from PIL import Image
2
  import os
3
- import io
4
- import sys
5
  import google.generativeai as genai
6
- import fitz # PyMuPDF
7
  import gradio as gr
8
 
9
 
10
  GOOGLE_API_KEY = os.getenv('GOOGLE_API_KEY')
11
  genai.configure(api_key=GOOGLE_API_KEY)
12
- model = genai.GenerativeModel('gemini-1.5-flash-latest')
13
  generation_config = genai.GenerationConfig(temperature=0)
14
 
15
 
16
  def upload(file):
17
  if not file:
18
  return "**ERROR!!! FILE NOT UPLOADED**"
19
-
20
- pics = []
21
- doc = fitz.open(file)
22
- for page_num in range(len(doc)):
23
- page = doc.load_page(page_num)
24
- pix = page.get_pixmap()
25
- pics.append(Image.open(io.BytesIO(pix.tobytes())))
26
 
27
  prompt = "You are an expert in medical report analysis. Analyze the given medical report and generate a summarized report of the same."\
28
  "All the medical tests in the given medical report must be specified in the summarized report. The response generated should be well-structured with health tips based on the report."\
29
 
30
- contents = [prompt]
31
- contents.extend(pics)
 
 
32
  response = model.generate_content(contents)
33
 
34
  return response.text
35
 
36
 
37
  demo = gr.Interface(
38
- fn=upload,
39
- inputs=gr.File(file_types=['.pdf']), # Input: File input
40
- outputs=gr.Markdown(), # Output: Textbox to display the extracted text
41
- title="Medical Report Summarizer",
42
- description="Note: This summary is based on the provided medical report and does not constitute medical advice. Please consult with your healthcare provider for any questions or concerns regarding your health."
43
  )
44
 
45
 
 
 
1
  import os
 
 
2
  import google.generativeai as genai
 
3
  import gradio as gr
4
 
5
 
6
  GOOGLE_API_KEY = os.getenv('GOOGLE_API_KEY')
7
  genai.configure(api_key=GOOGLE_API_KEY)
8
+ model = genai.GenerativeModel('gemini-2.0-flash-exp')
9
  generation_config = genai.GenerationConfig(temperature=0)
10
 
11
 
12
  def upload(file):
13
  if not file:
14
  return "**ERROR!!! FILE NOT UPLOADED**"
 
 
 
 
 
 
 
15
 
16
  prompt = "You are an expert in medical report analysis. Analyze the given medical report and generate a summarized report of the same."\
17
  "All the medical tests in the given medical report must be specified in the summarized report. The response generated should be well-structured with health tips based on the report."\
18
 
19
+ file = genai.upload_file(file)
20
+
21
+ contents = [prompt, file]
22
+
23
  response = model.generate_content(contents)
24
 
25
  return response.text
26
 
27
 
28
  demo = gr.Interface(
29
+ fn = upload,
30
+ inputs = gr.File(file_types=['.pdf']), # Input: File input
31
+ outputs = gr.Markdown(), # Output: Textbox to display the extracted text
32
+ title = "Medical Report Summarizer",
33
+ description = "Note: This summary is based on the provided medical report and does not constitute medical advice. Please consult with your healthcare provider for any questions or concerns regarding your health."
34
  )
35
 
36