jaimin commited on
Commit
d05f8da
1 Parent(s): 14ad1cc

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from src.crew_initializer import initialize_crew
3
+ from src.utils.pdf_generator import generate_pdf
4
+ import json
5
+ import logging
6
+
7
+ # Configure logging
8
+ logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
9
+
10
+ # Custom JSON Encoder
11
+ class CustomJSONEncoder(json.JSONEncoder):
12
+ def default(self, obj):
13
+ try:
14
+ # Convert objects with __dict__ attributes to dictionaries
15
+ if hasattr(obj, "__dict__"):
16
+ return obj.__dict__
17
+ return super().default(obj)
18
+ except TypeError:
19
+ return str(obj) # Fallback for unsupported types
20
+
21
+ def main():
22
+ """
23
+ Main entry point for the Streamlit application.
24
+ Handles user input, executes tasks, and displays results.
25
+ """
26
+ st.title("Company Researcher Tool")
27
+
28
+ st.sidebar.header("Provide Company Details")
29
+ company_name = st.sidebar.text_input("Enter the Company Name:", "")
30
+
31
+ if st.sidebar.button("Run Analysis"):
32
+ st.write(f"### Running analysis for: {company_name}")
33
+
34
+ with st.spinner("Executing tasks, please wait..."):
35
+ try:
36
+ crew = initialize_crew()
37
+ result = crew.kickoff(inputs={"company": company_name})
38
+ result_serialized = json.loads(json.dumps(result,cls=CustomJSONEncoder))
39
+ st.success("Analysis Complete!")
40
+ st.json(result_serialized)
41
+
42
+ pdf_buffer = generate_pdf(result_serialized)
43
+ st.download_button(
44
+ label="📄 Download Report (PDF)",
45
+ data=pdf_buffer,
46
+ file_name=f"{company_name}_report.pdf",
47
+ mime="application/pdf"
48
+ )
49
+ except Exception as e:
50
+ logging.error(f"Error during analysis: {str(e)}")
51
+ st.error(f"An error occurred: {str(e)}")
52
+
53
+ if __name__ == "__main__":
54
+ main()