Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -18,6 +18,9 @@ def process_metadata(file):
|
|
18 |
# Create category mapping dynamically
|
19 |
category_mapping = {cat: idx for idx, cat in enumerate(sorted(unique_categories))}
|
20 |
|
|
|
|
|
|
|
21 |
results = []
|
22 |
# Process each media item
|
23 |
for item in data["media_items"]:
|
@@ -43,8 +46,8 @@ def process_metadata(file):
|
|
43 |
}
|
44 |
results.append(json.dumps(output))
|
45 |
|
46 |
-
# Return
|
47 |
-
return "\n".join(results)
|
48 |
|
49 |
|
50 |
def save_text(text):
|
@@ -66,14 +69,17 @@ with gr.Blocks(title="VL-HF Annotations Converter") as iface:
|
|
66 |
input_file = gr.File(label="Upload JSON file exported from Visual Layer")
|
67 |
|
68 |
with gr.Row():
|
69 |
-
output_text = gr.Textbox(label="Converted JSONL output", lines=10)
|
|
|
|
|
|
|
70 |
download_btn = gr.DownloadButton(
|
71 |
label="Download JSONL", value="metadata.jsonl", interactive=True
|
72 |
)
|
73 |
|
74 |
# Connect the components
|
75 |
output = input_file.change(
|
76 |
-
fn=process_metadata, inputs=[input_file], outputs=[output_text]
|
77 |
).then( # Chain the save operation immediately after processing
|
78 |
fn=save_text, inputs=[output_text], outputs=[download_btn]
|
79 |
)
|
|
|
18 |
# Create category mapping dynamically
|
19 |
category_mapping = {cat: idx for idx, cat in enumerate(sorted(unique_categories))}
|
20 |
|
21 |
+
# Create a formatted string of the mapping
|
22 |
+
mapping_str = "\n".join([f"{cat}: {idx}" for cat, idx in category_mapping.items()])
|
23 |
+
|
24 |
results = []
|
25 |
# Process each media item
|
26 |
for item in data["media_items"]:
|
|
|
46 |
}
|
47 |
results.append(json.dumps(output))
|
48 |
|
49 |
+
# Return both results and mapping
|
50 |
+
return "\n".join(results), mapping_str
|
51 |
|
52 |
|
53 |
def save_text(text):
|
|
|
69 |
input_file = gr.File(label="Upload JSON file exported from Visual Layer")
|
70 |
|
71 |
with gr.Row():
|
72 |
+
output_text = gr.Textbox(label="Converted JSONL output", lines=10, scale=3)
|
73 |
+
mapping_text = gr.Textbox(label="Category Mapping", lines=10)
|
74 |
+
|
75 |
+
with gr.Row():
|
76 |
download_btn = gr.DownloadButton(
|
77 |
label="Download JSONL", value="metadata.jsonl", interactive=True
|
78 |
)
|
79 |
|
80 |
# Connect the components
|
81 |
output = input_file.change(
|
82 |
+
fn=process_metadata, inputs=[input_file], outputs=[output_text, mapping_text]
|
83 |
).then( # Chain the save operation immediately after processing
|
84 |
fn=save_text, inputs=[output_text], outputs=[download_btn]
|
85 |
)
|