Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,146 +1,57 @@
|
|
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 |
-
# <div class="container">
|
59 |
-
# <div class="header">
|
60 |
-
# <h1>Welcome to the VM24BHO Model Interface</h1>
|
61 |
-
# <p>Use this interface to interact with the deep learning model.</p>
|
62 |
-
# </div>
|
63 |
-
# <div class="gradio-container">
|
64 |
-
# <!-- Gradio interface elements will be inserted here -->
|
65 |
-
# </div>
|
66 |
-
# </div>
|
67 |
-
# """,
|
68 |
-
# css=css
|
69 |
-
# )
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
import gradio as gr
|
77 |
-
|
78 |
-
# Load your model (assuming the path is correct)
|
79 |
-
demo = gr.load("models/vm24bho/net_dfm_myimg")
|
80 |
-
|
81 |
-
# Custom CSS styling
|
82 |
-
css = """
|
83 |
-
body {
|
84 |
-
background-color: #f5f5f5;
|
85 |
-
font-family: 'Arial', sans-serif;
|
86 |
-
}
|
87 |
-
.container {
|
88 |
-
max-width: 800px;
|
89 |
-
margin: 0 auto;
|
90 |
-
padding: 20px;
|
91 |
-
background-color: #ffffff;
|
92 |
-
border-radius: 10px;
|
93 |
-
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
94 |
-
}
|
95 |
-
.header {
|
96 |
-
text-align: center;
|
97 |
-
padding-bottom: 20px;
|
98 |
-
}
|
99 |
-
h1 {
|
100 |
-
color: #333333;
|
101 |
-
}
|
102 |
-
p {
|
103 |
-
color: #666666;
|
104 |
-
}
|
105 |
-
.gradio-container {
|
106 |
-
display: flex;
|
107 |
-
flex-direction: column;
|
108 |
-
gap: 20px;
|
109 |
-
}
|
110 |
-
button {
|
111 |
-
background-color: #007bff;
|
112 |
-
color: white;
|
113 |
-
border: none;
|
114 |
-
padding: 10px 20px;
|
115 |
-
border-radius: 5px;
|
116 |
-
cursor: pointer;
|
117 |
-
font-size: 16px;
|
118 |
-
}
|
119 |
-
button:hover {
|
120 |
-
background-color: #0056b3;
|
121 |
-
}
|
122 |
-
"""
|
123 |
-
|
124 |
-
# Creating the Gradio interface
|
125 |
-
with gr.Blocks(css=css) as demo:
|
126 |
-
gr.Markdown(
|
127 |
-
"""
|
128 |
-
<div class="container">
|
129 |
-
<div class="header">
|
130 |
-
<h1>Welcome to the Deepfake detection Model Interface</h1>
|
131 |
-
<p>Use this interface to interact with the deep learning model.</p>
|
132 |
-
</div>
|
133 |
-
<div class="gradio-container">
|
134 |
-
<!-- Gradio interface elements will be inserted here -->
|
135 |
-
</div>
|
136 |
-
</div>
|
137 |
-
"""
|
138 |
-
)
|
139 |
-
|
140 |
-
# Assuming your model has a specific input/output interface
|
141 |
-
# Adjust this part according to your actual model's input/output
|
142 |
-
gr.Interface.load("models/vm24bho/net_dfm_myimg")
|
143 |
-
|
144 |
-
# Launch the Gradio interface
|
145 |
-
demo.launch()
|
146 |
-
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from PIL import Image
|
3 |
+
from transformers import pipeline
|
4 |
+
|
5 |
+
# Set the title and sidebar
|
6 |
+
st.set_page_config(page_title="Deepfake vs Real Image Detection", page_icon="🤖")
|
7 |
+
|
8 |
+
st.title("Deepfake vs Real Image Detection")
|
9 |
+
st.sidebar.title("Options")
|
10 |
+
|
11 |
+
# Description
|
12 |
+
st.markdown(
|
13 |
+
"""
|
14 |
+
Welcome to the Deepfake vs Real Image Detection app!
|
15 |
+
Upload an image and let our model determine if it is real or a deepfake.
|
16 |
+
"""
|
17 |
+
)
|
18 |
+
|
19 |
+
# Load the pipeline
|
20 |
+
model_name = "vm24bho/net_dfm_myimg"
|
21 |
+
pipe = pipeline('image-classification', model=model_name)
|
22 |
+
|
23 |
+
# Upload image
|
24 |
+
st.sidebar.subheader("Upload Image")
|
25 |
+
uploaded_file = st.sidebar.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
26 |
+
|
27 |
+
# Add a sample image option
|
28 |
+
if st.sidebar.button("Use Sample Image"):
|
29 |
+
sample_url = "https://drive.google.com/file/d/1O1mGXitkGcnu-kyISpnRBvhju3swRDP9/view?usp=drive_link" # Replace with a valid sample image URL
|
30 |
+
image = Image.open(requests.get(sample_url, stream=True).raw)
|
31 |
+
else:
|
32 |
+
if uploaded_file is not None:
|
33 |
+
image = Image.open(uploaded_file)
|
34 |
+
|
35 |
+
# Display the uploaded image
|
36 |
+
if uploaded_file or st.sidebar.button("Use Sample Image"):
|
37 |
+
st.image(image, caption='Uploaded Image', use_column_width=True)
|
38 |
+
st.write("")
|
39 |
+
st.write("Classifying...")
|
40 |
+
|
41 |
+
# Apply the model
|
42 |
+
result = pipe(image)
|
43 |
+
|
44 |
+
# Display the result
|
45 |
+
st.subheader("Classification Result")
|
46 |
+
for res in result:
|
47 |
+
st.write(f"**{res['label']}**: {res['score']*100:.2f}%")
|
48 |
+
else:
|
49 |
+
st.sidebar.info("Upload an image to get started.")
|
50 |
+
|
51 |
+
# Footer
|
52 |
+
st.sidebar.markdown(
|
53 |
+
"""
|
54 |
+
---
|
55 |
+
Created with ❤️ by VINAYAK MODI(https://github.com/vinayakmodi)
|
56 |
+
"""
|
57 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|