2021-07-03 05:28:47 +08:00
|
|
|
import gradio as gr
|
|
|
|
import numpy as np
|
2021-07-07 07:43:59 +08:00
|
|
|
from fpdf import FPDF
|
|
|
|
import os
|
|
|
|
import tempfile
|
2021-07-03 05:28:47 +08:00
|
|
|
|
|
|
|
def disease_report(img, scan_for, generate_report):
|
|
|
|
results = []
|
|
|
|
for i, mode in enumerate(["Red", "Green", "Blue"]):
|
|
|
|
color_filter = np.array([0, 0, 0])
|
|
|
|
color_filter[i] = 1
|
|
|
|
results.append([mode, img * color_filter])
|
2021-07-07 07:43:59 +08:00
|
|
|
tmp_dir = tempfile.gettempdir()
|
|
|
|
report = os.path.join(tmp_dir, "report.pdf")
|
|
|
|
if generate_report:
|
|
|
|
pdf = FPDF()
|
|
|
|
pdf.add_page()
|
|
|
|
pdf.set_font("Arial", size=15)
|
|
|
|
pdf.cell(200, 10, txt="Disease Report",
|
|
|
|
ln=1, align='C')
|
|
|
|
pdf.cell(200, 10, txt="A Gradio Demo.",
|
|
|
|
ln=2, align='C')
|
|
|
|
pdf.output(report)
|
|
|
|
return results, report if generate_report else None
|
2021-07-03 05:28:47 +08:00
|
|
|
|
|
|
|
iface = gr.Interface(disease_report,
|
|
|
|
[
|
|
|
|
"image",
|
|
|
|
gr.inputs.CheckboxGroup(["Cancer", "Rash", "Heart Failure", "Stroke", "Diabetes", "Pneumonia"]),
|
|
|
|
"checkbox"
|
|
|
|
],
|
|
|
|
[
|
|
|
|
gr.outputs.Carousel(["text", "image"], label="Disease"),
|
|
|
|
gr.outputs.File(label="Report")
|
|
|
|
],
|
|
|
|
title="Disease Report",
|
|
|
|
description="Upload an Xray and select the diseases to scan for.",
|
|
|
|
theme="compact",
|
2021-07-07 07:43:59 +08:00
|
|
|
flagging_options=["good", "bad", "etc"],
|
|
|
|
allow_flagging="auto"
|
2021-07-03 05:28:47 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
iface.launch()
|