import streamlit as st from crew_initializer import initialize_crew from utils.pdf_generator import generate_pdf import json import logging # Configure logging logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') # Custom JSON Encoder class CustomJSONEncoder(json.JSONEncoder): def default(self, obj): try: # Convert objects with __dict__ attributes to dictionaries if hasattr(obj, "__dict__"): return obj.__dict__ return super().default(obj) except TypeError: return str(obj) # Fallback for unsupported types def main(): """ Main entry point for the Streamlit application. Handles user input, executes tasks, and displays results. """ st.title("Company Researcher Tool") st.sidebar.header("Provide Company Details") company_name = st.sidebar.text_input("Enter the Company Name:", "") if st.sidebar.button("Run Analysis"): st.write(f"### Running analysis for: {company_name}") with st.spinner("Executing tasks, please wait..."): try: crew = initialize_crew() result = crew.kickoff(inputs={"company": company_name}) result_serialized = json.loads(json.dumps(result,cls=CustomJSONEncoder)) st.success("Analysis Complete!") st.json(result_serialized) pdf_buffer = generate_pdf(result_serialized) st.download_button( label="📄 Download Report (PDF)", data=pdf_buffer, file_name=f"{company_name}_report.pdf", mime="application/pdf" ) except Exception as e: logging.error(f"Error during analysis: {str(e)}") st.error(f"An error occurred: {str(e)}") if __name__ == "__main__": main()