vm24 adi-123 commited on
Commit
22212e0
1 Parent(s): b421cb9

Update app.py (#2)

Browse files

- Update app.py (e7853613f711e5004aca1179cb5f39aa5b2f8e9a)


Co-authored-by: Aditya Chourasiya <adi-123@users.noreply.huggingface.co>

Files changed (1) hide show
  1. app.py +25 -14
app.py CHANGED
@@ -10,22 +10,33 @@ pipe = pipeline('image-classification', model=model_name)
10
  st.title("Deepfake vs Real Image Detection")
11
 
12
  uploaded_file = st.file_uploader("Choose an image...", type="jpg")
 
13
  if uploaded_file is not None:
14
- image = Image.open(uploaded_file)
15
- st.image(image, caption='Uploaded Image.', use_column_width=True)
16
- st.write("")
17
- st.write("Classifying...")
 
18
 
19
- # Apply the model
20
- result = pipe(image)
21
 
22
- # Display the result
23
- st.write("Classification Result:")
24
- st.write("---------------")
 
 
 
 
 
25
 
26
- for i, res in enumerate(result):
27
- label = res["label"]
28
- score = res["score"]
29
- st.write(f"**{i+1}. {label}**: {score:.2f}%")
 
 
 
30
 
31
- st.write("---------------")
 
 
10
  st.title("Deepfake vs Real Image Detection")
11
 
12
  uploaded_file = st.file_uploader("Choose an image...", type="jpg")
13
+
14
  if uploaded_file is not None:
15
+ image = Image.open(uploaded_file)
16
+ st.image(image, caption='Uploaded Image.', use_column_width=True)
17
+
18
+ st.write("")
19
+ st.write("Classifying...")
20
 
21
+ # Apply the model
22
+ result = pipe(image)
23
 
24
+ # Display the result
25
+ st.write("**Classification Result:**")
26
+ st.write("---------------")
27
+ for i, res in enumerate(result):
28
+ label = res["label"]
29
+ score = res["score"] * 100 # Convert to percentage
30
+ st.write(f"**{i+1}. {label}**: {score:.2f}%")
31
+ st.write("---------------")
32
 
33
+ # Determine the majority score
34
+ real_score = result[0]["score"] * 100
35
+ fake_score = result[1]["score"] * 100
36
+ if real_score > fake_score:
37
+ majority_label = "Real"
38
+ else:
39
+ majority_label = "Fake"
40
 
41
+ # Display the final result
42
+ st.write(f"**Given image is {majority_label}**")