EunsuKim commited on
Commit
99b6330
·
verified ·
1 Parent(s): 83cc4f8

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -23
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}")
33
  return f"Task submitted successfully under type '{task_type}'!"
34
  except Exception as e:
35
  return f"Error saving task: {e}"
@@ -45,12 +45,12 @@ 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}")
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
@@ -60,32 +60,26 @@ def add_new_task_type(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 display tasks as clickable links that open in a new tab
 
 
 
 
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;'>"
67
  for idx, task in enumerate(tasks):
68
  color = random.choice(CARD_COLORS)
69
- # Generate a file for each task and serve as a link
70
- task_details_file = f"{task_type}_{idx}.html"
71
- task_path = os.path.join(DATA_DIR, task_details_file)
72
- with open(task_path, "w") as f:
73
- f.write(f"""
74
- <html>
75
- <head><title>{task['description']}</title></head>
76
- <body>
77
- <h3>Task Type: {task['task_type']}</h3>
78
- <p><b>Description:</b> {task['description']}</p>
79
- <pre>{task['yaml']}</pre>
80
- </body>
81
- </html>
82
- """)
83
  html_content += f"""
84
- <a href='{task_details_file}' target='_blank' style='text-decoration: none;'>
85
- <div style='background-color: {color}; padding: 10px; border-radius: 5px;'>
86
- <b>{task['description']}</b>
87
- </div>
88
- </a>
 
 
 
 
89
  """
90
  html_content += "</div>"
91
  return html_content
 
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
  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
 
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;'>"
71
  for idx, task in enumerate(tasks):
72
  color = random.choice(CARD_COLORS)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  html_content += f"""
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>"
85
  return html_content