Spaces:
Sleeping
Sleeping
File size: 1,479 Bytes
5658e0c 6d7e269 5658e0c 6d7e269 5658e0c 237695c 5658e0c | 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 | """Super basic Gradio UI for add_collaborators_to_dataset_from_csv.py.
"""
import gradio as gr
from add_collaborators_to_dataset_from_csv import add_collaborators, format_error_message, read_collaborators
from segments import SegmentsClient
from segments.exceptions import SegmentsError
def run(api_key: str, dataset_identifier: str, csv_file: str) -> str:
if not api_key or not dataset_identifier or not csv_file:
return "Please fill in the API key, dataset identifier, and CSV file."
try:
collaborators, skipped_rows = read_collaborators(csv_file)
except ValueError as error:
return str(error)
for skipped_row in skipped_rows:
print(skipped_row)
if not collaborators:
return "No usernames found in CSV"
try:
client = SegmentsClient(api_key)
except SegmentsError as error:
return format_error_message(error)
logs, _has_failures = add_collaborators(client, dataset_identifier, collaborators)
for log in logs:
print(log)
return "\n".join(skipped_rows + logs)
demo = gr.Interface(
fn=run,
inputs=[
gr.Textbox(label="API key", type="password"),
gr.Textbox(label="Dataset identifier", placeholder="jane/flowers"),
gr.File(label="CSV file", type="filepath"),
],
outputs=gr.Textbox(label="Log", lines=15),
title="Add dataset collaborators from CSV",
flagging_mode="never",
)
if __name__ == "__main__":
demo.launch()
|