Spaces:
Sleeping
Sleeping
Riccardo Taormina
commited on
Upload 103 files
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- app.py +95 -0
- images/00002720.png +0 -0
- images/00046169.png +0 -0
- images/00055654.png +0 -0
- images/00069800.png +0 -0
- images/00071719.png +0 -0
- images/00076692.png +0 -0
- images/00088775.png +0 -0
- images/00116458.png +0 -0
- images/00117348.png +0 -0
- images/00122097.png +0 -0
- images/00128889.png +0 -0
- images/00134089.png +0 -0
- images/00173582.png +0 -0
- images/00175871.png +0 -0
- images/00177468.png +0 -0
- images/00184032.png +0 -0
- images/00189308.png +0 -0
- images/00190227.png +0 -0
- images/00210684.png +0 -0
- images/00213396.png +0 -0
- images/00220697.png +0 -0
- images/00221213.png +0 -0
- images/00222387.png +0 -0
- images/00224834.png +0 -0
- images/00225888.png +0 -0
- images/00231002.png +0 -0
- images/00231010.png +0 -0
- images/00234428.png +0 -0
- images/00235099.png +0 -0
- images/00242368.png +0 -0
- images/00242381.png +0 -0
- images/00246069.png +0 -0
- images/00248494.png +0 -0
- images/00251253.png +0 -0
- images/00251271.png +0 -0
- images/00255694.png +0 -0
- images/00260898.png +0 -0
- images/00276076.png +0 -0
- images/00287653.png +0 -0
- images/00292339.png +0 -0
- images/00292340.png +0 -0
- images/00292342.png +0 -0
- images/00298504.png +0 -0
- images/00299021.png +0 -0
- images/00305000.png +0 -0
- images/00306868.png +0 -0
- images/00306871.png +0 -0
- images/00307807.png +0 -0
- images/00309864.png +0 -0
app.py
ADDED
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import gradio as gr
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
df_table_dsc = pd.read_csv('./results/df_table_dsc.csv')
|
6 |
+
df_table_prd = pd.read_csv('./results/df_table_prd.csv')
|
7 |
+
n_lines = 12
|
8 |
+
|
9 |
+
defect_dict = {'NoDefect':'No defect', 'RO': 'Defect: Roots', 'OB': 'Defect: Surface damage',
|
10 |
+
'RB': 'Defect: Cracks, breaks, and collapses', 'PF': 'Defect: Production error',
|
11 |
+
'DE':'Defect: Deformation'}
|
12 |
+
|
13 |
+
|
14 |
+
css="""
|
15 |
+
#image-out {
|
16 |
+
height: 400px;
|
17 |
+
width: 400px;
|
18 |
+
}
|
19 |
+
"""
|
20 |
+
|
21 |
+
def conv_int(txt):
|
22 |
+
try:
|
23 |
+
return (int(txt))
|
24 |
+
except:
|
25 |
+
return 'NaN'
|
26 |
+
|
27 |
+
def return_prev(index):
|
28 |
+
# Update current index based on navigation input
|
29 |
+
index -=1
|
30 |
+
# Ensure index is within bounds
|
31 |
+
index = max(0, min(index, len(df_table_dsc) - 1))
|
32 |
+
|
33 |
+
image_path, gpt4, gpt4b, cogvlm, llava, defect_class, predictions = return_image(index)
|
34 |
+
return index, index, image_path, gpt4, gpt4b, cogvlm, llava, defect_class, predictions
|
35 |
+
|
36 |
+
def return_next(index):
|
37 |
+
# Update current index based on navigation input
|
38 |
+
index +=1
|
39 |
+
# Ensure index is within bounds
|
40 |
+
index = max(0, min(index, len(df_table_dsc) - 1))
|
41 |
+
image_path, gpt4, gpt4b, cogvlm, llava, defect_class, predictions = return_image(index)
|
42 |
+
return index, index, image_path, gpt4, gpt4b, cogvlm, llava, defect_class, predictions
|
43 |
+
|
44 |
+
def return_image(index):
|
45 |
+
# Fetch row from DataFrame
|
46 |
+
row = df_table_dsc.iloc[index]
|
47 |
+
image_path = f"./images/{row['img_id']}"
|
48 |
+
|
49 |
+
defect_class = defect_dict[row['defect_type']]
|
50 |
+
|
51 |
+
row_prd = df_table_prd.iloc[index]
|
52 |
+
|
53 |
+
predictions = f"XIE:{conv_int(row_prd['Xie']>0.5)}, GPT4:{conv_int(row_prd['GPT4'])}, GPT4s:{conv_int(row_prd['GPT4_basic'])}, CogVLM:{conv_int(row_prd['CogVLM'])}, LLaVA:{conv_int(row_prd['LLaVA'])}"
|
54 |
+
|
55 |
+
# Return iamge path and descriptions
|
56 |
+
return image_path, row['GPT4'], row['GPT4_basic'], row['CogVLM'], row['LLaVA'], defect_class, predictions
|
57 |
+
|
58 |
+
|
59 |
+
with gr.Blocks(css=css) as demo:
|
60 |
+
# gr.Markdown("""
|
61 |
+
## Demo for 'The Potential of Generative AI for the Urban Water Sector'
|
62 |
+
### Riccardo Taormina, Delft University of Technology (TU Delft), Department of Water Management
|
63 |
+
### email: r.taormina@tudelft.nl""")
|
64 |
+
gr.Markdown("""
|
65 |
+
## Testing Large Multimodal Models for Sewer Defect Inspection
|
66 |
+
Press on \<Next\> or \<Previous\> to start!
|
67 |
+
""")
|
68 |
+
index = gr.Number(value=-1, visible=False)
|
69 |
+
with gr.Row():
|
70 |
+
with gr.Column(scale=1):
|
71 |
+
img_out = gr.Image(type="filepath", label="Image", elem_id="image-out")
|
72 |
+
with gr.Row():
|
73 |
+
txt_item = gr.Textbox(label="Sample no.", min_width= 20)
|
74 |
+
txt_defect_class = gr.Textbox(label="Defect class", interactive=False, min_width= 150)
|
75 |
+
txt_xie_pred = gr.Textbox(label="Predictions (XIE = benchmark, 0 = No Defect, 1 = Defect)", min_width= 300, interactive=False)
|
76 |
+
with gr.Row():
|
77 |
+
prev_btn = gr.Button("Previous")
|
78 |
+
next_btn = gr.Button("Next")
|
79 |
+
with gr.Column(scale=1):
|
80 |
+
gr.Markdown('Multimodal descriptions')
|
81 |
+
with gr.Row():
|
82 |
+
txt_out_GPT4 = gr.Textbox(label="GPT4", lines= n_lines, max_lines=n_lines)
|
83 |
+
txt_out_GPT4s = gr.Textbox(label="GPT4 simple", lines= n_lines, max_lines=n_lines)
|
84 |
+
with gr.Row():
|
85 |
+
txt_out_CogVLM = gr.Textbox(label="CogVLM", lines= n_lines, max_lines=n_lines)
|
86 |
+
txt_out_LLaVa = gr.Textbox(label="LLaVa", lines= n_lines, max_lines=n_lines)
|
87 |
+
prev_btn.click(fn=return_prev, inputs=index, outputs=[index, txt_item, img_out,
|
88 |
+
txt_out_GPT4, txt_out_GPT4s,
|
89 |
+
txt_out_CogVLM, txt_out_LLaVa, txt_defect_class, txt_xie_pred])
|
90 |
+
next_btn.click(fn=return_next, inputs=index, outputs=[index, txt_item, img_out,
|
91 |
+
txt_out_GPT4, txt_out_GPT4s,
|
92 |
+
txt_out_CogVLM, txt_out_LLaVa, txt_defect_class, txt_xie_pred])
|
93 |
+
|
94 |
+
if __name__ == "__main__":
|
95 |
+
demo.launch()
|
images/00002720.png
ADDED
images/00046169.png
ADDED
images/00055654.png
ADDED
images/00069800.png
ADDED
images/00071719.png
ADDED
images/00076692.png
ADDED
images/00088775.png
ADDED
images/00116458.png
ADDED
images/00117348.png
ADDED
images/00122097.png
ADDED
images/00128889.png
ADDED
images/00134089.png
ADDED
images/00173582.png
ADDED
images/00175871.png
ADDED
images/00177468.png
ADDED
images/00184032.png
ADDED
images/00189308.png
ADDED
images/00190227.png
ADDED
images/00210684.png
ADDED
images/00213396.png
ADDED
images/00220697.png
ADDED
images/00221213.png
ADDED
images/00222387.png
ADDED
images/00224834.png
ADDED
images/00225888.png
ADDED
images/00231002.png
ADDED
images/00231010.png
ADDED
images/00234428.png
ADDED
images/00235099.png
ADDED
images/00242368.png
ADDED
images/00242381.png
ADDED
images/00246069.png
ADDED
images/00248494.png
ADDED
images/00251253.png
ADDED
images/00251271.png
ADDED
images/00255694.png
ADDED
images/00260898.png
ADDED
images/00276076.png
ADDED
images/00287653.png
ADDED
images/00292339.png
ADDED
images/00292340.png
ADDED
images/00292342.png
ADDED
images/00298504.png
ADDED
images/00299021.png
ADDED
images/00305000.png
ADDED
images/00306868.png
ADDED
images/00306871.png
ADDED
images/00307807.png
ADDED
images/00309864.png
ADDED