Spaces:
Sleeping
Sleeping
File size: 13,630 Bytes
b9a2f1d |
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
# =============================================================================
# COPYRIGHT NOTICE
# -----------------------------------------------------------------------------
# This source code is the intellectual property of Aditya Pandey.
# Any unauthorized reproduction, distribution, or modification of this code
# is strictly prohibited.
# If you wish to use or modify this code for your project, please ensure
# to give full credit to Aditya Pandey.
#
# PROJECT DESCRIPTION
# -----------------------------------------------------------------------------
# This code is for a chatbot crafted with powerful prompts, designed to
# utilize the Gemini API. It is tailored to assist cybersecurity researchers.
#
# Author: Aditya Pandey
# =============================================================================
import os
import streamlit as st
from PIL import Image
import textwrap
from constants import gemini_key
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain.llms import OpenAI
from langchain import PromptTemplate
import seaborn as sns
from langchain.chains import LLMChain
import google.generativeai as genai
from langchain.memory import ConversationBufferMemory
from google.generativeai.types import HarmCategory, HarmBlockThreshold, HarmProbability
from google.generativeai import GenerativeModel
from langchain.chains import SequentialChain
#API configuration
os.environ["GOOGLE_API_KEY"]=gemini_key
genai.configure(api_key = os.environ['GOOGLE_API_KEY'])
# Define correct username and password
CORRECT_USERNAME = "Oxsecure"
CORRECT_PASSWORD = "Oxsecure@123"
# streamlit framework
st.set_page_config(
page_title="OxSecure",
page_icon="π",
layout="wide"
)
# Load custom CSS
def load_css(file_name):
with open(file_name) as f:
st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True)
# Load the CSS file
load_css("ui/Style.css")
def render_login_page():
st.title("Oxsecure π§ - Your Companion! π")
st.markdown("---")
st.image('ui/Ox.jpg', width=200, use_column_width='always')
st.write("Unlock the realm of cybersecurity expertise with OxSecure π§ π Safeguarding your data. π Let's chat about security topics and empower your knowledge! Product of CyberBULL ποΈ")
st.markdown("---")
st.write("Please log in to continue.")
st.write("π³ Default Credentials Username = Oxsecure , Password = Oxsecure@123 ")
st.divider()
st.markdown("""
**Welcome to OxSecure Intelligence** π your ultimate destination for comprehensive and up-to-date information on cybersecurity. Whether you're a professional, student, or enthusiast, this app is designed to empower you with the knowledge and tools needed to navigate the complex world of cybersecurity.
**Features**
**π In-Depth Information on Cybersecurity Topics:**
Explore a wide range of topics in cybersecurity with detailed articles and guides. This app covers everything from basic concepts to advanced techniques, ensuring you have access to the information you need to stay informed and secure.
**π» Secure Coding Principles:**
Learn the best practices for secure coding to protect your software from vulnerabilities. These guides provide practical tips and examples to help you write code that is both functional and secure.
**π¨ Major Cyberattacks:**
Stay updated on major cyberattacks and learn from real-world cases. Understand the methods used by attackers, the impact of these attacks, and the measures you can take to protect yourself and your organization.
**βοΈ Security Misconfiguration:**
Identify common security misconfigurations and learn how to fix them. These resources help you ensure that your systems are configured correctly to prevent breaches and unauthorized access.
**π VirusTotal File Analysis:**
Upload your files for in-depth malware scanning using the VirusTotal API. Instantly analyze your files and receive reports with threat intelligence on potential malware, ensuring your files are clean and secure.
**π Comprehensive File Analysis:**
Use this app to scan a variety of file types like PDFs, images, executables, and logs. From extracting metadata to analyzing file content, OxSecure Intelligence ensures thorough and real-time security analysis.
**π€ Powered by Gemini LLM:**
This app leverages the powerful Gemini LLM to provide you with accurate and relevant information. Gemini LLM enhances the content with cutting-edge insights and helps you get the answers you need quickly and efficiently.
**πΌοΈ Image Analysis with Imagen:**
Utilize the Imagen feature to extract detailed information from images. Simply upload an image, and our app will analyze it and provide responses tailored to your queries. Perfect for identifying vulnerabilities, assessing security measures, and more.
**Why Choose OxSecure Intelligence?**
- **π Comprehensive Coverage:** From basic concepts to advanced practices, this app covers all aspects of cybersecurity.
- **π Expert Guidance:** Learn from detailed articles and guides written by cybersecurity experts.
- **β‘ Advanced Tools:** Use powerful AI tools like Gemini LLM, Imagen, and VirusTotal to enhance your learning and problem-solving capabilities.
- **π Stay Updated:** Keep up with the latest trends, threats, and best practices in the cybersecurity field.
Join OxSecure Intelligence today and take your cybersecurity knowledge to the next level! π
""")
st.markdown("---")
linkedin_url = "https://www.linkedin.com/in/aditya-pandey-896109224"
st.markdown(" Created with π€π By Aditya Pandey " f"[ LinkedIn π]({linkedin_url})")
username = st.sidebar.text_input("Username π€")
password = st.sidebar.text_input("Password π", type="password")
login_button = st.sidebar.button("Login π«’")
if login_button:
if username == CORRECT_USERNAME and password == CORRECT_PASSWORD:
st.session_state.authenticated = True
st.success("Login successful!")
st.experimental_rerun()
render_main_program()
else:
st.error("Invalid username or password. Please try again.")
## Function to load Gemini vision model and get response
def get_gemini_response(input_prompt, image):
Model = genai.GenerativeModel('gemini-1.5-pro')
if input_prompt != "":
response = Model.generate_content([input_prompt, image])
else:
response = Model.generate_content(image)
return response.text
def render_main_program():
st.markdown("# π Unlock the Future of Cybersecurity with OxSecure ")
st.divider()
st.markdown("**Where Knowledge Meets Innovation! π Dive into Cyber Brilliance with OxSecure** π€ π")
st.markdown("----")
app_choice = st.sidebar.radio("Choose App", ("OxSecure Chat π€", "OxSecure ImaGen π¨"))
if app_choice == "OxSecure Chat π€":
render_gemini_api_app()
elif app_choice == "OxSecure ImaGen π¨":
render_gemini_vision_app()
def render_gemini_api_app():
st.caption("π Empower Tomorrow, π‘οΈ Secure Today: Unleash the Power of Cybersecurity Brilliance! π»β¨ π‘οΈπ¬ ")
st.markdown("---")
st.title("OxSecure Intelligence π§ ")
st.markdown("-----")
input_text = st.text_input("Search your Security Related Topic π")
# Prompt Templates
first_input_prompt = PromptTemplate(
input_variables=['Topic'],
template = textwrap.dedent("""
As an experienced cybersecurity researcher, provide a comprehensive and detailed explanation about {Topic}. Cover the following aspects:
1. Introduction and Importance in well informative
2. Key Concepts and Terminologies
3. Historical Background and Evolution
4. Its Architecture and Types
5. Current Trends and Best Practices
6. Major Threats and Vulnerabilities
7. Case Studies and Real-world Examples
8. Future Outlook and Predictions
Ensure the information is professional, well-structured, key conceptual and suitable for someone with an advanced understanding and Beginner of cybersecurity.
""")
)
# Select the model
model = genai.GenerativeModel('gemini-1.5-pro')
safety_settings = {
HarmCategory.HARM_CATEGORY_HATE_SPEECH: HarmBlockThreshold.BLOCK_NONE,
HarmCategory.HARM_CATEGORY_HARASSMENT: HarmBlockThreshold.BLOCK_NONE,
HarmCategory.HARM_CATEGORY_DANGEROUS: HarmBlockThreshold.BLOCK_NONE,
HarmCategory.HARM_CATEGORY_SEXUAL: HarmBlockThreshold.BLOCK_NONE,
HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_NONE,
HarmCategory.HARM_CATEGORY_HARASSMENT: HarmBlockThreshold.BLOCK_NONE,
HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT: HarmBlockThreshold.BLOCK_NONE,
HarmCategory.HARM_CATEGORY_TOXICITY: HarmBlockThreshold.BLOCK_NONE,
HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmProbability.HIGH
}
# Memory
Topic_memory = ConversationBufferMemory(input_key='Topic', memory_key='chat_history')
Policy_memory = ConversationBufferMemory(input_key='secure coding', memory_key='chat_history')
Practice_memory = ConversationBufferMemory(input_key='Practice', memory_key='description_history')
## GEMINI LLMS
llm = ChatGoogleGenerativeAI(model="gemini-1.5-flash")
chain = LLMChain(
llm=llm, prompt=first_input_prompt, verbose=True, output_key='secure coding', memory=Topic_memory)
safety_settings = {
HarmCategory.HARM_CATEGORY_HATE_SPEECH: HarmBlockThreshold.BLOCK_NONE,
HarmCategory.HARM_CATEGORY_HARASSMENT: HarmBlockThreshold.BLOCK_NONE,
HarmCategory.HARM_CATEGORY_DANGEROUS: HarmBlockThreshold.BLOCK_NONE,
HarmCategory.HARM_CATEGORY_SEXUAL: HarmBlockThreshold.BLOCK_NONE,
HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_NONE,
HarmCategory.HARM_CATEGORY_HARASSMENT: HarmBlockThreshold.BLOCK_NONE,
HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT: HarmBlockThreshold.BLOCK_NONE,
HarmCategory.HARM_CATEGORY_TOXICITY: HarmBlockThreshold.BLOCK_NONE,
HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmProbability.HIGH
}
# Prompt Templates
second_input_prompt = PromptTemplate(
input_variables=['secure coding'],
template="write best {secure coding} and perfect code snippet for implementing secure coding to this {Topic} in well detailed and descriptive way use code snippets for each point and describe code."
)
chain2 = LLMChain(
llm=llm, prompt=second_input_prompt, verbose=True, output_key='Practice', memory=Policy_memory)
# Prompt Templates
third_input_prompt = PromptTemplate(
input_variables=['Practice'],
template="Implement major best Cybersecurity {Practice} for this {Topic} that helps better security postures into any business. illustrate Major cyberattack which is done by misconfiguration of {Topic} and give the informative info about the malware which caused this"
)
chain3 = LLMChain(llm=llm, prompt=third_input_prompt, verbose=True, output_key='description', memory=Practice_memory)
parent_chain = SequentialChain(
chains=[chain, chain2, chain3], input_variables=['Topic'], output_variables=['secure coding', 'Practice',
'description'], verbose=True)
if input_text:
with st.spinner('Processing.... β³'):
st.text(parent_chain({'Topic': input_text}))
with st.expander('Your Topic'):
st.info(Topic_memory.buffer)
with st.expander('Major Practices'):
st.info(Practice_memory.buffer)
st.markdown("---")
linkedin_url = "https://www.linkedin.com/in/aditya-pandey-896109224"
st.markdown(" Created with π€π By Aditya Pandey " f"[ LinkedIn π]({linkedin_url})")
def render_gemini_vision_app():
st.title('OxSecure ImaGen π¨')
st.markdown("----")
input_prompt = st.text_input("Input Prompt: ", key="input")
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
image = ""
submit = False # Initialize submit variable
if uploaded_file is not None:
image = Image.open(uploaded_file)
st.image(image, caption="Uploaded Image.", use_column_width=True)
submit = st.button("Tell me about the image")
if submit:
response = get_gemini_response(input_prompt, image)
st.subheader("The Response is")
st.write(response)
st.markdown("---")
linkedin_url = "https://www.linkedin.com/in/aditya-pandey-896109224"
st.markdown(" Created with π€π By Aditya Pandey " f"[ LinkedIn π]({linkedin_url})")
def main():
# Initialize session state
if 'authenticated' not in st.session_state:
st.session_state.authenticated = False
# If not authenticated, display login portal
if not st.session_state.authenticated:
render_login_page()
else:
render_main_program()
if __name__ == "__main__":
main()
|