app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import time
|
| 5 |
+
import os
|
| 6 |
+
import tkinter as tk
|
| 7 |
+
from PIL import Image
|
| 8 |
+
import json
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def image_generator(directory_path):
|
| 12 |
+
for filename in os.listdir(directory_path):
|
| 13 |
+
if filename.endswith(".jpg") or filename.endswith(".png"):
|
| 14 |
+
image_path = os.path.join(directory_path, filename)
|
| 15 |
+
image = Image.open(image_path)
|
| 16 |
+
image_array = np.array(image)
|
| 17 |
+
yield filename,image_array
|
| 18 |
+
|
| 19 |
+
directory_path = "/content/drive/MyDrive/Testdateien"
|
| 20 |
+
|
| 21 |
+
# Create the generator
|
| 22 |
+
image_gen = image_generator(directory_path)
|
| 23 |
+
|
| 24 |
+
def record_input(fname:str, label:str):
|
| 25 |
+
if label != "Pass":
|
| 26 |
+
output = {"fname": fname, "label": label}
|
| 27 |
+
with open("/content/output.txt", 'a') as f:
|
| 28 |
+
json.dump(output, f)
|
| 29 |
+
f.write("\n")
|
| 30 |
+
fname, image = next(image_gen)
|
| 31 |
+
return fname, image
|
| 32 |
+
|
| 33 |
+
def increment():
|
| 34 |
+
global count # Access the global variable 'count'
|
| 35 |
+
count += 1 # Increment 'count' by 1
|
| 36 |
+
return f"{count}" # Return the updated value of 'count' as a string
|
| 37 |
+
|
| 38 |
+
def start():
|
| 39 |
+
fname, image = next(image_gen)
|
| 40 |
+
return fname, image
|
| 41 |
+
|
| 42 |
+
with gr.Blocks(fill_height=True, fill_width=True) as demo:
|
| 43 |
+
gr.Markdown("#DiseaseDetection")
|
| 44 |
+
output = gr.Number()
|
| 45 |
+
with gr.Row():
|
| 46 |
+
img_block = gr.Image(visible = True, width = 500, height = 500, show_fullscreen_button = True, show_share_button = False, show_download_button=False, show_label=False)
|
| 47 |
+
file_name = gr.Textbox(info="File name", visible = False)
|
| 48 |
+
with gr.Row():
|
| 49 |
+
disease1_btn = gr.Button(value = "disease1", interactive=True, visible = True)
|
| 50 |
+
disease2_btn = gr.Button(value = "disease2",interactive=True, visible = True)
|
| 51 |
+
disease3_btn = gr.Button(value = "disease3",interactive=True, visible = True)
|
| 52 |
+
with gr.Row():
|
| 53 |
+
disease4_btn = gr.Button(value = "disease4",interactive=True, visible = True)
|
| 54 |
+
disease5_btn = gr.Button(value = "disease5",interactive=True, visible = True)
|
| 55 |
+
nodisease_btn = gr.Button(value = "no disease",interactive=True, visible = True)
|
| 56 |
+
with gr.Row():
|
| 57 |
+
start_btn = gr.Button("Start")
|
| 58 |
+
disease1_btn.click(fn = record_input, inputs = [file_name, disease1_btn], outputs=[file_name,img_block])
|
| 59 |
+
disease2_btn.click(fn = record_input, inputs = [file_name, disease2_btn], outputs=[file_name,img_block])
|
| 60 |
+
disease3_btn.click(fn = record_input, inputs = [file_name, disease3_btn], outputs=[file_name,img_block])
|
| 61 |
+
disease4_btn.click(fn = record_input, inputs = [file_name, disease4_btn], outputs=[file_name,img_block])
|
| 62 |
+
disease5_btn.click(fn = record_input, inputs = [file_name, disease5_btn], outputs=[file_name,img_block])
|
| 63 |
+
nodisease_btn.click(fn = record_input, inputs = [file_name, nodisease_btn], outputs=[file_name,img_block])
|
| 64 |
+
start_btn.click(fn = start, outputs = [file_name,img_block])
|
| 65 |
+
disease1_btn.click(fn=increment, outputs=output)
|
| 66 |
+
disease2_btn.click(fn=increment, outputs=output)
|
| 67 |
+
disease3_btn.click(fn=increment, outputs=output)
|
| 68 |
+
disease4_btn.click(fn=increment, outputs=output)
|
| 69 |
+
disease5_btn.click(fn=increment, outputs=output)
|
| 70 |
+
nodisease_btn.click(fn=increment, outputs=output)
|
| 71 |
+
|
| 72 |
+
demo.queue()
|
| 73 |
+
demo.launch(share=True, debug=True)
|