import gradio as gr import fitz # PyMuPDF import os from groq import Groq # === Load the uploaded PDF === PDF_PATH = "MANUAL OF SECRETARIAT INSTRUCTIONS (Updated 2023)_1_0.pdf" if not os.path.exists(PDF_PATH): raise FileNotFoundError(f"â File not found: {PDF_PATH}") # === Groq Client === client = Groq(api_key=os.environ["GROQ_API_KEY"]) # === Generate Answer === def generate_answer(question): prompt = f"""You are a helpful assistant. Read the document titled "MANUAL OF SECRETARIAT INSTRUCTIONS" and answer this question: Question: {question} Answer:""" chat_completion = client.chat.completions.create( model="llama3-8b-8192", messages=[{"role": "user", "content": prompt}] ) return chat_completion.choices[0].message.content.strip() # === Suggested Questions === suggested_questions = [ "What are the primary responsibilities of a section officer?", "How is correspondence maintained between different departments?", "What are the procedures for maintaining confidentiality?", "How is a case file processed in the Secretariat?", "What are the duties of a superintendent as per the manual?", "Explain the protocol for submitting summaries to the Minister." ] # === Gradio UI === with gr.Blocks(theme=gr.themes.Soft()) as demo: dark_mode = gr.State(False) # === HEADER === with gr.Row(): gr.Markdown("