Spaces:
Sleeping
Sleeping
Update streamlit_app.py
Browse files- streamlit_app.py +53 -54
streamlit_app.py
CHANGED
|
@@ -43,68 +43,68 @@ st.sidebar.markdown("### About\nThis tool uses pretrained models to detect text
|
|
| 43 |
if module == "Text Misinformation":
|
| 44 |
st.title("📰 Misinformation Detection")
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
if
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
})
|
| 79 |
|
| 80 |
# ------------------- Image Deepfake -------------------
|
| 81 |
elif module == "Image Deepfake":
|
| 82 |
st.title("🖼 Deepfake Image Detection")
|
| 83 |
|
| 84 |
-
|
|
|
|
| 85 |
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
|
| 95 |
-
|
| 96 |
-
|
| 97 |
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
|
| 109 |
# ------------------- History -------------------
|
| 110 |
if "history" in st.session_state and st.session_state.history:
|
|
@@ -113,4 +113,3 @@ if "history" in st.session_state and st.session_state.history:
|
|
| 113 |
st.dataframe(df_hist)
|
| 114 |
csv = df_hist.to_csv(index=False).encode("utf-8")
|
| 115 |
st.download_button("Download History (CSV)", data=csv, file_name="analysis_history.csv", mime="text/csv")
|
| 116 |
-
|
|
|
|
| 43 |
if module == "Text Misinformation":
|
| 44 |
st.title("📰 Misinformation Detection")
|
| 45 |
|
| 46 |
+
with st.container():
|
| 47 |
+
user_input = st.text_area("Enter a news statement or claim:", height=150)
|
| 48 |
+
|
| 49 |
+
if st.button("Analyze Text"):
|
| 50 |
+
if not user_input.strip():
|
| 51 |
+
st.warning("Please enter some text to analyze.")
|
| 52 |
+
else:
|
| 53 |
+
model = load_text_model()
|
| 54 |
+
with st.spinner("Running model inference..."):
|
| 55 |
+
result = model(user_input, truncation=True)[0]
|
| 56 |
+
|
| 57 |
+
label = result.get("label", "N/A")
|
| 58 |
+
score = float(result.get("score", 0.0))
|
| 59 |
+
|
| 60 |
+
label_map = {"LABEL_0": "REAL", "LABEL_1": "FAKE", "REAL": "REAL", "FAKE": "FAKE"}
|
| 61 |
+
readable_label = label_map.get(label, label)
|
| 62 |
+
|
| 63 |
+
st.success(f"Prediction: {readable_label}")
|
| 64 |
+
st.metric("Confidence", f"{score*100:.2f}%")
|
| 65 |
+
|
| 66 |
+
with st.expander("🔍 Raw Model Output"):
|
| 67 |
+
st.json(result)
|
| 68 |
+
|
| 69 |
+
st.session_state.setdefault("history", [])
|
| 70 |
+
if len(st.session_state.history) < 20:
|
| 71 |
+
st.session_state.history.append({
|
| 72 |
+
"type": "text",
|
| 73 |
+
"input": user_input,
|
| 74 |
+
"label": readable_label,
|
| 75 |
+
"score": score,
|
| 76 |
+
"time": datetime.utcnow().isoformat()
|
| 77 |
+
})
|
|
|
|
| 78 |
|
| 79 |
# ------------------- Image Deepfake -------------------
|
| 80 |
elif module == "Image Deepfake":
|
| 81 |
st.title("🖼 Deepfake Image Detection")
|
| 82 |
|
| 83 |
+
with st.container():
|
| 84 |
+
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
| 85 |
|
| 86 |
+
if uploaded_file:
|
| 87 |
+
image = Image.open(uploaded_file).convert("RGB")
|
| 88 |
+
st.image(image, caption="Uploaded Image", use_container_width=True)
|
| 89 |
|
| 90 |
+
if st.button("Analyze Image"):
|
| 91 |
+
model = load_image_model()
|
| 92 |
+
with st.spinner("Running image model..."):
|
| 93 |
+
results = model(image, top_k=3)
|
| 94 |
|
| 95 |
+
df = pd.DataFrame([{"label": r.get("label"), "score": r.get("score")} for r in results])
|
| 96 |
+
st.dataframe(df)
|
| 97 |
|
| 98 |
+
best = results[0]
|
| 99 |
+
st.session_state.setdefault("history", [])
|
| 100 |
+
if len(st.session_state.history) < 20:
|
| 101 |
+
st.session_state.history.append({
|
| 102 |
+
"type": "image",
|
| 103 |
+
"filename": getattr(uploaded_file, "name", "upload"),
|
| 104 |
+
"label": best.get("label"),
|
| 105 |
+
"score": float(best.get("score", 0.0)),
|
| 106 |
+
"time": datetime.utcnow().isoformat()
|
| 107 |
+
})
|
| 108 |
|
| 109 |
# ------------------- History -------------------
|
| 110 |
if "history" in st.session_state and st.session_state.history:
|
|
|
|
| 113 |
st.dataframe(df_hist)
|
| 114 |
csv = df_hist.to_csv(index=False).encode("utf-8")
|
| 115 |
st.download_button("Download History (CSV)", data=csv, file_name="analysis_history.csv", mime="text/csv")
|
|
|