Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -85,6 +85,24 @@ def classify_image(input_image,model_selection):
|
|
| 85 |
|
| 86 |
return predicted_class, confidence
|
| 87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
def show_preds_image(image_path,model_selection):
|
| 89 |
mux_value = str(classify_image(image_path,model_selection)[0])
|
| 90 |
img = cv2.imread(image_path)
|
|
@@ -136,7 +154,8 @@ def show_preds_image(image_path,model_selection):
|
|
| 136 |
</body>
|
| 137 |
</html>
|
| 138 |
'''
|
| 139 |
-
|
|
|
|
| 140 |
|
| 141 |
inputs_image = gr.Image(type="filepath", label="Input Image")
|
| 142 |
model_selection = gr.Dropdown(["VGG19","InceptionV3","ResNet50","Efficientnet"],label="Model selection")
|
|
@@ -146,12 +165,12 @@ output_text = gr.Textbox(label="prediction & confidence")
|
|
| 146 |
inform = gr.Textbox(label="Information about the place")
|
| 147 |
g_map = gr.HTML(label="Place location")
|
| 148 |
info_html = gr.HTML()
|
| 149 |
-
|
| 150 |
|
| 151 |
interface_image = gr.Interface(
|
| 152 |
fn=show_preds_image,
|
| 153 |
inputs=[inputs_image,model_selection],
|
| 154 |
-
outputs=[outputs_image,output_text,inform,info_html,g_map],
|
| 155 |
title="image classification",
|
| 156 |
)
|
| 157 |
|
|
|
|
| 85 |
|
| 86 |
return predicted_class, confidence
|
| 87 |
|
| 88 |
+
def pdf_download(image_path,predicted_class,confidence):
|
| 89 |
+
pdf = FPDF()
|
| 90 |
+
pdf.add_page()
|
| 91 |
+
pdf.image(image_path, x=10, y=10, w=190)
|
| 92 |
+
pdf.set_font("Arial", style='B', size=16)
|
| 93 |
+
pdf.ln(110)
|
| 94 |
+
pdf.cell(0, 10, f"Prediction: {predicted_class}", ln=True, align='C')
|
| 95 |
+
pdf.cell(0, 10, f"Confidence: {confidence:.2%}", ln=True, align='C')
|
| 96 |
+
pdf.set_font("Arial", size=12)
|
| 97 |
+
pdf.ln(10)
|
| 98 |
+
pdf.multi_cell(0, 10, information_text)
|
| 99 |
+
pdf.ln(10)
|
| 100 |
+
pdf.multi_cell(0, 10, link_info_html)
|
| 101 |
+
pdf_buffer = BytesIO()
|
| 102 |
+
pdf.output(pdf_buffer)
|
| 103 |
+
pdf_buffer.seek(0)
|
| 104 |
+
return pdf
|
| 105 |
+
|
| 106 |
def show_preds_image(image_path,model_selection):
|
| 107 |
mux_value = str(classify_image(image_path,model_selection)[0])
|
| 108 |
img = cv2.imread(image_path)
|
|
|
|
| 154 |
</body>
|
| 155 |
</html>
|
| 156 |
'''
|
| 157 |
+
_pdf =pdf_download(image_path,mux_value,float(conf[-1]))
|
| 158 |
+
return img,conf,informations,link_info,google_map,_pdf
|
| 159 |
|
| 160 |
inputs_image = gr.Image(type="filepath", label="Input Image")
|
| 161 |
model_selection = gr.Dropdown(["VGG19","InceptionV3","ResNet50","Efficientnet"],label="Model selection")
|
|
|
|
| 165 |
inform = gr.Textbox(label="Information about the place")
|
| 166 |
g_map = gr.HTML(label="Place location")
|
| 167 |
info_html = gr.HTML()
|
| 168 |
+
pdf_output = gr.File(label="Download PDF")
|
| 169 |
|
| 170 |
interface_image = gr.Interface(
|
| 171 |
fn=show_preds_image,
|
| 172 |
inputs=[inputs_image,model_selection],
|
| 173 |
+
outputs=[outputs_image,output_text,inform,info_html,g_map,pdf_output],
|
| 174 |
title="image classification",
|
| 175 |
)
|
| 176 |
|