File size: 1,161 Bytes
cacd2bb
 
e95cc19
 
68e22b1
e95cc19
 
 
c849f65
e95cc19
cacd2bb
68e22b1
e785361
68e22b1
e785361
 
 
 
 
cacd2bb
e785361
 
68e22b1
e785361
 
 
 
 
 
 
 
b421cb9
e785361
 
 
 
 
 
 
b421cb9
e785361
 
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
import streamlit as st
from PIL import Image
import requests
from transformers import pipeline

# Load the pipeline
model_name = "vm24bho/net_dfm_myimg"
pipe = pipeline('image-classification', model=model_name)

st.title("Deepfake vs Real Image Detection")

uploaded_file = st.file_uploader("Choose an image...", type="jpg")

if uploaded_file is not None:
   image = Image.open(uploaded_file)
   st.image(image, caption='Uploaded Image.', use_column_width=True)

   st.write("")
   st.write("Classifying...")

   # Apply the model
   result = pipe(image)

   # Display the result
   st.write("**Classification Result:**")
   st.write("---------------")
   for i, res in enumerate(result):
       label = res["label"]
       score = res["score"] * 100  # Convert to percentage
       st.write(f"**{i+1}. {label}**: {score:.2f}%")
   st.write("---------------")

   # Determine the majority score
   real_score = result[0]["score"] * 100
   fake_score = result[1]["score"] * 100
   if real_score > fake_score:
       majority_label = "Real"
   else:
       majority_label = "Fake"

   # Display the final result
   st.write(f"**Given image is {majority_label}**")