Spaces:
Sleeping
Sleeping
akhfzl commited on
Commit Β·
95122b3
1
Parent(s): 65217d6
voice-processing
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
-
from faceVerificationUtilization import FaceValidation, FaceRecord, Recognize
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
-
with gr.Blocks() as demo:
|
| 5 |
with gr.Tabs():
|
| 6 |
with gr.Tab("Face Validation"):
|
| 7 |
gr.Markdown("## Cek validasi wajah")
|
|
@@ -34,7 +34,7 @@ with gr.Blocks() as demo:
|
|
| 34 |
b3.click(fn=lambda img, n: FaceRecord(img, n, 3), inputs=[webcam, name], outputs=status3)
|
| 35 |
b4.click(fn=lambda img, n: FaceRecord(img, n, 4), inputs=[webcam, name], outputs=status4)
|
| 36 |
|
| 37 |
-
with gr.Tab("
|
| 38 |
gr.Markdown("## Cek Siapa Anda")
|
| 39 |
gr.Interface(
|
| 40 |
fn=Recognize,
|
|
@@ -43,5 +43,44 @@ with gr.Blocks() as demo:
|
|
| 43 |
live=True
|
| 44 |
)
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
if __name__ == "__main__":
|
| 47 |
demo.launch()
|
|
|
|
| 1 |
+
from faceVerificationUtilization import FaceValidation, FaceRecord, Recognize, UploadVoice
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 5 |
with gr.Tabs():
|
| 6 |
with gr.Tab("Face Validation"):
|
| 7 |
gr.Markdown("## Cek validasi wajah")
|
|
|
|
| 34 |
b3.click(fn=lambda img, n: FaceRecord(img, n, 3), inputs=[webcam, name], outputs=status3)
|
| 35 |
b4.click(fn=lambda img, n: FaceRecord(img, n, 4), inputs=[webcam, name], outputs=status4)
|
| 36 |
|
| 37 |
+
with gr.Tab("Face Recognition"):
|
| 38 |
gr.Markdown("## Cek Siapa Anda")
|
| 39 |
gr.Interface(
|
| 40 |
fn=Recognize,
|
|
|
|
| 43 |
live=True
|
| 44 |
)
|
| 45 |
|
| 46 |
+
with gr.Tab("Voice Processing"):
|
| 47 |
+
with gr.Row():
|
| 48 |
+
with gr.Column(scale=1):
|
| 49 |
+
gr.Markdown("## π€ Voice Recorder (.wav)")
|
| 50 |
+
gr.Markdown("Rekam suara Anda lalu otomatis diunggah ke **n8n** untuk transkripsi & ringkasan.")
|
| 51 |
+
|
| 52 |
+
# komponen input rekaman
|
| 53 |
+
audio_input = gr.Audio(
|
| 54 |
+
sources=["microphone"],
|
| 55 |
+
type="filepath",
|
| 56 |
+
label="ποΈ Rekam Suara",
|
| 57 |
+
show_download_button=True
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
# tombol upload
|
| 61 |
+
submit_btn = gr.Button("β« Stop & Upload", variant="primary")
|
| 62 |
+
|
| 63 |
+
# status
|
| 64 |
+
status = gr.Label(label="Status")
|
| 65 |
+
|
| 66 |
+
with gr.Column(scale=1):
|
| 67 |
+
# hasil transkripsi & ringkasan
|
| 68 |
+
transcription = gr.Textbox(
|
| 69 |
+
label="π Hasil Transkripsi",
|
| 70 |
+
interactive=False,
|
| 71 |
+
lines=5
|
| 72 |
+
)
|
| 73 |
+
summary = gr.Textbox(
|
| 74 |
+
label="π Ringkasan",
|
| 75 |
+
interactive=False,
|
| 76 |
+
lines=5
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
submit_btn.click(
|
| 80 |
+
UploadVoice,
|
| 81 |
+
inputs=audio_input,
|
| 82 |
+
outputs=[status, transcription, summary]
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
if __name__ == "__main__":
|
| 86 |
demo.launch()
|
faceVerificationUtilization/__init__.py
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
from .utils import FaceValidation, FaceRecord, Recognize
|
|
|
|
| 1 |
+
from .utils import FaceValidation, FaceRecord, Recognize, UploadVoice
|
faceVerificationUtilization/__pycache__/__init__.cpython-313.pyc
CHANGED
|
Binary files a/faceVerificationUtilization/__pycache__/__init__.cpython-313.pyc and b/faceVerificationUtilization/__pycache__/__init__.cpython-313.pyc differ
|
|
|
faceVerificationUtilization/__pycache__/utils.cpython-313.pyc
CHANGED
|
Binary files a/faceVerificationUtilization/__pycache__/utils.cpython-313.pyc and b/faceVerificationUtilization/__pycache__/utils.cpython-313.pyc differ
|
|
|
faceVerificationUtilization/utils.py
CHANGED
|
@@ -5,6 +5,7 @@ import torch
|
|
| 5 |
import pandas as pd
|
| 6 |
from .setConfig import efficientnet_model, face_detector, transform, pca_xgb, faiss, load_db
|
| 7 |
import os
|
|
|
|
| 8 |
|
| 9 |
def ImgPreprocessing(img):
|
| 10 |
if len(img.shape) == 2 or img.shape[2] == 1:
|
|
@@ -58,6 +59,8 @@ def FaceValidationPredict(**face_crop):
|
|
| 58 |
|
| 59 |
return pred, features, face_crop
|
| 60 |
|
|
|
|
|
|
|
| 61 |
def FaceValidation(frame: np.ndarray):
|
| 62 |
if frame is None:
|
| 63 |
return "No frame captured from webcam"
|
|
@@ -150,8 +153,31 @@ def Recognize(frame: np.ndarray):
|
|
| 150 |
score = float(D[0][0])
|
| 151 |
idx = int(I[0][0])
|
| 152 |
|
| 153 |
-
if score < 0.
|
| 154 |
return f"Tidak dikenali"
|
| 155 |
else:
|
| 156 |
return f"Terkenali sebagai: {labels[idx]} - (score={score:.2f})"
|
| 157 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
import pandas as pd
|
| 6 |
from .setConfig import efficientnet_model, face_detector, transform, pca_xgb, faiss, load_db
|
| 7 |
import os
|
| 8 |
+
import requests
|
| 9 |
|
| 10 |
def ImgPreprocessing(img):
|
| 11 |
if len(img.shape) == 2 or img.shape[2] == 1:
|
|
|
|
| 59 |
|
| 60 |
return pred, features, face_crop
|
| 61 |
|
| 62 |
+
|
| 63 |
+
# feature
|
| 64 |
def FaceValidation(frame: np.ndarray):
|
| 65 |
if frame is None:
|
| 66 |
return "No frame captured from webcam"
|
|
|
|
| 153 |
score = float(D[0][0])
|
| 154 |
idx = int(I[0][0])
|
| 155 |
|
| 156 |
+
if score < 0.7:
|
| 157 |
return f"Tidak dikenali"
|
| 158 |
else:
|
| 159 |
return f"Terkenali sebagai: {labels[idx]} - (score={score:.2f})"
|
| 160 |
|
| 161 |
+
def UploadVoice(audio_file):
|
| 162 |
+
if audio_file is None:
|
| 163 |
+
return "β Tidak ada file audio. Coba rekam lagi.", "", ""
|
| 164 |
+
|
| 165 |
+
try:
|
| 166 |
+
with open(audio_file, "rb") as f:
|
| 167 |
+
files = {"file": ("recording.wav", f, "audio/wav")}
|
| 168 |
+
response = requests.post("https://n8n.smartid.or.id/webhook/voice-upload", files=files)
|
| 169 |
+
|
| 170 |
+
if response.status_code != 200:
|
| 171 |
+
return f"β Gagal upload. Status: {response.status_code}", "", ""
|
| 172 |
+
|
| 173 |
+
try:
|
| 174 |
+
data = response.json()
|
| 175 |
+
except Exception:
|
| 176 |
+
return f"β Server tidak mengirim JSON. Balasan:\n{response}", "", ""
|
| 177 |
+
|
| 178 |
+
transcription = data.get("transcribe", "(Tidak ada transkripsi)")
|
| 179 |
+
summary = data.get("summary", "(Tidak ada ringkasan)")
|
| 180 |
+
|
| 181 |
+
return "β
Rekaman berhasil diproses", f"Transcribe: {transcription}", f"Summary: {summary}"
|
| 182 |
+
except Exception as e:
|
| 183 |
+
return f"β Gagal upload: {e}.", f"Transcribe: ", f"Summary: "
|