Update app.py
Browse files
app.py
CHANGED
|
@@ -43,42 +43,21 @@ def generate_docs():
|
|
| 43 |
row_cells[1].text = docs[i][1]
|
| 44 |
row_cells[2].text = docs[i][2]
|
| 45 |
document.save("casting_report.docx")
|
| 46 |
-
return [gr.UploadButton(visible=True), gr.DownloadButton(visible=True)]
|
| 47 |
|
|
|
|
|
|
|
| 48 |
|
| 49 |
with gr.Blocks() as demo:
|
| 50 |
with gr.Column():
|
| 51 |
f = gr.File(file_count="multiple", file_types=[".jpg", ".jpeg", ".png", ".bmp", ".tif", ".tiff"])
|
| 52 |
u = gr.Button("Upload files", visible=True)
|
| 53 |
-
|
|
|
|
| 54 |
r = gr.DataFrame(headers=["Index", "File", "Result"])
|
| 55 |
|
| 56 |
-
u.click(upload_images, f, [r, u,
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
"""
|
| 61 |
-
def upload_images(image_paths):
|
| 62 |
-
df = pd.DataFrame(columns=["Index", "File", "Result"])
|
| 63 |
-
for i in range(len(image_paths)):
|
| 64 |
-
df.loc[i] = [str(i+1), image_paths[i].split("\\")[-1], predict(image_paths[i])]
|
| 65 |
-
return df
|
| 66 |
-
|
| 67 |
-
# Function to preprocess image and predict
|
| 68 |
-
def predict(image_path):
|
| 69 |
-
img = keras.utils.load_img(image_path, target_size=(300, 300))
|
| 70 |
-
img_array = keras.utils.img_to_array(img)
|
| 71 |
-
img_array = keras.ops.expand_dims(img_array, 0)
|
| 72 |
-
prediction = model.predict(img_array)
|
| 73 |
-
class_names = ["Defective", "Normal"] # Class 0: def, Class 1: ok
|
| 74 |
-
predicted_class = class_names[1] if prediction > 0.5 else class_names[0]
|
| 75 |
-
return predicted_class
|
| 76 |
-
|
| 77 |
-
demo = gr.Interface(
|
| 78 |
-
upload_images,
|
| 79 |
-
gr.File(file_count="multiple", file_types=[".jpg", ".jpeg", ".png", ".bmp", ".tif", ".tiff"]),
|
| 80 |
-
gr.DataFrame(headers=["Index", "File", "Result"])
|
| 81 |
-
)
|
| 82 |
-
"""
|
| 83 |
|
| 84 |
demo.launch(share=True, debug=True)
|
|
|
|
| 43 |
row_cells[1].text = docs[i][1]
|
| 44 |
row_cells[2].text = docs[i][2]
|
| 45 |
document.save("casting_report.docx")
|
| 46 |
+
return [gr.UploadButton(visible=True), gr.DownloadButton(visible=True), gr.DownloadButton(label=f"Download", value="casting_report.docx", visible=True)]
|
| 47 |
|
| 48 |
+
def download_file():
|
| 49 |
+
return [gr.UploadButton(visible=True), gr.DownloadButton(visible=True), gr.DownloadButton(visible=True)]
|
| 50 |
|
| 51 |
with gr.Blocks() as demo:
|
| 52 |
with gr.Column():
|
| 53 |
f = gr.File(file_count="multiple", file_types=[".jpg", ".jpeg", ".png", ".bmp", ".tif", ".tiff"])
|
| 54 |
u = gr.Button("Upload files", visible=True)
|
| 55 |
+
d1 = gr.DownloadButton("Download report", visible=True)
|
| 56 |
+
d2 = gr.DownloadButton("download report", visible=False)
|
| 57 |
r = gr.DataFrame(headers=["Index", "File", "Result"])
|
| 58 |
|
| 59 |
+
u.click(upload_images, f, [r, u, d1])
|
| 60 |
+
d1.click(generate_docs, None, [u, d1, d2])
|
| 61 |
+
d2.click(download_file, None, [u, d1, d2])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
demo.launch(share=True, debug=True)
|