MetaQu commited on
Commit
d748331
·
verified ·
1 Parent(s): ec2e06c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -1,20 +1,23 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Gunakan model publik valid
5
  classifier = pipeline("image-classification", model="dima806/deepfake_vs_real_image_detection")
6
 
7
  def detect_ai(image):
8
  results = classifier(image)
9
- label = results[0]['label']
10
- score = results[0]['score']
11
- # logika menentukan hasil
12
- if "real" in label.lower():
13
- return f"✅ Foto Asli (confidence: {score:.2f})"
 
 
 
14
  else:
15
- return f"🤖 Gambar AI / Fake (confidence: {score:.2f})"
 
 
16
 
17
- # Buat interface Gradio
18
  demo = gr.Interface(
19
  fn=detect_ai,
20
  inputs=gr.Image(type="pil", label="Upload Gambar"),
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
 
4
  classifier = pipeline("image-classification", model="dima806/deepfake_vs_real_image_detection")
5
 
6
  def detect_ai(image):
7
  results = classifier(image)
8
+
9
+ output_str = "Hasil Deteksi:\n"
10
+ for r in results:
11
+ output_str += f"- {r['label']}: {r['score']:.2f}\n"
12
+
13
+ best = max(results, key=lambda x: x['score'])
14
+ if "real" in best['label'].lower():
15
+ output_str = f"✅ Foto Asli (confidence: {best['score']:.2f})\n\n" + output_str
16
  else:
17
+ output_str = f"🤖 Gambar AI / Fake (confidence: {best['score']:.2f})\n\n" + output_str
18
+
19
+ return output_str
20
 
 
21
  demo = gr.Interface(
22
  fn=detect_ai,
23
  inputs=gr.Image(type="pil", label="Upload Gambar"),