MetaQu commited on
Commit
c1ebb63
·
verified ·
1 Parent(s): 604eff9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -21
app.py CHANGED
@@ -1,31 +1,29 @@
1
  import gradio as gr
2
  from transformers import pipeline
 
3
 
4
- # gunakan model deteksi AI vs Real
5
- pipe = pipeline("image-classification", model="umm-maybe/AI-image-detector")
6
 
7
- def detect_ai(image):
8
- results = pipe(image)
9
  results = sorted(results, key=lambda x: x['score'], reverse=True)
10
  label = results[0]['label']
11
- confidence = results[0]['score']
12
 
13
- if "ai" in label.lower() or "fake" in label.lower():
14
- status = "⚠️ Kemungkinan besar AI Generated"
15
  else:
16
- status = "✅ Kemungkinan besar Foto Asli"
17
 
18
- return f"{status}\n\nLabel: {label}\nConfidence: {confidence*100:.2f}%"
 
 
 
 
 
 
 
19
 
20
- with gr.Blocks() as demo:
21
- gr.Markdown("## 🖼️ AI Image Detector")
22
- with gr.Row():
23
- with gr.Column():
24
- image_input = gr.Image(type="pil", label="Upload Gambar")
25
- btn = gr.Button("Deteksi")
26
- with gr.Column():
27
- output_text = gr.Textbox(label="Hasil Deteksi", lines=5)
28
-
29
- btn.click(detect_ai, inputs=image_input, outputs=output_text)
30
-
31
- demo.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
+ from PIL import Image
4
 
5
+ # Gunakan model khusus deteksi AI-generated photo
6
+ detector = pipeline("image-classification", model="microsoft/ai-image-detector")
7
 
8
+ def detect(image):
9
+ results = detector(image)
10
  results = sorted(results, key=lambda x: x['score'], reverse=True)
11
  label = results[0]['label']
12
+ confidence = results[0]['score'] * 100
13
 
14
+ if "fake" in label.lower() or "ai" in label.lower():
15
+ return f"⚠️ Kemungkinan besar Gambar AI\n\nLabel: {label}\nConfidence: {confidence:.2f}%"
16
  else:
17
+ return f"✅ Kemungkinan besar Foto Asli\n\nLabel: {label}\nConfidence: {confidence:.2f}%"
18
 
19
+ # UI dengan Gradio
20
+ app = gr.Interface(
21
+ fn=detect,
22
+ inputs=gr.Image(type="pil", label="Upload Foto"),
23
+ outputs="text",
24
+ title="AI vs Foto Detector",
25
+ description="Unggah foto untuk mendeteksi apakah ini foto asli atau hasil AI-generated."
26
+ )
27
 
28
+ if __name__ == "__main__":
29
+ app.launch()