PutuPadma commited on
Commit
2bab227
·
verified ·
1 Parent(s): cdee2c6

Upload 7 files

Browse files
Files changed (7) hide show
  1. .DS_Store +0 -0
  2. app.py +14 -0
  3. chatbot.py +57 -0
  4. homepage.py +66 -0
  5. model_used/yolov5/best.pt +3 -0
  6. model_used/yolov8/best.pt +3 -0
  7. requirements.txt +91 -0
.DS_Store ADDED
Binary file (6.15 kB). View file
 
app.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from homepage import homepage
3
+ from chatbot import chatbot_bisindo
4
+
5
+ # Halaman navigasi
6
+ home_page = st.Page(homepage, title="Home", icon=":material/home:")
7
+ chatbot_page = st.Page(chatbot_bisindo, title="Chatbot BISINDO", icon=":material/chat:")
8
+
9
+ # Daftar halaman
10
+ pg = st.navigation({
11
+ "Menu": [home_page, chatbot_page],
12
+ })
13
+
14
+ pg.run()
chatbot.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+
4
+ # Konfigurasi API Gemini
5
+ API_URL = "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-exp:generateContent"
6
+ API_KEY = "" # Ganti dengan API Key Anda
7
+
8
+ # Konteks tentang BISINDO
9
+ BISINDO_CONTEXT = (
10
+ "Anda adalah chatbot yang ahli dalam menjelaskan Bahasa Isyarat Indonesia (BISINDO). "
11
+ "BISINDO adalah bahasa isyarat yang digunakan oleh komunitas Tuli di Indonesia untuk berkomunikasi. "
12
+ "Anda hanya akan menjawab pertanyaan pengguna yang berkaitan tentang BISINDO. "
13
+ "Jawab dengan bahasa yang ringkas dan mudah dimengerti."
14
+ )
15
+
16
+ def send_message_to_gemini(api_url, api_key, user_message, context):
17
+ headers = {'Content-Type': 'application/json'}
18
+ data = {"contents": [{"parts": [{"text": f"{context}\n\nPertanyaan pengguna: {user_message}"}]}]}
19
+ try:
20
+ response = requests.post(f"{api_url}?key={api_key}", headers=headers, json=data)
21
+ response_data = response.json()
22
+ candidates = response_data.get('candidates', [])
23
+ if candidates:
24
+ return candidates[0].get('content', {}).get('parts', [{}])[0].get('text', '') or "Maaf, bot tidak dapat memberikan balasan."
25
+ return "Maaf, bot tidak dapat memberikan balasan."
26
+ except requests.exceptions.RequestException as e:
27
+ return f"Terjadi kesalahan saat menghubungi API: {str(e)}"
28
+
29
+ def chatbot_bisindo():
30
+ st.title("Chatbot BISINDO")
31
+
32
+ # Inisialisasi sesi untuk menyimpan riwayat percakapan
33
+ if "messages" not in st.session_state:
34
+ st.session_state.messages = []
35
+
36
+ # Render riwayat percakapan
37
+ for message in st.session_state.messages:
38
+ with st.chat_message(message["role"]):
39
+ st.markdown(message["content"])
40
+
41
+ # Input pengguna
42
+ if user_input := st.chat_input("Tanyakan sesuatu tentang BISINDO..."):
43
+ # Tambahkan input pengguna ke riwayat
44
+ st.session_state.messages.append({"role": "user", "content": user_input})
45
+ with st.chat_message("user"):
46
+ st.markdown(user_input)
47
+
48
+ # Proses respons dari Gemini
49
+ with st.chat_message("assistant"):
50
+ bot_message_placeholder = st.empty()
51
+ bot_message_placeholder.markdown("Sedang menjawab...")
52
+ bot_reply = send_message_to_gemini(API_URL, API_KEY, user_input, BISINDO_CONTEXT)
53
+ bot_message_placeholder.markdown(bot_reply)
54
+
55
+ # Tambahkan respons bot ke riwayat
56
+ st.session_state.messages.append({"role": "assistant", "content": bot_reply})
57
+
homepage.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import cv2
3
+ import torch
4
+ import numpy as np
5
+ import time
6
+
7
+ # --- Caching Model ---
8
+ @st.cache_resource(show_spinner=False)
9
+ def load_model(model_path):
10
+ return torch.hub.load('ultralytics/yolov5', 'custom', path=model_path)
11
+
12
+ def get_color(class_id):
13
+ np.random.seed(int(class_id))
14
+ return tuple(np.random.randint(100, 255, size=3).tolist())
15
+
16
+ def detect_objects(frame, model):
17
+ frame_resized = cv2.resize(frame, (640, 480)) # Resize untuk performa lebih baik
18
+ frame_rgb = cv2.cvtColor(frame_resized, cv2.COLOR_BGR2RGB)
19
+ results = model(frame_rgb)
20
+ detections = results.xyxy[0].cpu().numpy()
21
+
22
+ for detection in detections:
23
+ xmin, ymin, xmax, ymax, confidence, class_id = detection
24
+ label = f"{model.names[int(class_id)]} {confidence:.2f}"
25
+ color = get_color(class_id)
26
+
27
+ cv2.rectangle(frame_resized, (int(xmin), int(ymin)), (int(xmax), int(ymax)), color, 2)
28
+ cv2.putText(frame_resized, label, (int(xmin), int(ymin) - 10),
29
+ cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2)
30
+
31
+ return frame_resized
32
+
33
+ def homepage():
34
+ st.title("Deteksi Bahasa Isyarat BISINDO")
35
+ model_path = 'model_used/yolov5/best.pt'
36
+ model = load_model(model_path)
37
+
38
+ if "camera_active" not in st.session_state:
39
+ st.session_state["camera_active"] = False
40
+
41
+ col1, col2 = st.columns(2)
42
+ with col1:
43
+ if st.button("🎥 Mulai Kamera"):
44
+ st.session_state["camera_active"] = True
45
+ with col2:
46
+ if st.button("🛑 Stop Kamera"):
47
+ st.session_state["camera_active"] = False
48
+
49
+ stframe = st.empty()
50
+
51
+ if st.session_state["camera_active"]:
52
+ cap = cv2.VideoCapture(0) # Pastikan kamera di index 0
53
+
54
+ while cap.isOpened() and st.session_state["camera_active"]:
55
+ ret, frame = cap.read()
56
+ if not ret:
57
+ st.error("Gagal membaca frame dari webcam.")
58
+ break
59
+
60
+ detected_frame = detect_objects(frame, model)
61
+ detected_frame_rgb = cv2.cvtColor(detected_frame, cv2.COLOR_BGR2RGB)
62
+ stframe.image(detected_frame_rgb, channels="RGB", use_container_width=True)
63
+ time.sleep(0.1)
64
+
65
+ cap.release()
66
+ st.session_state["camera_active"] = False
model_used/yolov5/best.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:90cd14d022acb22feaa1b0c71f5650def26a9b0e699fd0578a1a0915afe0827e
3
+ size 14579112
model_used/yolov8/best.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f6d16abd213a3c435ed3d53ff51104f98bc1bb10e9c37eb48992fb96e6a9cd56
3
+ size 22539555
requirements.txt ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ altair==5.5.0
2
+ annotated-types==0.7.0
3
+ attrs==25.1.0
4
+ blinker==1.9.0
5
+ Brotli @ file:///C:/b/abs_c415aux9ra/croot/brotli-split_1736182803933/work
6
+ cachetools==5.5.1
7
+ certifi @ file:///C:/b/abs_8a944p1_gn/croot/certifi_1738623753421/work/certifi
8
+ charset-normalizer @ file:///croot/charset-normalizer_1721748349566/work
9
+ click==8.1.8
10
+ colorama==0.4.6
11
+ contourpy==1.3.1
12
+ cycler==0.12.1
13
+ filelock @ file:///C:/b/abs_f2gie28u58/croot/filelock_1700591233643/work
14
+ fonttools==4.56.0
15
+ fsspec==2025.2.0
16
+ gitdb==4.0.12
17
+ GitPython==3.1.44
18
+ gmpy2 @ file:///C:/b/abs_d8ki0o0h97/croot/gmpy2_1738085498525/work
19
+ google-ai-generativelanguage==0.6.15
20
+ google-api-core==2.24.1
21
+ google-api-python-client==2.160.0
22
+ google-auth==2.38.0
23
+ google-auth-httplib2==0.2.0
24
+ google-generativeai==0.8.4
25
+ googleapis-common-protos==1.67.0rc1
26
+ grpcio==1.70.0
27
+ grpcio-status==1.70.0
28
+ httplib2==0.22.0
29
+ idna @ file:///C:/b/abs_aad84bnnw5/croot/idna_1714398896795/work
30
+ Jinja2 @ file:///C:/b/abs_10zs3i4lof/croot/jinja2_1737760123028/work
31
+ jsonschema==4.23.0
32
+ jsonschema-specifications==2024.10.1
33
+ kiwisolver==1.4.8
34
+ markdown-it-py==3.0.0
35
+ MarkupSafe @ file:///C:/b/abs_a0ma7ge0jc/croot/markupsafe_1738584052792/work
36
+ matplotlib==3.10.0
37
+ mdurl==0.1.2
38
+ mkl-service==2.4.0
39
+ mkl_fft @ file:///C:/Users/dev-admin/mkl/mkl_fft_1730823082242/work
40
+ mkl_random @ file:///C:/Users/dev-admin/mkl/mkl_random_1730822522280/work
41
+ mpmath @ file:///C:/b/abs_7833jrbiox/croot/mpmath_1690848321154/work
42
+ narwhals==1.25.2
43
+ networkx @ file:///C:/b/abs_b054htfn9t/croot/networkx_1737043671910/work
44
+ numpy @ file:///C:/b/abs_0123vcxhf8/croot/numpy_and_numpy_base_1725470331966/work/dist/numpy-2.0.1-cp310-cp310-win_amd64.whl#sha256=e824ec3b279f4c5207736c83ac2f2dc79b489e08501a4ea9e3fc178c45db289b
45
+ opencv-python==4.11.0.86
46
+ packaging==24.2
47
+ pandas==2.2.3
48
+ pillow @ file:///C:/b/abs_b50vowcrzo/croot/pillow_1738010273782/work
49
+ proto-plus==1.26.0
50
+ protobuf==5.29.3
51
+ psutil==6.1.1
52
+ py-cpuinfo==9.0.0
53
+ pyarrow==19.0.0
54
+ pyasn1==0.6.1
55
+ pyasn1_modules==0.4.1
56
+ pydantic==2.10.6
57
+ pydantic_core==2.27.2
58
+ pydeck==0.9.1
59
+ Pygments==2.19.1
60
+ pyparsing==3.2.1
61
+ PySocks @ file:///C:/ci_310/pysocks_1642089375450/work
62
+ python-dateutil==2.9.0.post0
63
+ python-dotenv==1.0.1
64
+ pytz==2025.1
65
+ PyYAML @ file:///C:/b/abs_14xkfs39bx/croot/pyyaml_1728657968772/work
66
+ referencing==0.36.2
67
+ requests @ file:///C:/b/abs_c3508vg8ez/croot/requests_1731000584867/work
68
+ rich==13.9.4
69
+ rpds-py==0.22.3
70
+ rsa==4.9
71
+ scipy==1.15.1
72
+ seaborn==0.13.2
73
+ six==1.17.0
74
+ smmap==5.0.2
75
+ streamlit==1.42.0
76
+ sympy==1.13.1
77
+ tenacity==9.0.0
78
+ toml==0.10.2
79
+ torch==2.5.1
80
+ torchaudio==2.5.1
81
+ torchvision==0.20.1
82
+ tornado==6.4.2
83
+ tqdm==4.67.1
84
+ typing_extensions @ file:///C:/b/abs_0ffjxtihug/croot/typing_extensions_1734714875646/work
85
+ tzdata==2025.1
86
+ ultralytics==8.3.73
87
+ ultralytics-thop==2.0.14
88
+ uritemplate==4.1.1
89
+ urllib3 @ file:///C:/b/abs_7bst06lizn/croot/urllib3_1737133657081/work
90
+ watchdog==6.0.0
91
+ win-inet-pton @ file:///C:/ci_310/win_inet_pton_1642658466512/work