Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import matplotlib.pyplot as plt
|
| 3 |
+
import time
|
| 4 |
+
|
| 5 |
+
# Global Storage
|
| 6 |
+
task_tree = {}
|
| 7 |
+
comments = []
|
| 8 |
+
|
| 9 |
+
# Function to Add Task Update
|
| 10 |
+
def add_task(employee, task, status, actual_time, predicted_time):
|
| 11 |
+
global task_tree
|
| 12 |
+
task_id = f"{employee}_{int(time.time())}" # Unique Task ID
|
| 13 |
+
task_tree[task_id] = {
|
| 14 |
+
"Employee": employee,
|
| 15 |
+
"Task": task,
|
| 16 |
+
"Status": status,
|
| 17 |
+
"Actual Time": actual_time,
|
| 18 |
+
"Predicted Time": predicted_time
|
| 19 |
+
}
|
| 20 |
+
return f"Task '{task}' added by {employee} with status: {status}"
|
| 21 |
+
|
| 22 |
+
# Function to Plot Task Timeline
|
| 23 |
+
def plot_task_timeline():
|
| 24 |
+
if not task_tree:
|
| 25 |
+
return "No tasks available!"
|
| 26 |
+
|
| 27 |
+
tasks = list(task_tree.keys())
|
| 28 |
+
actual_times = [task_tree[t]["Actual Time"] for t in tasks]
|
| 29 |
+
predicted_times = [task_tree[t]["Predicted Time"] for t in tasks]
|
| 30 |
+
|
| 31 |
+
fig, ax = plt.subplots(figsize=(8, 5))
|
| 32 |
+
ax.plot(tasks, actual_times, marker="o", linestyle="-", label="Actual Time", color="b")
|
| 33 |
+
ax.plot(tasks, predicted_times, marker="s", linestyle="--", label="Predicted Time", color="r")
|
| 34 |
+
|
| 35 |
+
ax.set_xlabel("Tasks")
|
| 36 |
+
ax.set_ylabel("Time (Hours)")
|
| 37 |
+
ax.set_title("Actual vs Predicted Task Timeline")
|
| 38 |
+
ax.legend()
|
| 39 |
+
ax.grid(True)
|
| 40 |
+
plt.xticks(rotation=45, ha="right")
|
| 41 |
+
|
| 42 |
+
return fig # Returning figure object for Gradio Plot
|
| 43 |
+
|
| 44 |
+
# Function to Add Comments
|
| 45 |
+
def add_comment(user, comment):
|
| 46 |
+
global comments
|
| 47 |
+
comments.append(f"{user}: {comment}")
|
| 48 |
+
return "Comment Added!"
|
| 49 |
+
|
| 50 |
+
# Function to View Comments
|
| 51 |
+
def view_comments():
|
| 52 |
+
return "\n".join(comments) if comments else "No comments yet!"
|
| 53 |
+
|
| 54 |
+
# Gradio UI
|
| 55 |
+
with gr.Blocks() as live_action_tracker:
|
| 56 |
+
gr.Markdown("## ๐ Live-Action-Tracker Dashboard")
|
| 57 |
+
|
| 58 |
+
with gr.Row():
|
| 59 |
+
with gr.Column():
|
| 60 |
+
gr.Markdown("### ๐น Add Task Update")
|
| 61 |
+
employee = gr.Textbox(label="Employee Name")
|
| 62 |
+
task = gr.Textbox(label="Task Description")
|
| 63 |
+
status = gr.Radio(["Pending", "In Progress", "Completed"], label="Task Status")
|
| 64 |
+
actual_time = gr.Number(label="Actual Time (Hours)")
|
| 65 |
+
predicted_time = gr.Number(label="Predicted Time (Hours)")
|
| 66 |
+
add_task_btn = gr.Button("Submit Task")
|
| 67 |
+
task_output = gr.Textbox(label="Task Submission Status", interactive=False)
|
| 68 |
+
|
| 69 |
+
with gr.Column():
|
| 70 |
+
gr.Markdown("### ๐น Live Comment Board")
|
| 71 |
+
user = gr.Textbox(label="Your Name")
|
| 72 |
+
comment = gr.Textbox(label="Write Comment")
|
| 73 |
+
add_comment_btn = gr.Button("Add Comment")
|
| 74 |
+
comment_output = gr.Textbox(label="Live Comments", interactive=False)
|
| 75 |
+
|
| 76 |
+
with gr.Row():
|
| 77 |
+
task_view_btn = gr.Button("๐ View Task Timeline")
|
| 78 |
+
task_view_output = gr.Plot(label="Task Timeline Graph") # Changed from gr.Image to gr.Plot
|
| 79 |
+
|
| 80 |
+
comment_view_btn = gr.Button("๐ฌ View All Comments")
|
| 81 |
+
comment_view_output = gr.Textbox(label="Community Board", interactive=False)
|
| 82 |
+
|
| 83 |
+
# Button Actions
|
| 84 |
+
add_task_btn.click(add_task, inputs=[employee, task, status, actual_time, predicted_time], outputs=task_output)
|
| 85 |
+
task_view_btn.click(plot_task_timeline, outputs=task_view_output)
|
| 86 |
+
add_comment_btn.click(add_comment, inputs=[user, comment], outputs=comment_output)
|
| 87 |
+
comment_view_btn.click(view_comments, outputs=comment_view_output)
|
| 88 |
+
|
| 89 |
+
# Run the Gradio App
|
| 90 |
+
live_action_tracker.launch()
|