Spaces:
Sleeping
Sleeping
Arifin
commited on
Commit
·
6a580dd
1
Parent(s):
f2209a5
csv 1
Browse files
app.py
CHANGED
|
@@ -7,7 +7,7 @@ import requests
|
|
| 7 |
from io import BytesIO
|
| 8 |
import pandas as pd
|
| 9 |
import os
|
| 10 |
-
|
| 11 |
# Initialize Roboflow with your API key
|
| 12 |
rf = Roboflow(api_key="kKDoCn3ABT9AKeFQDCB4")
|
| 13 |
|
|
@@ -52,7 +52,6 @@ def get_inspection_recommendation(total_area):
|
|
| 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 |
def url_infer_and_calculate(url, location, unit="pixels", conversion_factor=1, corrosion_type="", inspection_standards=[], ndt_methods=[], manual_recommendation="", supporting_data=""):
|
| 57 |
try:
|
| 58 |
# Run inference using the Roboflow script
|
|
@@ -76,7 +75,10 @@ def url_infer_and_calculate(url, location, unit="pixels", conversion_factor=1, c
|
|
| 76 |
# Write DataFrame to local CSV file with index included immediately after creating it.
|
| 77 |
df.to_csv('Corrosion_Report.csv', index=False)
|
| 78 |
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
except Exception as e:
|
| 82 |
return {"error": str(e)}
|
|
@@ -87,7 +89,7 @@ iface = gr.Interface(
|
|
| 87 |
inputs=[
|
| 88 |
gr.inputs.Textbox(label="Enter the URL of an image"),
|
| 89 |
gr.inputs.Textbox(label="Enter the Location"),
|
| 90 |
-
gr.inputs.Dropdown(choices=["pixels", "cm"], label="Area Unit"),
|
| 91 |
gr.inputs.Textbox(label="Conversion Factor"),
|
| 92 |
gr.inputs.Textbox(label="Enter the Corrosion Type"),
|
| 93 |
gr.inputs.CheckboxGroup(choices=[f"Standard {i+1}" for i in range(10)], label="Inspection Standards"),
|
|
@@ -95,22 +97,10 @@ iface = gr.Interface(
|
|
| 95 |
gr.inputs.Textbox(label="Enter Manual Recommendation"),
|
| 96 |
gr.inputs.Textbox(lines=5, label="Enter Supporting Data URLs (separated by commas)")
|
| 97 |
],
|
| 98 |
-
outputs=[gr.outputs.Image(type="pil"), "json", "json"],
|
| 99 |
title="Tim CCG",
|
| 100 |
description="Enter the URL of an image to perform rust detection and calculate corrosion areas.",
|
| 101 |
)
|
| 102 |
|
| 103 |
# Launch the Gradio interface
|
| 104 |
iface.launch(debug=False, share=False)
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
|
|
|
| 7 |
from io import BytesIO
|
| 8 |
import pandas as pd
|
| 9 |
import os
|
| 10 |
+
|
| 11 |
# Initialize Roboflow with your API key
|
| 12 |
rf = Roboflow(api_key="kKDoCn3ABT9AKeFQDCB4")
|
| 13 |
|
|
|
|
| 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, corrosion_type="", inspection_standards=[], ndt_methods=[], manual_recommendation="", supporting_data=""):
|
| 56 |
try:
|
| 57 |
# Run inference using the Roboflow script
|
|
|
|
| 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 |
+
# Write DataFrame to a string in CSV format
|
| 79 |
+
csv_string = df.to_csv(index=False)
|
| 80 |
+
|
| 81 |
+
return img, corrosion_areas, prediction_json, csv_string
|
| 82 |
|
| 83 |
except Exception as e:
|
| 84 |
return {"error": str(e)}
|
|
|
|
| 89 |
inputs=[
|
| 90 |
gr.inputs.Textbox(label="Enter the URL of an image"),
|
| 91 |
gr.inputs.Textbox(label="Enter the Location"),
|
| 92 |
+
gr.inputs.Dropdown(choices=["pixels", "cm??"], label="Area Unit"),
|
| 93 |
gr.inputs.Textbox(label="Conversion Factor"),
|
| 94 |
gr.inputs.Textbox(label="Enter the Corrosion Type"),
|
| 95 |
gr.inputs.CheckboxGroup(choices=[f"Standard {i+1}" for i in range(10)], label="Inspection Standards"),
|
|
|
|
| 97 |
gr.inputs.Textbox(label="Enter Manual Recommendation"),
|
| 98 |
gr.inputs.Textbox(lines=5, label="Enter Supporting Data URLs (separated by commas)")
|
| 99 |
],
|
| 100 |
+
outputs=[gr.outputs.Image(type="pil"), "json", "json", gr.outputs.Textbox(label="CSV Data")],
|
| 101 |
title="Tim CCG",
|
| 102 |
description="Enter the URL of an image to perform rust detection and calculate corrosion areas.",
|
| 103 |
)
|
| 104 |
|
| 105 |
# Launch the Gradio interface
|
| 106 |
iface.launch(debug=False, share=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|