Rammohan0504 commited on
Commit
bbb2285
·
verified ·
1 Parent(s): 6e4efc6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -10
app.py CHANGED
@@ -6,9 +6,9 @@ from sklearn.linear_model import LinearRegression
6
  import random
7
  import base64
8
  import joblib
9
- import pdfkit
 
10
  from io import BytesIO
11
- import json
12
 
13
  # Initialize the face mesh model
14
  mp_face_mesh = mp.solutions.face_mesh
@@ -117,15 +117,23 @@ def build_table(title, rows):
117
  return html
118
 
119
 
120
- # Generate PDF from HTML content
121
  def generate_pdf(html_content):
122
- pdf = pdfkit.from_string(html_content, False)
123
- return BytesIO(pdf)
 
 
 
 
 
 
 
 
 
 
 
 
124
 
125
- # Find labs using geolocation (for example purposes, replace with actual logic)
126
- def find_labs_nearby(location):
127
- # This can use the location to query a database of nearby labs
128
- return f"Nearby labs for your location {location}: Lab A, Lab B, Lab C."
129
 
130
  # Modified analyze_face function
131
  def analyze_face(input_data):
@@ -278,7 +286,6 @@ with gr.Blocks() as demo:
278
  result_html = gr.HTML(label="🧪 Health Report Table")
279
  result_image = gr.Image(label="📷 Key Frame Snapshot")
280
  download_btn = gr.Button("📥 Download PDF")
281
- download_btn.click(fn=lambda pdf_file: pdf_file, inputs=[result_html], outputs=[download_btn])
282
 
283
  submit_btn.click(fn=route_inputs,
284
  inputs=[mode_selector, image_input, video_input, patient_name, patient_age, patient_gender, patient_id],
 
6
  import random
7
  import base64
8
  import joblib
9
+ from reportlab.lib.pagesizes import letter
10
+ from reportlab.pdfgen import canvas
11
  from io import BytesIO
 
12
 
13
  # Initialize the face mesh model
14
  mp_face_mesh = mp.solutions.face_mesh
 
117
  return html
118
 
119
 
120
+ # Generate PDF from HTML content using reportlab
121
  def generate_pdf(html_content):
122
+ buffer = BytesIO()
123
+ c = canvas.Canvas(buffer, pagesize=letter)
124
+
125
+ # Adding basic content to PDF (you can modify this to match your layout)
126
+ text = c.beginText(40, 750)
127
+ text.setFont("Helvetica", 12)
128
+ text.textLines(html_content) # Add the content
129
+
130
+ c.drawText(text)
131
+ c.showPage()
132
+ c.save()
133
+
134
+ buffer.seek(0)
135
+ return buffer
136
 
 
 
 
 
137
 
138
  # Modified analyze_face function
139
  def analyze_face(input_data):
 
286
  result_html = gr.HTML(label="🧪 Health Report Table")
287
  result_image = gr.Image(label="📷 Key Frame Snapshot")
288
  download_btn = gr.Button("📥 Download PDF")
 
289
 
290
  submit_btn.click(fn=route_inputs,
291
  inputs=[mode_selector, image_input, video_input, patient_name, patient_age, patient_gender, patient_id],