EunsuKim commited on
Commit
94673da
·
verified ·
1 Parent(s): 99b6330

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -13
app.py CHANGED
@@ -29,7 +29,7 @@ def submit_task(task_type, description, yaml_text):
29
  try:
30
  with open(file_path, "w") as f:
31
  json.dump(data, f)
32
- print(f"Saved file: {file_path}, Contents: {data}") # Debug line
33
  return f"Task submitted successfully under type '{task_type}'!"
34
  except Exception as e:
35
  return f"Error saving task: {e}"
@@ -45,26 +45,22 @@ def get_tasks_by_type(task_type):
45
  try:
46
  with open(os.path.join(DATA_DIR, file), "r") as f:
47
  data = json.load(f)
48
- print(f"File: {file}, Content: {data}") # Debug line
49
  # Filter by task type
50
  if data.get("task_type") == task_type:
51
  tasks.append(data)
52
  except (json.JSONDecodeError, KeyError) as e:
53
- print(f"Error reading file {file}: {e}") # Debug line
54
  return tasks
55
 
56
  # Function to dynamically add a new task type
57
  def add_new_task_type(new_type):
58
  if new_type and new_type not in TASK_TYPES:
59
  TASK_TYPES.append(new_type)
60
- return gr.update(choices=TASK_TYPES), f"Task type '{new_type}' added successfully!"
61
- return gr.update(choices=TASK_TYPES), "Task type already exists or invalid input."
62
 
63
- # Function to switch tabs
64
- def switch_tab(tab_name):
65
- return gr.Tabs.update(visible_tab=tab_name)
66
-
67
- # Function to display tasks as clickable cards with modal popups
68
  def display_tasks(task_type):
69
  tasks = get_tasks_by_type(task_type)
70
  html_content = "<div style='display: flex; flex-wrap: wrap; gap: 10px;'>"
@@ -74,11 +70,12 @@ def display_tasks(task_type):
74
  <div style='background-color: {color}; padding: 10px; border-radius: 5px; cursor: pointer;' onclick="document.getElementById('task-details-{idx}').style.display='block';">
75
  <b>{task['description']}</b>
76
  </div>
77
- <div id='task-details-{idx}' style='display: none; margin-top: 10px;'>
78
  <b>Task Type:</b> {task['task_type']}<br>
79
  <b>Description:</b> {task['description']}<br>
80
  <b>YAML/Text:</b><pre>{task['yaml']}</pre>
81
- <button onclick="document.getElementById('task-details-{idx}').style.display='none';">Close</button>
 
82
  </div>
83
  """
84
  html_content += "</div>"
@@ -125,7 +122,7 @@ with gr.Blocks() as app:
125
  add_task_button.click(
126
  add_new_task_type,
127
  inputs=[new_task_input],
128
- outputs=[task_type_input, add_task_status]
129
  )
130
 
131
  # Handle task submission
 
29
  try:
30
  with open(file_path, "w") as f:
31
  json.dump(data, f)
32
+ print(f"Saved file: {file_path}, Contents: {data}")
33
  return f"Task submitted successfully under type '{task_type}'!"
34
  except Exception as e:
35
  return f"Error saving task: {e}"
 
45
  try:
46
  with open(os.path.join(DATA_DIR, file), "r") as f:
47
  data = json.load(f)
48
+ print(f"File: {file}, Content: {data}")
49
  # Filter by task type
50
  if data.get("task_type") == task_type:
51
  tasks.append(data)
52
  except (json.JSONDecodeError, KeyError) as e:
53
+ print(f"Error reading file {file}: {e}")
54
  return tasks
55
 
56
  # Function to dynamically add a new task type
57
  def add_new_task_type(new_type):
58
  if new_type and new_type not in TASK_TYPES:
59
  TASK_TYPES.append(new_type)
60
+ return gr.update(choices=TASK_TYPES), gr.update(choices=TASK_TYPES), f"Task type '{new_type}' added successfully!"
61
+ return gr.update(choices=TASK_TYPES), gr.update(choices=TASK_TYPES), "Task type already exists or invalid input."
62
 
63
+ # Function to display tasks as clickable cards
 
 
 
 
64
  def display_tasks(task_type):
65
  tasks = get_tasks_by_type(task_type)
66
  html_content = "<div style='display: flex; flex-wrap: wrap; gap: 10px;'>"
 
70
  <div style='background-color: {color}; padding: 10px; border-radius: 5px; cursor: pointer;' onclick="document.getElementById('task-details-{idx}').style.display='block';">
71
  <b>{task['description']}</b>
72
  </div>
73
+ <div id='task-details-{idx}' style='display: none; margin-top: 10px; border: 1px solid #ccc; background: #fff; padding: 10px; border-radius: 5px;'>
74
  <b>Task Type:</b> {task['task_type']}<br>
75
  <b>Description:</b> {task['description']}<br>
76
  <b>YAML/Text:</b><pre>{task['yaml']}</pre>
77
+ <button style='margin-top: 10px;' onclick="document.getElementById('task-details-{idx}').style.display='none';">Close</button>
78
+ <span style='cursor: pointer; float: right; font-size: 18px;' onclick="document.getElementById('task-details-{idx}').style.display='none';">&times;</span>
79
  </div>
80
  """
81
  html_content += "</div>"
 
122
  add_task_button.click(
123
  add_new_task_type,
124
  inputs=[new_task_input],
125
+ outputs=[task_type_input, task_type_filter, add_task_status] # Update both dropdowns
126
  )
127
 
128
  # Handle task submission