Spaces:
Sleeping
Sleeping
noumanjavaid
commited on
Commit
•
a7ad512
1
Parent(s):
3708db4
Update app.py
Browse files
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 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
with col1:
|
627 |
st.subheader("Original Image")
|
628 |
st.image(image, use_container_width=True)
|
629 |
|
630 |
# Process image
|
631 |
-
|
632 |
result = process_image(image_bytes)
|
633 |
|
634 |
-
|
635 |
data = result['data'][0]
|
636 |
-
|
637 |
-
|
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 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
else:
|
678 |
-
st.warning("No faces detected in the image")
|
679 |
else:
|
680 |
-
st.
|
|
|
|
|
681 |
|
682 |
def calculate_similarity(text1, text2):
|
683 |
-
|
684 |
-
|
685 |
|
686 |
if __name__ == "__main__":
|
687 |
-
|
|
|
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()
|