Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -30,7 +30,6 @@ def fetch_metadata(api_key, workspace, project, version):
|
|
| 30 |
resp = requests.get(endpoint, params=params)
|
| 31 |
resp.raise_for_status()
|
| 32 |
data = resp.json()
|
| 33 |
-
# Use version-level image count and project-level class counts
|
| 34 |
total_images = data.get('version', {}).get('images') or data.get('project', {}).get('images', 0)
|
| 35 |
classes = data.get('project', {}).get('classes', {})
|
| 36 |
return total_images, classes
|
|
@@ -64,18 +63,25 @@ def make_bar_chart(counts):
|
|
| 64 |
return fig
|
| 65 |
|
| 66 |
|
| 67 |
-
def load_datasets(api_key,
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
df_data = [[cls, cnt] for cls, cnt in aggregated.items()]
|
| 73 |
fig = make_bar_chart(aggregated)
|
| 74 |
return f"{total_images}", df_data, fig, json.dumps(aggregated, indent=2)
|
| 75 |
|
| 76 |
|
| 77 |
def update_classes(df_data):
|
| 78 |
-
# df_data: list of [class_name, count]
|
| 79 |
updated = {row[0]: int(row[1]) for row in df_data if row[0] and isinstance(row[1], (int, float, str)) and str(row[1]).isdigit()}
|
| 80 |
total_images = sum(updated.values())
|
| 81 |
fig = make_bar_chart(updated)
|
|
@@ -87,7 +93,7 @@ def build_ui():
|
|
| 87 |
gr.Markdown("## Roboflow Dataset Inspector")
|
| 88 |
with gr.Row():
|
| 89 |
api_input = gr.Textbox(label="Roboflow API Key", type="password", placeholder="Enter your API key...")
|
| 90 |
-
|
| 91 |
load_btn = gr.Button("Load Datasets")
|
| 92 |
total_out = gr.Textbox(label="Total Images", interactive=False)
|
| 93 |
df = gr.Dataframe(headers=["Class Name", "Count"], row_count=(1, None), col_count=2, interactive=True)
|
|
@@ -96,7 +102,7 @@ def build_ui():
|
|
| 96 |
update_btn = gr.Button("Apply Class Edits")
|
| 97 |
|
| 98 |
load_btn.click(fn=load_datasets,
|
| 99 |
-
inputs=[api_input,
|
| 100 |
outputs=[total_out, df, plot_out, json_out])
|
| 101 |
|
| 102 |
update_btn.click(fn=update_classes,
|
|
|
|
| 30 |
resp = requests.get(endpoint, params=params)
|
| 31 |
resp.raise_for_status()
|
| 32 |
data = resp.json()
|
|
|
|
| 33 |
total_images = data.get('version', {}).get('images') or data.get('project', {}).get('images', 0)
|
| 34 |
classes = data.get('project', {}).get('classes', {})
|
| 35 |
return total_images, classes
|
|
|
|
| 63 |
return fig
|
| 64 |
|
| 65 |
|
| 66 |
+
def load_datasets(api_key, file_objs):
|
| 67 |
+
"""
|
| 68 |
+
Read multiple .txt uploads, parse URLs, and aggregate metadata.
|
| 69 |
+
Returns total images, dataframe data, plot, and JSON mapping.
|
| 70 |
+
"""
|
| 71 |
+
# Combine URLs from all uploaded files
|
| 72 |
+
urls = []
|
| 73 |
+
for file_obj in file_objs:
|
| 74 |
+
content = file_obj.read().decode('utf-8')
|
| 75 |
+
urls.extend([line.strip() for line in content.splitlines() if line.strip()])
|
| 76 |
+
# Remove duplicate URLs while preserving order
|
| 77 |
+
unique_urls = list(dict.fromkeys(urls))
|
| 78 |
+
total_images, aggregated = aggregate_datasets(api_key, unique_urls)
|
| 79 |
df_data = [[cls, cnt] for cls, cnt in aggregated.items()]
|
| 80 |
fig = make_bar_chart(aggregated)
|
| 81 |
return f"{total_images}", df_data, fig, json.dumps(aggregated, indent=2)
|
| 82 |
|
| 83 |
|
| 84 |
def update_classes(df_data):
|
|
|
|
| 85 |
updated = {row[0]: int(row[1]) for row in df_data if row[0] and isinstance(row[1], (int, float, str)) and str(row[1]).isdigit()}
|
| 86 |
total_images = sum(updated.values())
|
| 87 |
fig = make_bar_chart(updated)
|
|
|
|
| 93 |
gr.Markdown("## Roboflow Dataset Inspector")
|
| 94 |
with gr.Row():
|
| 95 |
api_input = gr.Textbox(label="Roboflow API Key", type="password", placeholder="Enter your API key...")
|
| 96 |
+
file_inputs = gr.Files(label="Upload one or more .txt files of Roboflow URLs", file_types=[".txt"])
|
| 97 |
load_btn = gr.Button("Load Datasets")
|
| 98 |
total_out = gr.Textbox(label="Total Images", interactive=False)
|
| 99 |
df = gr.Dataframe(headers=["Class Name", "Count"], row_count=(1, None), col_count=2, interactive=True)
|
|
|
|
| 102 |
update_btn = gr.Button("Apply Class Edits")
|
| 103 |
|
| 104 |
load_btn.click(fn=load_datasets,
|
| 105 |
+
inputs=[api_input, file_inputs],
|
| 106 |
outputs=[total_out, df, plot_out, json_out])
|
| 107 |
|
| 108 |
update_btn.click(fn=update_classes,
|