noumanjavaid commited on
Commit
a7ad512
1 Parent(s): 3708db4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -47
app.py CHANGED
@@ -617,25 +617,23 @@ st.markdown("""
617
  """, unsafe_allow_html=True)
618
 
619
  uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
620
- if uploaded_file is not None:
621
- # Display original image
622
- image_bytes = uploaded_file.getvalue()
623
- image = Image.open(io.BytesIO(image_bytes))
624
- col1, col2 = st.columns(2)
625
-
626
- with col1:
627
  st.subheader("Original Image")
628
  st.image(image, use_container_width=True)
629
 
630
  # Process image
631
- with st.spinner("Analyzing image..."):
632
  result = process_image(image_bytes)
633
 
634
- if result and 'data' in result:
635
  data = result['data'][0]
636
-
637
- # Display results
638
- if 'bounding_boxes' in data:
639
  for box in data['bounding_boxes']:
640
  # Draw bounding box on image
641
  annotated_image = draw_bounding_box(
@@ -645,43 +643,43 @@ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png
645
  box['is_deepfake']
646
  )
647
 
648
- with col2:
649
- st.subheader("Analysis Result")
650
- st.image(annotated_image, use_container_width=True)
651
-
652
- # Display confidence metrics
653
- deepfake_conf = box['is_deepfake'] * 100
654
- bbox_conf = box['bbox_confidence'] * 100
655
-
656
- st.write("### Detection Confidence")
657
- col3, col4 = st.columns(2)
658
-
659
- with col3:
660
- st.metric("Deepfake Confidence", f"{deepfake_conf:.1f}%")
661
- st.progress(deepfake_conf/100)
662
-
663
- with col4:
664
- st.metric("Face Detection Confidence", f"{bbox_conf:.1f}%")
665
- st.progress(bbox_conf/100)
666
-
667
- if deepfake_conf > 90:
668
- st.error("⚠️ High probability of deepfake detected!")
669
- elif deepfake_conf > 70:
670
- st.warning("⚠️ Moderate probability of deepfake detected!")
671
- else:
672
- st.success("✅ Low probability of deepfake")
673
-
674
- # Display raw JSON data in expander
675
- with st.expander("View Raw JSON Response"):
676
- st.json(result)
677
- else:
678
- st.warning("No faces detected in the image")
679
  else:
680
- st.error("Failed to process image")
 
 
681
 
682
  def calculate_similarity(text1, text2):
683
- matcher = SequenceMatcher(None, text1, text2)
684
- return matcher.ratio()
685
 
686
  if __name__ == "__main__":
687
- main()
 
617
  """, unsafe_allow_html=True)
618
 
619
  uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
620
+ if uploaded_file is not None:
621
+ image_bytes = uploaded_file.getvalue()
622
+ image = Image.open(io.BytesIO(image_bytes))
623
+ col1, col2 = st.columns(2)
624
+
625
+ with col1:
 
626
  st.subheader("Original Image")
627
  st.image(image, use_container_width=True)
628
 
629
  # Process image
630
+ with st.spinner("Analyzing image..."):
631
  result = process_image(image_bytes)
632
 
633
+ if result and 'data' in result:
634
  data = result['data'][0]
635
+
636
+ if 'bounding_boxes' in data:
 
637
  for box in data['bounding_boxes']:
638
  # Draw bounding box on image
639
  annotated_image = draw_bounding_box(
 
643
  box['is_deepfake']
644
  )
645
 
646
+ with col2:
647
+ st.subheader("Analysis Result")
648
+ st.image(annotated_image, use_container_width=True)
649
+
650
+ # Display confidence metrics
651
+ deepfake_conf = box['is_deepfake'] * 100
652
+ bbox_conf = box['bbox_confidence'] * 100
653
+
654
+ st.write("### Detection Confidence")
655
+ col3, col4 = st.columns(2)
656
+
657
+ with col3:
658
+ st.metric("Deepfake Confidence", f"{deepfake_conf:.1f}%")
659
+ st.progress(deepfake_conf/100)
660
+
661
+ with col4:
662
+ st.metric("Face Detection Confidence", f"{bbox_conf:.1f}%")
663
+ st.progress(bbox_conf/100)
664
+
665
+ if deepfake_conf > 90:
666
+ st.error("⚠️ High probability of deepfake detected!")
667
+ elif deepfake_conf > 70:
668
+ st.warning("⚠️ Moderate probability of deepfake detected!")
669
+ else:
670
+ st.success("✅ Low probability of deepfake")
671
+
672
+ # Display raw JSON data in expander
673
+ with st.expander("View Raw JSON Response"):
674
+ st.json(result)
 
 
675
  else:
676
+ st.warning("No faces detected in the image")
677
+ else:
678
+ st.error("Failed to process image")
679
 
680
  def calculate_similarity(text1, text2):
681
+ matcher = SequenceMatcher(None, text1, text2)
682
+ return matcher.ratio()
683
 
684
  if __name__ == "__main__":
685
+ main()