Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -7,41 +7,54 @@ DATA_DIR = "submissions"
|
|
| 7 |
os.makedirs(DATA_DIR, exist_ok=True)
|
| 8 |
|
| 9 |
# Predefined task types
|
| 10 |
-
TASK_TYPES = ["
|
| 11 |
|
| 12 |
# Function to handle task submission
|
| 13 |
def submit_task(task_type, description, yaml_text):
|
| 14 |
if not yaml_text.strip():
|
| 15 |
return "YAML/Text input cannot be empty."
|
| 16 |
|
| 17 |
-
#
|
| 18 |
data = {
|
| 19 |
"task_type": task_type,
|
| 20 |
"description": description,
|
| 21 |
"yaml": yaml_text
|
| 22 |
}
|
| 23 |
file_path = os.path.join(DATA_DIR, f"{task_type}_{len(os.listdir(DATA_DIR))}.json")
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
# Function to get tasks by type
|
| 30 |
def get_tasks_by_type(task_type):
|
| 31 |
tasks = []
|
| 32 |
for file in os.listdir(DATA_DIR):
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
return tasks
|
| 38 |
|
| 39 |
# Function to dynamically add a new task type
|
| 40 |
def add_new_task_type(new_type):
|
| 41 |
if new_type and new_type not in TASK_TYPES:
|
| 42 |
TASK_TYPES.append(new_type)
|
| 43 |
-
|
| 44 |
-
|
|
|
|
| 45 |
|
| 46 |
# Function to switch tabs
|
| 47 |
def switch_tab(tab_name):
|
|
@@ -59,7 +72,7 @@ with gr.Blocks() as app:
|
|
| 59 |
task_type_input = gr.Dropdown(
|
| 60 |
label="Task Type",
|
| 61 |
choices=TASK_TYPES,
|
| 62 |
-
value="
|
| 63 |
interactive=True
|
| 64 |
)
|
| 65 |
new_task_input = gr.Textbox(
|
|
@@ -111,7 +124,7 @@ with gr.Blocks() as app:
|
|
| 111 |
task_type_filter = gr.Dropdown(
|
| 112 |
label="Filter by Task Type",
|
| 113 |
choices=TASK_TYPES,
|
| 114 |
-
value="
|
| 115 |
interactive=True
|
| 116 |
)
|
| 117 |
view_button = gr.Button("View Tasks")
|
|
@@ -137,4 +150,4 @@ with gr.Blocks() as app:
|
|
| 137 |
outputs=[tabs]
|
| 138 |
)
|
| 139 |
|
| 140 |
-
app.launch()
|
|
|
|
| 7 |
os.makedirs(DATA_DIR, exist_ok=True)
|
| 8 |
|
| 9 |
# Predefined task types
|
| 10 |
+
TASK_TYPES = ["Classification", "Regression", "Translation"]
|
| 11 |
|
| 12 |
# Function to handle task submission
|
| 13 |
def submit_task(task_type, description, yaml_text):
|
| 14 |
if not yaml_text.strip():
|
| 15 |
return "YAML/Text input cannot be empty."
|
| 16 |
|
| 17 |
+
# Prepare data
|
| 18 |
data = {
|
| 19 |
"task_type": task_type,
|
| 20 |
"description": description,
|
| 21 |
"yaml": yaml_text
|
| 22 |
}
|
| 23 |
file_path = os.path.join(DATA_DIR, f"{task_type}_{len(os.listdir(DATA_DIR))}.json")
|
| 24 |
+
|
| 25 |
+
try:
|
| 26 |
+
with open(file_path, "w") as f:
|
| 27 |
+
json.dump(data, f)
|
| 28 |
+
return f"Task submitted successfully under type '{task_type}'!"
|
| 29 |
+
except Exception as e:
|
| 30 |
+
return f"Error saving task: {e}"
|
| 31 |
|
| 32 |
# Function to get tasks by type
|
| 33 |
def get_tasks_by_type(task_type):
|
| 34 |
tasks = []
|
| 35 |
for file in os.listdir(DATA_DIR):
|
| 36 |
+
# Skip non-JSON files
|
| 37 |
+
if not file.endswith(".json"):
|
| 38 |
+
continue
|
| 39 |
+
|
| 40 |
+
try:
|
| 41 |
+
with open(os.path.join(DATA_DIR, file), "r") as f:
|
| 42 |
+
data = json.load(f)
|
| 43 |
+
# Filter by task type
|
| 44 |
+
if data.get("task_type") == task_type:
|
| 45 |
+
tasks.append(data)
|
| 46 |
+
except (json.JSONDecodeError, KeyError):
|
| 47 |
+
# Skip invalid or corrupted files
|
| 48 |
+
print(f"Skipped invalid file: {file}")
|
| 49 |
return tasks
|
| 50 |
|
| 51 |
# Function to dynamically add a new task type
|
| 52 |
def add_new_task_type(new_type):
|
| 53 |
if new_type and new_type not in TASK_TYPES:
|
| 54 |
TASK_TYPES.append(new_type)
|
| 55 |
+
# Return the updated choices
|
| 56 |
+
return TASK_TYPES, f"Task type '{new_type}' added successfully!"
|
| 57 |
+
return TASK_TYPES, "Task type already exists or invalid input."
|
| 58 |
|
| 59 |
# Function to switch tabs
|
| 60 |
def switch_tab(tab_name):
|
|
|
|
| 72 |
task_type_input = gr.Dropdown(
|
| 73 |
label="Task Type",
|
| 74 |
choices=TASK_TYPES,
|
| 75 |
+
value="Classification",
|
| 76 |
interactive=True
|
| 77 |
)
|
| 78 |
new_task_input = gr.Textbox(
|
|
|
|
| 124 |
task_type_filter = gr.Dropdown(
|
| 125 |
label="Filter by Task Type",
|
| 126 |
choices=TASK_TYPES,
|
| 127 |
+
value="Classification",
|
| 128 |
interactive=True
|
| 129 |
)
|
| 130 |
view_button = gr.Button("View Tasks")
|
|
|
|
| 150 |
outputs=[tabs]
|
| 151 |
)
|
| 152 |
|
| 153 |
+
app.launch()
|