pravjet commited on
Commit
94f33f5
·
verified ·
1 Parent(s): ffebf2e

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +44 -0
  2. requirements.txt +4 -3
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import streamlit as st
3
+ from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
4
+ from transformers import ViTImageProcessor, ViTForImageClassification
5
+ from PIL import Image
6
+ import torch
7
+
8
+ st.set_page_config(page_title="AI Misinformation & Deepfake Detector", layout="wide")
9
+
10
+ # Sidebar selection
11
+ option = st.sidebar.selectbox("Choose Detection Type", ["Text Misinformation", "Image Deepfake"])
12
+
13
+ if option == "Text Misinformation":
14
+ st.title("🧠 Text Misinformation Detection")
15
+ text_input = st.text_area("Enter text to analyze:", height=150)
16
+ if st.button("Analyze Text"):
17
+ if text_input.strip():
18
+ model_name = "mrm8488/bert-tiny-finetuned-fake-news-detection"
19
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
20
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
21
+ nlp = pipeline("text-classification", model=model, tokenizer=tokenizer)
22
+ result = nlp(text_input)[0]
23
+ st.success(f"Prediction: {result['label']} ({round(result['score']*100, 2)}%)")
24
+ else:
25
+ st.warning("Please enter some text.")
26
+
27
+ elif option == "Image Deepfake":
28
+ st.title("🖼️ Image Deepfake Detection")
29
+ uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
30
+ if uploaded_file is not None:
31
+ image = Image.open(uploaded_file).convert("RGB")
32
+ st.image(image, caption="Uploaded Image", use_column_width=True)
33
+
34
+ if st.button("Analyze Image"):
35
+ model_name = "prithivMLmods/Deep-Fake-Detector-v2-Model"
36
+ processor = ViTImageProcessor.from_pretrained(model_name)
37
+ model = ViTForImageClassification.from_pretrained(model_name)
38
+ inputs = processor(images=image, return_tensors="pt")
39
+ with torch.no_grad():
40
+ outputs = model(**inputs)
41
+ logits = outputs.logits
42
+ predicted_class = torch.argmax(logits, dim=1).item()
43
+ label = model.config.id2label[predicted_class]
44
+ st.success(f"Prediction: {label}")
requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
- altair
2
- pandas
3
- streamlit
 
 
1
+ streamlit
2
+ transformers
3
+ torch
4
+ pillow