import os import firebase_admin from firebase_admin import credentials, db from transformers import pipeline import gradio as gr # ---------------------------------- # Initialize Firebase # ---------------------------------- # Replace with your Firebase credentials firebase_cred_path = "path/to/your-serviceAccountKey.json" # Upload to your Hugging Face space firebase_db_url = "https://your-database-name.firebaseio.com/" # Replace with your Realtime Database URL cred = credentials.Certificate(firebase_cred_path) firebase_admin.initialize_app(cred, {"databaseURL": firebase_db_url}) # ---------------------------------- # Initialize Hugging Face RAG Model # ---------------------------------- rag_model = pipeline("question-answering", model="facebook/rag-token-base") # ---------------------------------- # Functions for Firebase Operations # ---------------------------------- def fetch_tasks(): """Fetch tasks from Firebase Realtime Database.""" ref = db.reference("projects") data = ref.get() if not data: return "No tasks found!" output = "" for project_id, project_data in data.items(): output += f"Project: {project_id}\n" for task_id, task_data in project_data.get("tasks", {}).items(): output += f"- Task: {task_data['title']} (Status: {task_data['status']})\n" return output def add_task(project_id, task_name, description, assignee, deadline): """Add a new task to Firebase.""" ref = db.reference(f"projects/{project_id}/tasks") new_task_ref = ref.push() # Create a new task new_task_ref.set( { "title": task_name, "description": description, "status": "in-progress", "assignee": assignee, "deadline": deadline, } ) return f"Task '{task_name}' added to project '{project_id}' successfully!" def query_rag(question): """Query RAG model with project data as context.""" ref = db.reference("projects") data = ref.get() if not data: return "No data available for RAG." # Prepare context from Firebase data context = "" for project_id, project_data in data.items(): for task_id, task_data in project_data.get("tasks", {}).items(): context += f"{task_data['title']}: {task_data['status']} (Assigned to: {task_data['assignee']}).\n" # Query RAG model response = rag_model(question=question, context=context) return response["answer"] # ---------------------------------- # Gradio Dashboard # ---------------------------------- def dashboard(): """Gradio interface for Project Management Dashboard.""" with gr.Blocks() as app: gr.Markdown("## Project Management Dashboard with Live Updates") # Add Task Section with gr.Tab("Add Task"): project_id = gr.Textbox(label="Project ID") task_name = gr.Textbox(label="Task Name") description = gr.Textbox(label="Description") assignee = gr.Textbox(label="Assignee") deadline = gr.Textbox(label="Deadline (YYYY-MM-DD)") add_task_button = gr.Button("Add Task") add_task_output = gr.Textbox(label="Output", interactive=False) add_task_button.click( add_task, [project_id, task_name, description, assignee, deadline], add_task_output, ) # Fetch Tasks Section with gr.Tab("View Tasks"): fetch_button = gr.Button("Fetch Tasks") tasks_output = gr.Textbox(label="Tasks", interactive=False) fetch_button.click(fetch_tasks, [], tasks_output) # Query RAG Section with gr.Tab("Ask Questions"): question = gr.Textbox(label="Ask a question about your projects") query_button = gr.Button("Get Answer") rag_output = gr.Textbox(label="Answer", interactive=False) query_button.click(query_rag, [question], rag_output) app.launch() # Launch the app if __name__ == "__main__": dashboard()