MetaQu commited on
Commit
2d38802
·
verified ·
1 Parent(s): 211d58b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -17
app.py CHANGED
@@ -1,27 +1,32 @@
1
- from transformers import pipeline
2
  import gradio as gr
 
 
3
 
4
- # Ganti model dengan yang khusus AI detection
5
- classifier = pipeline("image-classification", model="microsoft/ai-image-detector")
6
 
7
- def detect_image(image):
 
8
  results = classifier(image)
9
- label = results[0]["label"]
10
- score = results[0]["score"] * 100
 
 
11
 
12
- if "fake" in label.lower() or "ai" in label.lower():
13
- verdict = "Kemungkinan besar Hasil AI"
14
  else:
15
- verdict = "Kemungkinan besar Foto Asli"
16
 
17
- return f"{verdict}\n\nLabel: {label}\nConfidence: {score:.2f}%"
18
 
19
- iface = gr.Interface(
20
- fn=detect_image,
21
- inputs=gr.Image(type="pil"),
22
- outputs="text",
23
- title="Deteksi Foto AI vs Asli",
24
- description="Upload foto untuk mendeteksi apakah asli atau hasil AI."
25
  )
26
 
27
- iface.launch()
 
 
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
+ from PIL import Image
4
 
5
+ # Gunakan model deteksi publik
6
+ classifier = pipeline("image-classification", model="dima806/deepfake_vs_real_image_detection")
7
 
8
+ def detect(image):
9
+ # image dari Gradio
10
  results = classifier(image)
11
+ # hasil tertinggi
12
+ best = max(results, key=lambda x: x['score'])
13
+ label = best['label']
14
+ confidence = best['score'] * 100
15
 
16
+ if "fake" in label.lower() or "generated" in label.lower() or "ai" in label.lower():
17
+ verdict = "⚠️ Kemungkinan besar Gambar AI / Fake"
18
  else:
19
+ verdict = "Kemungkinan besar Foto Asli"
20
 
21
+ return f"{verdict}\n\nLabel: {label}\nConfidence: {confidence:.2f}%"
22
 
23
+ app = gr.Interface(
24
+ fn=detect,
25
+ inputs=gr.Image(type="pil", label="Upload Foto"),
26
+ outputs=gr.Textbox(label="Hasil Deteksi"),
27
+ title="Detektor Foto vs AI",
28
+ description="Unggah foto realistik untuk mendeteksi apakah foto asli atau hasil AI."
29
  )
30
 
31
+ if __name__ == "__main__":
32
+ app.launch()