MetaQu commited on
Commit
54df4dd
·
verified ·
1 Parent(s): a2e5023

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -18
app.py CHANGED
@@ -1,28 +1,26 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Load model dari Hugging Face (pretrained AI image detector)
5
- classifier = pipeline("image-classification", model="dima806/fake-image-detection")
6
 
7
- def detect_image(img):
8
- results = classifier(img)
9
- # Ambil hasil dengan skor tertinggi
10
- top_result = max(results, key=lambda x: x["score"])
11
- label = top_result["label"]
12
- score = round(top_result["score"] * 100, 2)
13
-
14
- if label.lower() == "fake":
15
- return f"🚨 Gambar kemungkinan besar AI Generated ({score}%)"
16
  else:
17
- return f" Gambar kemungkinan besar Asli ({score}%)"
18
 
19
- # Gradio UI
20
  demo = gr.Interface(
21
- fn=detect_image,
22
- inputs=gr.Image(type="filepath"),
23
- outputs="text",
24
  title="AI Image Detector",
25
- description="Upload foto untuk mendeteksi apakah gambar asli atau AI generated."
26
  )
27
 
28
- demo.launch()
 
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Pakai model yang masih tersedia (public)
5
+ classifier = pipeline("image-classification", model="orpatashnik/StyleGAN-nada-detector")
6
 
7
+ def detect_ai(image):
8
+ results = classifier(image)
9
+ label = results[0]['label']
10
+ score = results[0]['score']
11
+ if "real" in label.lower():
12
+ return f"🌍 Foto Asli (confidence: {score:.2f})"
 
 
 
13
  else:
14
+ return f"🤖 Gambar AI (confidence: {score:.2f})"
15
 
16
+ # Buat interface Gradio
17
  demo = gr.Interface(
18
+ fn=detect_ai,
19
+ inputs=gr.Image(type="pil", label="Upload Gambar"),
20
+ outputs=gr.Textbox(label="Hasil Deteksi"),
21
  title="AI Image Detector",
22
+ description="Upload gambar untuk mendeteksi apakah gambar asli atau buatan AI."
23
  )
24
 
25
+ if __name__ == "__main__":
26
+ demo.launch()