LPX commited on
Commit
179d07c
·
1 Parent(s): cbd537f

✨ feat(html):

Browse files

- add new parameter (model_path) for external link enabling access to individual models
- enumerate models with unique model paths

- fix default accordion open state

Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -137,7 +137,7 @@ def generate_results_html(results):
137
  else:
138
  return 'bg-gray-300 text-gray-700', 'bg-gray-400', 'bg-gray-100', 'bg-gray-700 text-gray-700', 'bg-gray-200'
139
 
140
- def generate_tile_html(index, result, model_name, contributor):
141
  label = result[-1]
142
  header_colors = get_header_color(label)
143
  real_conf = result[2]
@@ -180,7 +180,7 @@ def generate_results_html(results):
180
  <div class="flex flex-col items-start">
181
  <h4 class="mt-4 text-sm font-semibold tracking-wide">{model_name}</h4>
182
  <div class="text-xs font-mono">Real: {real_conf:.4f}, AI: {ai_conf:.4f}</div>
183
- <a class="mt-2 text-xs tracking-wide">@{contributor} / more info</a>
184
  </div>
185
  </div>
186
  """
@@ -189,17 +189,17 @@ def generate_results_html(results):
189
  <link href="https://unpkg.com/[email protected]/dist/tailwind.min.css" rel="stylesheet">
190
  <div class="container mx-auto">
191
  <div class="grid xl:grid-cols-5 md:grid-cols-5 grid-cols-1 gap-1">
192
- {generate_tile_html(0, results[0], "SwinV2 Based", "haywoodsloan")}
193
- {generate_tile_html(1, results[1], "ViT Based", "Heem2")}
194
- {generate_tile_html(2, results[2], "SDXL Dataset", "Organika")}
195
- {generate_tile_html(3, results[3], "SDXL + FLUX", "cmckinle")}
196
- {generate_tile_html(4, results[4], "Vit Based", "prithivMLmods")}
197
- {generate_tile_html(5, results[5], "Vit Based, Newer Dataset", "prithivMLmods")}
198
  </div>
199
  </div>
200
  """
201
  return html_content
202
- # Modify the predict_image function to return the HTML content
203
  def predict_image_with_html(img, confidence_threshold):
204
  img_pil, results = predict_image(img, confidence_threshold)
205
  html_content = generate_results_html(results)
@@ -217,7 +217,7 @@ with gr.Blocks() as iface:
217
  inputs = [image_input, confidence_slider]
218
  predict_button = gr.Button("Predict")
219
  with gr.Column(scale=2):
220
- with gr.Accordion("Project OpenSight - Model Evaluations & Playground", open=True, elem_id="project_accordion"):
221
  gr.Markdown("## OpenSight is a SOTA gen. image detection model, in pre-release prep.\n\nThis HF Space is a temporary home for us and the public to evaluate the shortcomings of current open source models.\n\n<-- Feel free to play around by starting with an image as we prepare our formal announcement.")
222
  image_output = gr.Image(label="Processed Image", visible=False)
223
  # Custom HTML component to display results in 5 columns
 
137
  else:
138
  return 'bg-gray-300 text-gray-700', 'bg-gray-400', 'bg-gray-100', 'bg-gray-700 text-gray-700', 'bg-gray-200'
139
 
140
+ def generate_tile_html(index, result, model_name, contributor, model_path):
141
  label = result[-1]
142
  header_colors = get_header_color(label)
143
  real_conf = result[2]
 
180
  <div class="flex flex-col items-start">
181
  <h4 class="mt-4 text-sm font-semibold tracking-wide">{model_name}</h4>
182
  <div class="text-xs font-mono">Real: {real_conf:.4f}, AI: {ai_conf:.4f}</div>
183
+ <a href="https://huggingface.co/{model_path}" target="_blank" class="mt-2 text-xs tracking-wide">by @{contributor}</a>
184
  </div>
185
  </div>
186
  """
 
189
  <link href="https://unpkg.com/[email protected]/dist/tailwind.min.css" rel="stylesheet">
190
  <div class="container mx-auto">
191
  <div class="grid xl:grid-cols-5 md:grid-cols-5 grid-cols-1 gap-1">
192
+ {generate_tile_html(0, results[0], "SwinV2 Based", "haywoodsloan", MODEL_PATHS["model_1"])}
193
+ {generate_tile_html(1, results[1], "ViT Based", "Heem2", MODEL_PATHS["model_2"])}
194
+ {generate_tile_html(2, results[2], "SDXL Dataset", "Organika", MODEL_PATHS["model_3"])}
195
+ {generate_tile_html(3, results[3], "SDXL + FLUX", "cmckinle", MODEL_PATHS["model_4"])}
196
+ {generate_tile_html(4, results[4], "Vit Based", "prithivMLmods", MODEL_PATHS["model_5"])}
197
+ {generate_tile_html(5, results[5], "Vit Based, Newer Dataset", "prithivMLmods", MODEL_PATHS["model_5b"])}
198
  </div>
199
  </div>
200
  """
201
  return html_content
202
+
203
  def predict_image_with_html(img, confidence_threshold):
204
  img_pil, results = predict_image(img, confidence_threshold)
205
  html_content = generate_results_html(results)
 
217
  inputs = [image_input, confidence_slider]
218
  predict_button = gr.Button("Predict")
219
  with gr.Column(scale=2):
220
+ with gr.Accordion("Project OpenSight - Model Evaluations & Playground", open=False, elem_id="project_accordion"):
221
  gr.Markdown("## OpenSight is a SOTA gen. image detection model, in pre-release prep.\n\nThis HF Space is a temporary home for us and the public to evaluate the shortcomings of current open source models.\n\n<-- Feel free to play around by starting with an image as we prepare our formal announcement.")
222
  image_output = gr.Image(label="Processed Image", visible=False)
223
  # Custom HTML component to display results in 5 columns