Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,8 @@
|
|
1 |
import os
|
|
|
|
|
|
|
|
|
2 |
os.environ["CUDA_VISIBLE_DEVICES"] = "-1" # Force TensorFlow to use CPU
|
3 |
|
4 |
import gradio as gr
|
@@ -21,8 +25,41 @@ with open("templates/re.html", "r", encoding="utf-8") as file:
|
|
21 |
# List of sample images
|
22 |
sample_images = [f"samples/{img}" for img in os.listdir("samples") if img.endswith((".png", ".jpg", ".jpeg"))]
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
# Function to process X-ray and generate a PDF report
|
25 |
-
def generate_report(name, age, gender, weight, height, allergies, cause, xray):
|
26 |
image_size = (224, 224)
|
27 |
|
28 |
def predict_fracture(xray_path):
|
@@ -115,6 +152,9 @@ def generate_report(name, age, gender, weight, height, allergies, cause, xray):
|
|
115 |
|
116 |
c.save()
|
117 |
|
|
|
|
|
|
|
118 |
return report_path # Return path for auto-download
|
119 |
|
120 |
# Function to select a sample image
|
@@ -139,6 +179,9 @@ with gr.Blocks() as app:
|
|
139 |
allergies = gr.Textbox(label="Allergies (if any)")
|
140 |
cause = gr.Textbox(label="Cause of Injury")
|
141 |
|
|
|
|
|
|
|
142 |
with gr.Row():
|
143 |
xray = gr.Image(type="filepath", label="Upload X-ray Image")
|
144 |
|
@@ -153,7 +196,7 @@ with gr.Blocks() as app:
|
|
153 |
|
154 |
submit_button.click(
|
155 |
generate_report,
|
156 |
-
inputs=[name, age, gender, weight, height, allergies, cause, xray],
|
157 |
outputs=[output_file],
|
158 |
)
|
159 |
|
|
|
1 |
import os
|
2 |
+
import smtplib
|
3 |
+
import ssl
|
4 |
+
from email.message import EmailMessage
|
5 |
+
|
6 |
os.environ["CUDA_VISIBLE_DEVICES"] = "-1" # Force TensorFlow to use CPU
|
7 |
|
8 |
import gradio as gr
|
|
|
25 |
# List of sample images
|
26 |
sample_images = [f"samples/{img}" for img in os.listdir("samples") if img.endswith((".png", ".jpg", ".jpeg"))]
|
27 |
|
28 |
+
# Function to send email
|
29 |
+
def send_email(patient_email, report_path, patient_name):
|
30 |
+
sender_email = "[email protected]"
|
31 |
+
sender_password = "your_email_password"
|
32 |
+
|
33 |
+
subject = f"Bone Fracture Report for {patient_name}"
|
34 |
+
body = f"""
|
35 |
+
Dear {patient_name},
|
36 |
+
|
37 |
+
Your bone fracture diagnosis report is attached.
|
38 |
+
|
39 |
+
If you have any concerns, consult your doctor.
|
40 |
+
|
41 |
+
Regards,
|
42 |
+
Hospital Team
|
43 |
+
"""
|
44 |
+
|
45 |
+
msg = EmailMessage()
|
46 |
+
msg["From"] = sender_email
|
47 |
+
msg["To"] = patient_email
|
48 |
+
msg["Subject"] = subject
|
49 |
+
msg.set_content(body)
|
50 |
+
|
51 |
+
# Attach PDF file
|
52 |
+
with open(report_path, "rb") as file:
|
53 |
+
msg.add_attachment(file.read(), maintype="application", subtype="pdf", filename=os.path.basename(report_path))
|
54 |
+
|
55 |
+
# Secure email sending
|
56 |
+
context = ssl.create_default_context()
|
57 |
+
with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as server:
|
58 |
+
server.login(sender_email, sender_password)
|
59 |
+
server.send_message(msg)
|
60 |
+
|
61 |
# Function to process X-ray and generate a PDF report
|
62 |
+
def generate_report(name, age, gender, weight, height, allergies, cause, xray, email):
|
63 |
image_size = (224, 224)
|
64 |
|
65 |
def predict_fracture(xray_path):
|
|
|
152 |
|
153 |
c.save()
|
154 |
|
155 |
+
# Send the report via email
|
156 |
+
send_email(email, report_path, name)
|
157 |
+
|
158 |
return report_path # Return path for auto-download
|
159 |
|
160 |
# Function to select a sample image
|
|
|
179 |
allergies = gr.Textbox(label="Allergies (if any)")
|
180 |
cause = gr.Textbox(label="Cause of Injury")
|
181 |
|
182 |
+
with gr.Row():
|
183 |
+
email = gr.Textbox(label="Patient Email", type="email")
|
184 |
+
|
185 |
with gr.Row():
|
186 |
xray = gr.Image(type="filepath", label="Upload X-ray Image")
|
187 |
|
|
|
196 |
|
197 |
submit_button.click(
|
198 |
generate_report,
|
199 |
+
inputs=[name, age, gender, weight, height, allergies, cause, xray, email],
|
200 |
outputs=[output_file],
|
201 |
)
|
202 |
|