ProjectInsta / app.py
SivaMallikarjun's picture
Create app.py
3d547db verified
import gradio as gr
import matplotlib.pyplot as plt
import time
# Global Storage
task_tree = {}
comments = []
# Function to Add Task Update
def add_task(employee, task, status, actual_time, predicted_time):
global task_tree
task_id = f"{employee}_{int(time.time())}" # Unique Task ID
task_tree[task_id] = {
"Employee": employee,
"Task": task,
"Status": status,
"Actual Time": actual_time,
"Predicted Time": predicted_time
}
return f"Task '{task}' added by {employee} with status: {status}"
# Function to Plot Task Timeline
def plot_task_timeline():
if not task_tree:
return "No tasks available!"
tasks = list(task_tree.keys())
actual_times = [task_tree[t]["Actual Time"] for t in tasks]
predicted_times = [task_tree[t]["Predicted Time"] for t in tasks]
fig, ax = plt.subplots(figsize=(8, 5))
ax.plot(tasks, actual_times, marker="o", linestyle="-", label="Actual Time", color="b")
ax.plot(tasks, predicted_times, marker="s", linestyle="--", label="Predicted Time", color="r")
ax.set_xlabel("Tasks")
ax.set_ylabel("Time (Hours)")
ax.set_title("Actual vs Predicted Task Timeline")
ax.legend()
ax.grid(True)
plt.xticks(rotation=45, ha="right")
return fig # Returning figure object for Gradio Plot
# Function to Add Comments
def add_comment(user, comment):
global comments
comments.append(f"{user}: {comment}")
return "Comment Added!"
# Function to View Comments
def view_comments():
return "\n".join(comments) if comments else "No comments yet!"
# Gradio UI
with gr.Blocks() as live_action_tracker:
gr.Markdown("## πŸš€ Live-Action-Tracker Dashboard")
with gr.Row():
with gr.Column():
gr.Markdown("### πŸ”Ή Add Task Update")
employee = gr.Textbox(label="Employee Name")
task = gr.Textbox(label="Task Description")
status = gr.Radio(["Pending", "In Progress", "Completed"], label="Task Status")
actual_time = gr.Number(label="Actual Time (Hours)")
predicted_time = gr.Number(label="Predicted Time (Hours)")
add_task_btn = gr.Button("Submit Task")
task_output = gr.Textbox(label="Task Submission Status", interactive=False)
with gr.Column():
gr.Markdown("### πŸ”Ή Live Comment Board")
user = gr.Textbox(label="Your Name")
comment = gr.Textbox(label="Write Comment")
add_comment_btn = gr.Button("Add Comment")
comment_output = gr.Textbox(label="Live Comments", interactive=False)
with gr.Row():
task_view_btn = gr.Button("πŸ“Š View Task Timeline")
task_view_output = gr.Plot(label="Task Timeline Graph") # Changed from gr.Image to gr.Plot
comment_view_btn = gr.Button("πŸ’¬ View All Comments")
comment_view_output = gr.Textbox(label="Community Board", interactive=False)
# Button Actions
add_task_btn.click(add_task, inputs=[employee, task, status, actual_time, predicted_time], outputs=task_output)
task_view_btn.click(plot_task_timeline, outputs=task_view_output)
add_comment_btn.click(add_comment, inputs=[user, comment], outputs=comment_output)
comment_view_btn.click(view_comments, outputs=comment_view_output)
# Run the Gradio App
live_action_tracker.launch()