parass13 commited on
Commit
2849839
·
verified ·
1 Parent(s): 8f65fd7

Delete pages/home.py

Browse files
Files changed (1) hide show
  1. pages/home.py +0 -123
pages/home.py DELETED
@@ -1,123 +0,0 @@
1
- import streamlit as st
2
- import mysql.connector
3
- import re
4
- import tensorflow as tf
5
- from PIL import Image
6
- import numpy as np
7
- import cv2
8
-
9
- # Initialize database connection
10
- try:
11
- mydb = mysql.connector.connect(
12
- host="localhost",
13
- user="root",
14
- password="12345",
15
- database="user_info"
16
- )
17
- mycursor = mydb.cursor()
18
- print("Connection Established")
19
- except mysql.connector.Error as err:
20
- print(f"Error: {err}")
21
- st.error("Database connection failed.")
22
-
23
- # Load the deepfake detection model
24
- deepfake_model_path = "C:\\Users\\Paras Sharma\\OneDrive\\Documents\\Deepfake\\model_15_64 (1).h5"
25
- deepfake_model = tf.keras.models.load_model(deepfake_model_path)
26
-
27
- def validate_name(name):
28
- if re.match(r"^[a-zA-Z]+\s[a-zA-Z]+$", name):
29
- return True
30
- else:
31
- st.warning("Please enter a valid name (e.g., Firstname Lastname).")
32
- return False
33
-
34
- def validate_phone(phone):
35
- if re.match(r"^[0-9]{10}$", phone):
36
- return True
37
- else:
38
- st.warning("Please enter a valid 10-digit phone number.")
39
- return False
40
-
41
- def validate_email(email):
42
- email_pattern = r"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}"
43
- if re.match(email_pattern, email):
44
- return True
45
- else:
46
- st.warning("Please enter a valid email.")
47
- return False
48
-
49
- def preprocess_image(image):
50
- try:
51
- image = np.array(image)
52
- image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) # Convert BGR to RGB
53
- image = cv2.resize(image, (128, 128)) # Resize to match model input size
54
- image = image.astype(np.float32) / 255.0 # Normalize pixel values
55
- return np.expand_dims(image, axis=0) # Add batch dimension
56
- except Exception as e:
57
- print(f"Error preprocessing image: {e}")
58
- return None
59
-
60
- def predict_deepfake(image):
61
- preprocessed_image = preprocess_image(image)
62
- if preprocessed_image is not None:
63
- prediction = deepfake_model.predict(preprocessed_image)
64
- return prediction[0][0] # Assuming the model outputs a single value between 0 and 1
65
- else:
66
- return None
67
-
68
- def show_home():
69
- st.header(' ')
70
- st.markdown("<h1 style='text-align: center; color: black;'>AuthentiTech: Leveraging Machine Learning to Combat Deepfake Detection</h1>", unsafe_allow_html=True)
71
- st.header(' ', divider="rainbow")
72
- st.header(' ')
73
-
74
- st.markdown("<p style='font-size: medium;'>Enter Your Details</p>", unsafe_allow_html=True)
75
-
76
- NAME = st.text_input('Name: ', st.session_state.get('name', ''))
77
- if not validate_name(NAME):
78
- return
79
-
80
- PHONE = st.text_input('Contact Number(+91): ', max_chars=10)
81
- PHONE = PHONE.strip() # Remove any leading/trailing spaces
82
- if not validate_phone(PHONE):
83
- return
84
-
85
- GENDER = st.selectbox('Enter gender', ('F', 'M', 'other'))
86
-
87
- EMAIL = st.text_input('Email: ', st.session_state.get('EMAIL', ''))
88
- if not validate_email(EMAIL):
89
- return
90
-
91
- if st.button("Submit"):
92
- try:
93
- sql = "INSERT INTO user_details (NAME, PHONE, EMAIL, GENDER) VALUES (%s, %s, %s, %s)"
94
- val = (NAME, PHONE, EMAIL, GENDER)
95
- mycursor.execute(sql, val)
96
- mydb.commit()
97
- st.session_state['name'] = NAME
98
- st.session_state['EMAIL'] = EMAIL
99
- st.success("Details submitted successfully!")
100
- except mysql.connector.Error as err:
101
- st.error(f"Error: {err}")
102
- print(f"Error executing SQL: {err}")
103
-
104
- st.write("Upload your image (JPEG, JPG, PNG) here (max size: 15 KB):")
105
- uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"], accept_multiple_files=False, key="file_uploader")
106
-
107
- if uploaded_file is not None:
108
- file_details = {"FileName": uploaded_file.name, "FileType": uploaded_file.type, "FileSize": uploaded_file.size}
109
- st.write(file_details)
110
- image = Image.open(uploaded_file)
111
- st.image(image, caption="Uploaded Image", use_column_width=True)
112
-
113
- if st.button("Detect Now"):
114
- prediction = predict_deepfake(image)
115
- if prediction < 0.5:
116
- st.write("Fake Image")
117
- else:
118
- st.write("Real Image")
119
- else:
120
- st.warning("Please upload an image.")
121
-
122
- if __name__ == "__main__":
123
- show_home()