EunsuKim commited on
Commit
83cc4f8
·
verified ·
1 Parent(s): 0cd8e4c

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -55
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,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}") # 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,63 +60,32 @@ 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 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 = """
71
- <style>
72
- .modal {{
73
- display: none;
74
- position: fixed;
75
- z-index: 1;
76
- left: 0;
77
- top: 0;
78
- width: 100%;
79
- height: 100%;
80
- overflow: auto;
81
- background-color: rgba(0,0,0,0.4);
82
- }}
83
- .modal-content {{
84
- background-color: #fefefe;
85
- margin: 15% auto;
86
- padding: 20px;
87
- border: 1px solid #888;
88
- width: 80%;
89
- border-radius: 10px;
90
- }}
91
- .close {{
92
- color: #aaa;
93
- float: right;
94
- font-size: 28px;
95
- font-weight: bold;
96
- }}
97
- .close:hover,
98
- .close:focus {{
99
- color: black;
100
- text-decoration: none;
101
- cursor: pointer;
102
- }}
103
- </style>
104
- """
105
- html_content += "<div style='display: flex; flex-wrap: wrap; gap: 10px;'>"
106
  for idx, task in enumerate(tasks):
107
  color = random.choice(CARD_COLORS)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  html_content += f"""
109
- <div style='background-color: {color}; padding: 10px; border-radius: 5px; cursor: pointer;' onclick="document.getElementById('modal-{idx}').style.display='block';">
110
- <b>{task['description']}</b>
111
- </div>
112
- <div id='modal-{idx}' class='modal'>
113
- <div class='modal-content'>
114
- <span class='close' onclick="document.getElementById('modal-{idx}').style.display='none';">&times;</span>
115
- <b>Task Type:</b> {task['task_type']}<br>
116
- <b>Description:</b> {task['description']}<br>
117
- <b>YAML/Text:</b><pre>{task['yaml']}</pre>
118
  </div>
119
- </div>
120
  """
121
  html_content += "</div>"
122
  return html_content
@@ -206,4 +175,4 @@ with gr.Blocks() as app:
206
  outputs=[tabs]
207
  )
208
 
209
- app.launch()
 
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
 
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
 
175
  outputs=[tabs]
176
  )
177
 
178
+ app.launch()