File size: 1,927 Bytes
14ad1cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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()