Spaces:
Running
Running
first commit
Browse files- app.py +77 -24
- requirements.txt +5 -0
app.py
CHANGED
@@ -10,7 +10,7 @@ API_TEXT = os.getenv("API_TEXT")
|
|
10 |
# ==== Function for backend calls ====
|
11 |
def handle_audio(audio_file):
|
12 |
if audio_file is None:
|
13 |
-
return "
|
14 |
with open(audio_file, "rb") as f:
|
15 |
files = {"audio": f}
|
16 |
response = requests.post(API_TRANSCRIBE, files=files)
|
@@ -19,32 +19,81 @@ def handle_audio(audio_file):
|
|
19 |
|
20 |
def handle_text(dialogue):
|
21 |
if not dialogue.strip():
|
22 |
-
return "
|
23 |
response = requests.post(API_TEXT, json={"dialogue": dialogue})
|
24 |
result = response.json()
|
25 |
return dialogue, result.get("soap_content", "-"), result.get("tags_content", "-")
|
26 |
|
27 |
-
# ==== Function to toggle inputs ====
|
28 |
-
def
|
|
|
29 |
return (
|
30 |
-
gr.update(visible=(choice == "Upload Audio")),
|
31 |
-
gr.update(visible=(choice == "
|
32 |
-
gr.update(visible=(choice == "Input Teks")),
|
|
|
|
|
|
|
33 |
)
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
# ==== UI ====
|
36 |
with gr.Blocks(title="SOAP AI Dropdown Input") as app:
|
37 |
gr.Markdown("## π©Ί SOAP AI β Pilih Jenis Input")
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
44 |
|
45 |
# Input fields (hidden by default except selected)
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
# Tombol proses
|
50 |
process_button = gr.Button("π Proses ke SOAP")
|
@@ -55,21 +104,25 @@ with gr.Blocks(title="SOAP AI Dropdown Input") as app:
|
|
55 |
tags_output = gr.Textbox(label="π·οΈ Medical Tags", lines=6)
|
56 |
|
57 |
# === Events ===
|
58 |
-
|
59 |
-
|
|
|
|
|
|
|
|
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
outputs=[transcript_output, soap_output, tags_output]
|
65 |
-
show_progress="minimal"
|
66 |
)
|
67 |
|
|
|
68 |
process_button.click(
|
69 |
-
fn=
|
70 |
-
inputs=text_input,
|
71 |
outputs=[transcript_output, soap_output, tags_output],
|
72 |
show_progress="minimal"
|
73 |
)
|
74 |
|
75 |
-
app.launch()
|
|
|
10 |
# ==== Function for backend calls ====
|
11 |
def handle_audio(audio_file):
|
12 |
if audio_file is None:
|
13 |
+
return "", "", ""
|
14 |
with open(audio_file, "rb") as f:
|
15 |
files = {"audio": f}
|
16 |
response = requests.post(API_TRANSCRIBE, files=files)
|
|
|
19 |
|
20 |
def handle_text(dialogue):
|
21 |
if not dialogue.strip():
|
22 |
+
return "", "", ""
|
23 |
response = requests.post(API_TEXT, json={"dialogue": dialogue})
|
24 |
result = response.json()
|
25 |
return dialogue, result.get("soap_content", "-"), result.get("tags_content", "-")
|
26 |
|
27 |
+
# ==== Function to toggle inputs with refresh ====
|
28 |
+
def toggle_inputs_with_refresh(choice):
|
29 |
+
# Clear semua output saat dropdown berubah
|
30 |
return (
|
31 |
+
gr.update(visible=(choice == "Upload Audio"), value=None), # Clear audio upload
|
32 |
+
gr.update(visible=(choice == "Realtime Recording"), value=None), # Clear audio record
|
33 |
+
gr.update(visible=(choice == "Input Teks"), value=""), # Clear text input
|
34 |
+
gr.update(value=""), # Clear transcript output
|
35 |
+
gr.update(value=""), # Clear SOAP output
|
36 |
+
gr.update(value="") # Clear tags output
|
37 |
)
|
38 |
|
39 |
+
# ==== Function to clear all data ====
|
40 |
+
def clear_all_data():
|
41 |
+
return (
|
42 |
+
gr.update(value=None), # Clear audio upload
|
43 |
+
gr.update(value=None), # Clear audio record
|
44 |
+
gr.update(value=""), # Clear text input
|
45 |
+
gr.update(value=""), # Clear transcript output
|
46 |
+
gr.update(value=""), # Clear SOAP output
|
47 |
+
gr.update(value="") # Clear tags output
|
48 |
+
)
|
49 |
+
|
50 |
+
# ==== Combined processing function ====
|
51 |
+
def process_data(choice, audio_upload, audio_record, text_input):
|
52 |
+
if choice == "Upload Audio":
|
53 |
+
return handle_audio(audio_upload)
|
54 |
+
elif choice == "Realtime Recording":
|
55 |
+
return handle_audio(audio_record)
|
56 |
+
elif choice == "Input Teks":
|
57 |
+
return handle_text(text_input)
|
58 |
+
else:
|
59 |
+
return "", "", ""
|
60 |
+
|
61 |
# ==== UI ====
|
62 |
with gr.Blocks(title="SOAP AI Dropdown Input") as app:
|
63 |
gr.Markdown("## π©Ί SOAP AI β Pilih Jenis Input")
|
64 |
|
65 |
+
with gr.Row():
|
66 |
+
input_choice = gr.Dropdown(
|
67 |
+
choices=["Upload Audio", "Realtime Recording", "Input Teks"],
|
68 |
+
value="Upload Audio",
|
69 |
+
label="Pilih Metode Input",
|
70 |
+
scale=4
|
71 |
+
)
|
72 |
+
clear_button = gr.Button("ποΈClear all", variant="secondary", size="sm", scale=0.5, min_width=25)
|
73 |
|
74 |
# Input fields (hidden by default except selected)
|
75 |
+
# Upload Audio - seperti gambar 1 (drag & drop + upload button)
|
76 |
+
audio_upload = gr.Audio(
|
77 |
+
sources=["upload"],
|
78 |
+
label="π Upload File Audio",
|
79 |
+
type="filepath",
|
80 |
+
visible=True
|
81 |
+
)
|
82 |
+
|
83 |
+
# Realtime Recording - seperti gambar 2 (tombol record + microphone selector)
|
84 |
+
audio_record = gr.Audio(
|
85 |
+
sources=["microphone"],
|
86 |
+
label="π Realtime Recording",
|
87 |
+
type="filepath",
|
88 |
+
visible=False
|
89 |
+
)
|
90 |
+
|
91 |
+
# Text Input
|
92 |
+
text_input = gr.Textbox(
|
93 |
+
label="π Masukkan Percakapan Dokter-Pasien",
|
94 |
+
lines=6,
|
95 |
+
visible=False
|
96 |
+
)
|
97 |
|
98 |
# Tombol proses
|
99 |
process_button = gr.Button("π Proses ke SOAP")
|
|
|
104 |
tags_output = gr.Textbox(label="π·οΈ Medical Tags", lines=6)
|
105 |
|
106 |
# === Events ===
|
107 |
+
# Event untuk dropdown change - akan clear semua data
|
108 |
+
input_choice.change(
|
109 |
+
fn=toggle_inputs_with_refresh,
|
110 |
+
inputs=input_choice,
|
111 |
+
outputs=[audio_upload, audio_record, text_input, transcript_output, soap_output, tags_output]
|
112 |
+
)
|
113 |
|
114 |
+
# Event untuk tombol clear - akan clear semua data
|
115 |
+
clear_button.click(
|
116 |
+
fn=clear_all_data,
|
117 |
+
outputs=[audio_upload, audio_record, text_input, transcript_output, soap_output, tags_output]
|
|
|
118 |
)
|
119 |
|
120 |
+
# Single event handler untuk semua jenis input
|
121 |
process_button.click(
|
122 |
+
fn=process_data,
|
123 |
+
inputs=[input_choice, audio_upload, audio_record, text_input],
|
124 |
outputs=[transcript_output, soap_output, tags_output],
|
125 |
show_progress="minimal"
|
126 |
)
|
127 |
|
128 |
+
app.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio==5.19.0
|
2 |
+
groq==0.18.0
|
3 |
+
python-dotenv==1.0.1
|
4 |
+
sumy==0.11.0
|
5 |
+
nltk==3.9.1
|