File size: 7,684 Bytes
b3399e1
 
 
73829b1
b3399e1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e7d3e10
b3399e1
 
 
1731a35
e7d3e10
460a278
e7d3e10
 
 
 
 
 
b3399e1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2bcb597
b3399e1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
from ImageNet import image2net
from CV2Net import cv2net
from Download import save_csv
import gradio as gr

css = css = """
  .action-btn {
    align-items: center;
    appearance: none;
    background-image: radial-gradient(100% 100% at 100% 0, #5aff76 0, #07911a 100%);
    border: 0;
    border-radius: 6px;
    box-shadow: rgba(45, 35, 66, .4) 0 2px 4px,rgba(45, 35, 66, .3) 0 7px 13px -3px,rgba(58, 65, 111, .5) 0 -3px 0 inset;
    box-sizing: border-box;
    color: #0c0b0b;
    cursor: pointer;
    display: inline-flex;
    font-family: "JetBrains Mono",monospace;
    height: 48px;
    justify-content: center;
    line-height: 1;
    list-style: none;
    overflow: hidden;
    padding-left: 16px;
    padding-right: 16px;
    position: relative;
    text-align: left;
    text-decoration: none;
    transition: box-shadow .15s,transform .15s;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    white-space: nowrap;
    will-change: box-shadow,transform;
    font-size: 18px;
  }

  .action-btn:focus {
    outline: none;
    box-shadow: none
  }

  .action-btn:hover {
    box-shadow: rgba(45, 35, 66, .4) 0 4px 8px, rgba(45, 35, 66, .3) 0 7px 13px -3px, #3ce065 0 -3px 0 inset;
    transform: translateY(-2px);
  }

  .action-btn:active {
    box-shadow: #3ce065 0 3px 7px inset;
    transform: translateY(2px);
  }

  /* Enhanced dark theme for dataframe - Multiple selectors for compatibility */
  #dark-df,
  #dark-df .MuiDataGrid-root,
  #dark-df .dataframe,
  #dark-df .gr-dataframe,
  #dark-df table {
    background-color: #0a0a0a !important;
    color: #e8e8e8 !important;
    border: 2px solid #404040 !important;
    border-radius: 8px !important;
    font-size: 14px;
  }

  /* Headers for both MUI and standard tables */
  #dark-df .MuiDataGrid-columnHeaders,
  #dark-df thead,
  #dark-df th {
    background-color: #1a1a1a !important;
    color: #ffffff !important;
    border-bottom: 2px solid #505050 !important;
    font-weight: 600 !important;
  }

  #dark-df .MuiDataGrid-columnHeader {
    border-right: 1px solid #404040 !important;
  }

  /* Cells for both MUI and standard tables */
  #dark-df .MuiDataGrid-cell,
  #dark-df td {
    background-color: #0a0a0a !important;
    color: #e8e8e8 !important;
    border-bottom: 1px solid #333333 !important;
    border-right: 1px solid #333333 !important;
    padding: 8px 12px !important;
  }

  #dark-df .MuiDataGrid-cell:last-of-type {
    border-right: none !important;
  }

  /* Rows for both MUI and standard tables */
  #dark-df .MuiDataGrid-row,
  #dark-df tr {
    background-color: #0a0a0a !important;
  }

  #dark-df .MuiDataGrid-row:nth-of-type(even),
  #dark-df tr:nth-of-type(even) {
    background-color: #111111 !important;
  }

  #dark-df .MuiDataGrid-row:hover,
  #dark-df tr:hover {
    background-color: #1f1f1f !important;
  }

  #dark-df .MuiDataGrid-row:nth-of-type(even):hover,
  #dark-df tr:nth-of-type(even):hover {
    background-color: #1f1f1f !important;
  }

  #dark-df .MuiDataGrid-footerContainer {
    background-color: #1a1a1a !important;
    color: #cccccc !important;
    border-top: 2px solid #505050 !important;
  }

  /* Add Gradio-specific dataframe styling */
  #dark-df .gr-dataframe,
  #dark-df .gr-dataframe table,
  #dark-df .gr-dataframe tbody,
  #dark-df .gr-dataframe thead {
    background-color: #0a0a0a !important;
    color: #e8e8e8 !important;
  }

  #dark-df .gr-dataframe th {
    background-color: #1a1a1a !important;
    color: #ffffff !important;
    border: 1px solid #404040 !important;
  }

  #dark-df .gr-dataframe td {
    background-color: #0a0a0a !important;
    color: #e8e8e8 !important;
    border: 1px solid #333333 !important;
  }

  #dark-df .gr-dataframe tr:nth-child(even) td {
    background-color: #111111 !important;
  }

  #dark-df .gr-dataframe tr:hover td {
    background-color: #1f1f1f !important;
  }

  /* Force override any default styling */
  #dark-df * {
    box-sizing: border-box;
  }

  #dark-df .gr-dataframe .gr-button {
    background-color: #333333 !important;
    color: #e8e8e8 !important;
    border: 1px solid #555555 !important;
  }

  #dark-df .gr-dataframe .gr-button:hover {
    background-color: #444444 !important;
  }
  #dark-df .MuiDataGrid-virtualScroller::-webkit-scrollbar {
    width: 8px;
    height: 8px;
  }

  #dark-df .MuiDataGrid-virtualScroller::-webkit-scrollbar-track {
    background: #1a1a1a;
  }

  #dark-df .MuiDataGrid-virtualScroller::-webkit-scrollbar-thumb {
    background: #404040;
    border-radius: 4px;
  }

  #dark-df .MuiDataGrid-virtualScroller::-webkit-scrollbar-thumb:hover {
    background: #505050;
  }

  /* Selection styling */
  #dark-df .MuiDataGrid-row.Mui-selected {
    background-color: #2d4a3e !important;
  }

  #dark-df .MuiDataGrid-row.Mui-selected:hover {
    background-color: #365242 !important;
  }

  #dark-df .MuiDataGrid-cell.Mui-selected {
    background-color: #2d4a3e !important;
  }

  /* Sorting and filtering icons */
  #dark-df .MuiDataGrid-iconSeparator {
    color: #666666 !important;
  }

  #dark-df .MuiDataGrid-sortIcon {
    color: #cccccc !important;
  }

  #dark-df .MuiDataGrid-filterIcon {
    color: #cccccc !important;
  }
"""
with gr.Blocks(
    theme=gr.themes.Base(primary_hue="teal", secondary_hue="amber").set(
    body_background_fill="*neutral_950",
    body_text_color="*neutral_200",
    background_fill_primary="*neutral_900",
    background_fill_secondary="*neutral_800",
    border_color_primary="*neutral_700",
    block_background_fill="*neutral_900",
    input_background_fill="*neutral_800",
    button_primary_background_fill="*primary_600",
    button_primary_background_fill_hover="*primary_700",
    button_secondary_background_fill="*neutral_700",
    button_secondary_background_fill_hover="*neutral_600"
),
    css=css,
) as app:
  gr.HTML("<h1 style='text-align:center;color:#07911a;font-weight:bold;'>🖼️ Image To Network 🕸️</h1>")
  with gr.Column(elem_classes="cols"):
    with gr.Row():
      gr.Markdown("""
      How To Use:
      - Visit [Google AI Studio](https://aistudio.google.com/app/apikey) and obtain your Google API key.
      - Paste your Google API key
      - Upload image files from computer
      - Generate network data from uploaded images
      - Download data for analysis in NodeXL
      """)
      gr.Markdown("")    
      gr.Markdown("""
      Practical Use Cases:
      - Manufacturing and quality control
      - Urban planning and Infrastructure
      - Home organization and design
      - Medical diagnostics
      - Automotive repair      
      """)
    with gr.Row():
      api_key = gr.Textbox(label="🔑 Google API Key",placeholder="Paste your Google API Key",elem_classes="widgets")
    with gr.Row():
      image_input = gr.File(file_types=["image"],
                      label="🖼️ Upload Image Files",
                      file_count="multiple",
                      elem_classes="widgets",
                      interactive=True)
      df_output = gr.Dataframe(label="🕸️ Network Data", elem_id="dark-df")
    with gr.Column(elem_classes="cols"):
      with gr.Row():
        btn = gr.Button("🧬 Generate Data",elem_classes="action-btn", elem_id = "click")
        download_btn = gr.DownloadButton("⬇️ Download Data", elem_classes="action-btn")
      with gr.Column():
        with gr.Row():
          clear = gr.Button("🗑️ Clear",value="", elem_classes="action-btn")


  btn.click(image2net, inputs=[image_input,api_key], outputs=[df_output, download_btn])
  clear.click(lambda: [None,None,None], inputs = [], outputs = [image_input, df_output])

 
if __name__ == "__main__":
  app.launch()