import os import gradio as gr from crewai import Agent, Task, Crew from langchain_google_genai import ChatGoogleGenerativeAI from dotenv import load_dotenv # Load environment variables load_dotenv() # Initialize Gemini model gemini_llm = ChatGoogleGenerativeAI( model="gemini-pro", temperature=0.3, google_api_key=os.getenv("GOOGLE_API_KEY") ) def summarize_text(content): """Generate summary using CrewAI agents""" # Define summarizer agent (VERBOSE SET TO BOOLEAN) summarizer = Agent( role='Expert Summarizer', goal='Create concise, accurate summaries of text content', backstory="""A highly skilled AI assistant specialized in text condensation and information extraction. Known for preserving key insights while eliminating unnecessary details.""", llm=gemini_llm, verbose=True # CHANGED TO BOOLEAN ) # Create summarization task summarize_task = Task( description=f"Summarize this text while preserving key information:\n\n{content}", agent=summarizer, expected_output="A concise paragraph summary (3-5 sentences) capturing main points" ) # Form and execute the crew (VERBOSE SET TO BOOLEAN) text_crew = Crew( agents=[summarizer], tasks=[summarize_task], verbose=True # CHANGED TO BOOLEAN ) return text_crew.kickoff() # Gradio interface with gr.Blocks(theme=gr.themes.Soft()) as demo: gr.Markdown("# ✨ Text Summarizer") gr.Markdown("Paste any text below to generate a concise summary") with gr.Row(): text_input = gr.Textbox( label="Input Text", lines=8, placeholder="Paste your content here..." ) with gr.Row(): summary_output = gr.Textbox( label="Summary", lines=5, interactive=False ) submit_btn = gr.Button("Generate Summary", variant="primary") # Connect components submit_btn.click( fn=summarize_text, inputs=text_input, outputs=summary_output ) # Add clear button clear_btn = gr.Button("Clear") clear_btn.click( fn=lambda: ["", ""], inputs=[], outputs=[text_input, summary_output] ) if __name__ == "__main__": demo.launch()