menikev commited on
Commit
1f6bf12
·
verified ·
1 Parent(s): fada27b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +77 -127
app.py CHANGED
@@ -1,128 +1,78 @@
1
  import streamlit as st
2
- import smtplib
3
- from email.mime.text import MIMEText
4
- from email.mime.multipart import MIMEMultipart
5
- from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
6
- from langchain_huggingface import HuggingFacePipeline
7
- from langchain.agents import create_react_agent, AgentExecutor, Tool
8
- from langchain.prompts import PromptTemplate
9
- from langchain.memory import ConversationBufferMemory
10
- from langchain.schema import AgentAction, AgentFinish
11
- import concurrent.futures
12
- import time
13
-
14
- # Email configuration
15
- SENDER_EMAIL = "clen.emenike@gmail.com"
16
- SENDER_PASSWORD = "Achuta@86"
17
- SMTP_SERVER = "smtp.gmail.com"
18
- SMTP_PORT = 587
19
-
20
- @st.cache_resource
21
- def load_model():
22
- model_name = "google/flan-t5-small"
23
- tokenizer = AutoTokenizer.from_pretrained(model_name)
24
- model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
25
- pipe = pipeline("text2text-generation", model=model, tokenizer=tokenizer, max_length=512)
26
- return HuggingFacePipeline(pipeline=pipe)
27
-
28
- local_llm = load_model()
29
-
30
- def send_email(to_email, subject, body):
31
- try:
32
- message = MIMEMultipart()
33
- message["From"] = SENDER_EMAIL
34
- message["To"] = to_email
35
- message["Subject"] = subject
36
- message.attach(MIMEText(body, "plain"))
37
- with smtplib.SMTP(SMTP_SERVER, SMTP_PORT) as server:
38
- server.starttls()
39
- server.login(SENDER_EMAIL, SENDER_PASSWORD)
40
- server.send_message(message)
41
- return "Email sent successfully"
42
- except Exception as e:
43
- return f"Failed to send email: {str(e)}"
44
-
45
- # Define tools before creating the agent
46
- tools = [Tool(name="Send Email", func=send_email, description="Sends an email. Args: to_email, subject, body")]
47
-
48
- # Define the prompt before creating the agent
49
- prompt = PromptTemplate.from_template(
50
- """You are a helpful assistant scheduling cybersecurity program meetings.
51
- Collect the user's name, email, and preferred meeting date, then send a meeting invitation.
52
- Begin by asking for the user's name if you don't have it.
53
- Zoom link: https://us04web.zoom.us/j/73793374638?pwd=S0TEJ30da7dhQ8viOdafMzPfCVzoLJ.1
54
- Meeting ID: 737 9337 4638
55
-
56
- {chat_history}
57
- Human: {input}
58
- Assistant: Let's approach this step-by-step:
59
- {agent_scratchpad}
60
-
61
- Tools available:
62
- {tools}
63
-
64
- Tool names:
65
- {tool_names}
66
- """
67
- )
68
-
69
- # Create the agent after loading the model and defining tools and prompt
70
- agent = create_react_agent(local_llm, tools, prompt)
71
-
72
- # Create the AgentExecutor
73
- agent_executor = AgentExecutor.from_agent_and_tools(
74
- agent=agent,
75
- tools=tools,
76
- verbose=True,
77
- memory=ConversationBufferMemory(memory_key="chat_history", return_messages=True),
78
- handle_parsing_errors=True,
79
- max_iterations=6, # Limit the number of iterations
80
- early_stopping_method="force" # or "generate_until_stop"
81
- )
82
-
83
- def run_agent_with_timeout(executor, input_data, timeout):
84
- with concurrent.futures.ThreadPoolExecutor() as pool:
85
- future = pool.submit(executor, input_data)
86
- try:
87
- return future.result(timeout=timeout)
88
- except concurrent.futures.TimeoutError:
89
- raise TimeoutError("The operation timed out.")
90
-
91
- st.title("CyberSecurity Program Meeting Scheduler")
92
- st.write("Chat with the AI to schedule your meeting. The AI will ask for your name, email, and preferred meeting date.")
93
-
94
- if "messages" not in st.session_state:
95
- st.session_state.messages = []
96
-
97
- for message in st.session_state.messages:
98
- with st.chat_message(message["role"]):
99
- st.markdown(message["content"])
100
-
101
- if prompt := st.chat_input("Your message"):
102
- st.session_state.messages.append({"role": "user", "content": prompt})
103
- with st.chat_message("user"):
104
- st.markdown(prompt)
105
-
106
- with st.chat_message("assistant"):
107
- with st.spinner("Thinking..."):
108
- try:
109
- start_time = time.time()
110
- response = run_agent_with_timeout(agent_executor, {"input": prompt}, timeout=15)
111
- if isinstance(response, dict) and "output" in response:
112
- assistant_response = response["output"]
113
- elif isinstance(response, (AgentAction, AgentFinish)):
114
- assistant_response = response.return_values.get("output", str(response))
115
- else:
116
- assistant_response = str(response)
117
-
118
- st.markdown(assistant_response)
119
- st.session_state.messages.append({"role": "assistant", "content": assistant_response})
120
- except TimeoutError:
121
- st.error("I apologize, but I'm having trouble processing your request at the moment. Could you please try asking your question again, or rephrase it?")
122
- except Exception as e:
123
- st.error(f"An error occurred: {str(e)}")
124
-
125
- st.sidebar.title("About")
126
- st.sidebar.info("This is an interactive CyberSecurity Program Meeting Scheduler. Chat with the AI to schedule your meeting. It will collect your information and send a meeting invitation via email.")
127
-
128
- # To run this script, use: streamlit run your_script_name.py
 
1
  import streamlit as st
2
+ from streamlit_elements import elements, mui, html, dashboard, sync
3
+
4
+ # Function to render skills with progress bars
5
+ def render_skill(skill_name, proficiency):
6
+ st.write(skill_name)
7
+ st.progress(proficiency / 100) # Streamlit progress bar expects a value between 0 and 1
8
+
9
+ # Main function to render the dashboard
10
+ def app():
11
+ st.set_page_config(page_title="Recruitment Dashboard", layout="wide")
12
+
13
+ # Personal Details Section
14
+ st.title("John Doe")
15
+ col1, col2 = st.columns([1, 3])
16
+
17
+ with col1:
18
+ st.image("https://via.placeholder.com/100", width=100)
19
+
20
+ with col2:
21
+ st.markdown("**Contact Information:**")
22
+ st.markdown("📧 johndoe@example.com")
23
+ st.markdown("📞 (123) 456-7890")
24
+ st.markdown("🔗 [linkedin.com/in/johndoe](https://linkedin.com/in/johndoe)")
25
+
26
+ st.markdown("---") # Horizontal line
27
+
28
+ # Skills Section
29
+ st.header("Skills")
30
+ col1, col2 = st.columns(2)
31
+
32
+ with col1:
33
+ st.subheader("Hard Skills")
34
+ render_skill("Penetration Testing", 90)
35
+ render_skill("Network Security", 85)
36
+ render_skill("Incident Response", 80)
37
+ render_skill("Malware Analysis", 75)
38
+
39
+ with col2:
40
+ st.subheader("Soft Skills")
41
+ render_skill("Critical Thinking", 90)
42
+ render_skill("Problem-Solving", 85)
43
+ render_skill("Communication", 80)
44
+ render_skill("Team Collaboration", 75)
45
+
46
+ st.markdown("---") # Horizontal line
47
+
48
+ # Projects Section
49
+ st.header("Projects Delivered")
50
+ st.subheader("Simulated Network Intrusion and Defense")
51
+ st.write("Designed and executed a penetration testing strategy...")
52
+ st.markdown("**Tools Used:** Metasploit, Wireshark, Nmap")
53
+
54
+ st.markdown("---") # Horizontal line
55
+
56
+ # Tools Proficiency Section
57
+ st.header("Tools Proficiency")
58
+ st.write("SIEM (Splunk, QRadar): Advanced")
59
+ st.write("Penetration Testing (Metasploit, Kali Linux): Advanced")
60
+ st.write("Network Analysis (Wireshark): Advanced")
61
+ st.write("Malware Analysis (Cuckoo Sandbox): Intermediate")
62
+ st.write("Cloud Security (AWS Security Hub): Intermediate")
63
+
64
+ st.markdown("---") # Horizontal line
65
+
66
+ # Final Recommendation Section
67
+ st.header("Final Recommendation")
68
+ st.write("**Fit for Role:** Excellent")
69
+ st.write("**Recommended Action:** Highly recommended for interview.")
70
+ st.write("**Potential Areas for Development:** Further training in cloud security...")
71
+
72
+ # Action Button
73
+ if st.button("Schedule Interview"):
74
+ st.success("Interview scheduled!")
75
+
76
+ # Run the app
77
+ if __name__ == "__main__":
78
+ app()