File size: 3,947 Bytes
ad956b6
46cbdf9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ad956b6
46cbdf9
 
 
75eb05b
46cbdf9
75eb05b
46cbdf9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75eb05b
 
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
import gradio as gr
import os
import json

# Directory to store submissions
DATA_DIR = "submissions"
os.makedirs(DATA_DIR, exist_ok=True)

# Predefined task types
TASK_TYPES = ["Classification", "Regression", "Translation", "Custom"]

# Function to handle task submission
def submit_task(task_type, description, yaml_text):
    if not yaml_text.strip():
        return "YAML/Text input cannot be empty."

    # Save task data
    data = {
        "task_type": task_type,
        "description": description,
        "yaml": yaml_text
    }
    file_path = os.path.join(DATA_DIR, f"{task_type}_{len(os.listdir(DATA_DIR))}.json")
    with open(file_path, "w") as f:
        json.dump(data, f)

    return f"Task submitted successfully under type '{task_type}'!"

# Function to get tasks by type
def get_tasks_by_type(task_type):
    tasks = []
    for file in os.listdir(DATA_DIR):
        with open(os.path.join(DATA_DIR, file), "r") as f:
            data = json.load(f)
            if data["task_type"] == task_type:
                tasks.append(data)
    return tasks

# Function to switch tabs
def switch_tab(tab_name):
    return gr.Tabs.update(visible_tab=tab_name)

# Gradio App
with gr.Blocks() as app:
    gr.Markdown("# Task Configuration Sharing Space")

    with gr.Tabs() as tabs:
        with gr.Tab("Submit Task"):
            gr.Markdown("## Submit a New Task Configuration")
            
            # Input fields for the task submission
            task_type_input = gr.Dropdown(
                label="Task Type",
                choices=TASK_TYPES,
                value="Classification",
                interactive=True
            )
            description_input = gr.Textbox(
                label="Task Description",
                placeholder="Provide a brief description of the task.",
                lines=3
            )
            yaml_input = gr.Textbox(
                label="YAML/Text Input",
                placeholder="Paste your YAML or text configuration here.",
                lines=10
            )
            submit_button = gr.Button("Submit Task")
            go_to_view_tab = gr.Button("Go to View Tasks")
            submission_status = gr.Textbox(label="Status", interactive=False)

            # Handle task submission
            submit_button.click(
                submit_task,
                inputs=[task_type_input, description_input, yaml_input],
                outputs=[submission_status]
            )

            # Button to switch to "View Tasks" tab
            go_to_view_tab.click(
                switch_tab,
                inputs=None,
                outputs=[tabs],
                fn_kwargs={"tab_name": "View Tasks"}
            )

        with gr.Tab("View Tasks"):
            gr.Markdown("## View Submitted Tasks")

            task_type_filter = gr.Dropdown(
                label="Filter by Task Type",
                choices=TASK_TYPES,
                value="Classification",
                interactive=True
            )
            view_button = gr.Button("View Tasks")
            task_table = gr.Dataframe(headers=["Task Type", "Description", "YAML/Text"], interactive=False)
            go_to_submit_tab = gr.Button("Go to Submit Task")

            # Function to filter tasks by type
            def filter_tasks(task_type):
                tasks = get_tasks_by_type(task_type)
                return [{"Task Type": t["task_type"], "Description": t["description"], "YAML/Text": t["yaml"]} for t in tasks]

            # Handle task filtering
            view_button.click(
                filter_tasks,
                inputs=[task_type_filter],
                outputs=[task_table]
            )

            # Button to switch to "Submit Task" tab
            go_to_submit_tab.click(
                switch_tab,
                inputs=None,
                outputs=[tabs],
                fn_kwargs={"tab_name": "Submit Task"}
            )

app.launch()