Spaces:
Sleeping
Sleeping
Arifin commited on
Commit ·
9e577f7
1
Parent(s): 2558cde
stable2
Browse files
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from roboflow import Roboflow
|
| 3 |
import numpy as np
|
|
@@ -51,8 +52,7 @@ def get_inspection_recommendation(total_area):
|
|
| 51 |
return "Immediate inspection required."
|
| 52 |
|
| 53 |
# Define a Gradio interface to input a URL, run inference, and calculate corrosion areas
|
| 54 |
-
|
| 55 |
-
def url_infer_and_calculate(url, location=None, unit="pixels", conversion_factor=1, corrosion_type=None, inspection_standards=None, ndt_methods=None, recommendation=None, files=None):
|
| 56 |
try:
|
| 57 |
# Run inference using the Roboflow script
|
| 58 |
rf_project = rf.workspace().project("corrosion-instance-segmentation-sfcpc")
|
|
@@ -75,23 +75,11 @@ def url_infer_and_calculate(url, location=None, unit="pixels", conversion_factor
|
|
| 75 |
# Write DataFrame to local CSV file with index included immediately after creating it.
|
| 76 |
df.to_csv('Corrosion_Report.csv', index=False)
|
| 77 |
|
| 78 |
-
|
| 79 |
-
result = {
|
| 80 |
-
"corrosion_type": corrosion_type,
|
| 81 |
-
"inspection_standards": inspection_standards,
|
| 82 |
-
"ndt_methods": ndt_methods,
|
| 83 |
-
"manual_recommendation": recommendation,
|
| 84 |
-
"files": [f.name for f in files] if files else []
|
| 85 |
-
}
|
| 86 |
-
|
| 87 |
-
# Return the path of the CSV file along with other outputs.
|
| 88 |
-
return img, corrosion_areas, prediction_json, os.path.abspath('Corrosion_Report.csv'), result
|
| 89 |
|
| 90 |
except Exception as e:
|
| 91 |
return {"error": str(e)}
|
| 92 |
|
| 93 |
-
|
| 94 |
-
|
| 95 |
# Create a Gradio interface for URL input, inference, and corrosion area calculation
|
| 96 |
iface = gr.Interface(
|
| 97 |
fn=url_infer_and_calculate,
|
|
@@ -99,17 +87,22 @@ iface = gr.Interface(
|
|
| 99 |
gr.inputs.Textbox(label="Enter the URL of an image"),
|
| 100 |
gr.inputs.Textbox(label="Enter the Location"),
|
| 101 |
gr.inputs.Dropdown(choices=["pixels", "cm??"], label="Area Unit"),
|
| 102 |
-
gr.inputs.Textbox(label="Conversion Factor")
|
| 103 |
-
gr.inputs.Textbox(label="Enter Corrosion Type"),
|
| 104 |
-
gr.inputs.CheckboxGroup(choices=[f"Standard {i+1}" for i in range(10)], label="Inspection Standards"),
|
| 105 |
-
gr.inputs.CheckboxGroup(choices=["UT thickness", "UT scan", "Phased Array UT", "Short range UT", "Long range UT", "MT", "PT", "Acfm", "Pulse eddy current", "magnetic flux leakage"], label="NDT Inspection Methods"),
|
| 106 |
-
gr.inputs.Textbox(label="Enter Manual Recommendation"),
|
| 107 |
-
*[gr.inputs.File(label=f"Upload Supporting Data {i+1}") for i in range(10)]
|
| 108 |
],
|
| 109 |
-
outputs=[gr.outputs.Image(type="pil"), "json", "json"
|
| 110 |
title="Tim CCG",
|
| 111 |
description="Enter the URL of an image to perform rust detection and calculate corrosion areas.",
|
| 112 |
)
|
| 113 |
|
| 114 |
# Launch the Gradio interface
|
| 115 |
iface.launch(debug=False, share=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#import library
|
| 2 |
import gradio as gr
|
| 3 |
from roboflow import Roboflow
|
| 4 |
import numpy as np
|
|
|
|
| 52 |
return "Immediate inspection required."
|
| 53 |
|
| 54 |
# Define a Gradio interface to input a URL, run inference, and calculate corrosion areas
|
| 55 |
+
def url_infer_and_calculate(url, location, unit="pixels", conversion_factor=1):
|
|
|
|
| 56 |
try:
|
| 57 |
# Run inference using the Roboflow script
|
| 58 |
rf_project = rf.workspace().project("corrosion-instance-segmentation-sfcpc")
|
|
|
|
| 75 |
# Write DataFrame to local CSV file with index included immediately after creating it.
|
| 76 |
df.to_csv('Corrosion_Report.csv', index=False)
|
| 77 |
|
| 78 |
+
return img, corrosion_areas, prediction_json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
except Exception as e:
|
| 81 |
return {"error": str(e)}
|
| 82 |
|
|
|
|
|
|
|
| 83 |
# Create a Gradio interface for URL input, inference, and corrosion area calculation
|
| 84 |
iface = gr.Interface(
|
| 85 |
fn=url_infer_and_calculate,
|
|
|
|
| 87 |
gr.inputs.Textbox(label="Enter the URL of an image"),
|
| 88 |
gr.inputs.Textbox(label="Enter the Location"),
|
| 89 |
gr.inputs.Dropdown(choices=["pixels", "cm??"], label="Area Unit"),
|
| 90 |
+
gr.inputs.Textbox(label="Conversion Factor")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
],
|
| 92 |
+
outputs=[gr.outputs.Image(type="pil"), "json", "json"],
|
| 93 |
title="Tim CCG",
|
| 94 |
description="Enter the URL of an image to perform rust detection and calculate corrosion areas.",
|
| 95 |
)
|
| 96 |
|
| 97 |
# Launch the Gradio interface
|
| 98 |
iface.launch(debug=False, share=False)
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
|