codrizsain commited on
Commit
966bd8f
·
verified ·
1 Parent(s): 07eae2b

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -57
app.py DELETED
@@ -1,57 +0,0 @@
1
- import gradio as gr
2
- import cv2
3
- import mediapipe as mp
4
- import time
5
-
6
- mp_hands = mp.solutions.hands
7
- mp_drawing = mp.solutions.drawing_utils
8
-
9
- # OPTIMASI 1: Gunakan model_complexity=0 (Mode paling ringan dan cepat)
10
- hands_detector = mp_hands.Hands(
11
- model_complexity=0,
12
- min_detection_confidence=0.5,
13
- min_tracking_confidence=0.5
14
- )
15
-
16
- def detect_optimized(image, last_trigger_time):
17
- if image is None: return None, None, None, last_trigger_time
18
-
19
- # OPTIMASI 2: Perkecil gambar khusus untuk "dilihat" oleh AI
20
- # Proses gambar ukuran 320x240 jauh lebih ringan untuk CPU gratisan
21
- small_image = cv2.resize(image, (320, 240))
22
- rgb_small = cv2.cvtColor(small_image, cv2.COLOR_BGR2RGB)
23
-
24
- results = hands_detector.process(rgb_small)
25
-
26
- hand_detected = False
27
- if results.multi_hand_landmarks:
28
- hand_detected = True
29
- for res in results.multi_hand_landmarks:
30
- # Garis kerangka tetap digambar di gambar ASLI agar tetap HD dilihat pengguna
31
- mp_drawing.draw_landmarks(image, res, mp_hands.HAND_CONNECTIONS)
32
-
33
- curr = time.time()
34
- gif, audio = None, None
35
- if hand_detected and (curr - last_trigger_time > 3):
36
- gif, audio, last_trigger_time = "animasi.gif", "suara.mp3", curr
37
-
38
- return image, gif, audio, last_trigger_time
39
-
40
- with gr.Blocks() as demo:
41
- gr.Markdown("# ✋ Hand Detector (Speed Optimized)")
42
- t_state = gr.State(0)
43
- with gr.Row():
44
- cam = gr.Image(sources=["webcam"], streaming=True)
45
- with gr.Column():
46
- out_cam = gr.Image(label="Live Monitor")
47
- out_gif = gr.Image(label="Respon Visual")
48
- out_aud = gr.Audio(autoplay=True)
49
-
50
- cam.stream(
51
- fn=detect_optimized,
52
- inputs=[cam, t_state],
53
- outputs=[out_cam, out_gif, out_aud, t_state],
54
- show_progress="hidden"
55
- )
56
-
57
- demo.launch()