syafiqq02 commited on
Commit
b55b713
Β·
1 Parent(s): 49e7846

first commit

Browse files
Files changed (2) hide show
  1. app.py +77 -24
  2. 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 toggle_inputs(choice):
 
29
  return (
30
- gr.update(visible=(choice == "Upload Audio")),
31
- gr.update(visible=(choice == "Rekam Audio")),
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
- input_choice = gr.Dropdown(
40
- choices=["Upload Audio", "Input Teks"],
41
- value="Upload Audio",
42
- label="Pilih Metode Input"
43
- )
 
 
 
44
 
45
  # Input fields (hidden by default except selected)
46
- audio_upload = gr.Audio("microphone",label="πŸ”Š Upload File Audio", type="filepath", visible=True)
47
- text_input = gr.Textbox(label="πŸ“ Masukkan Percakapan Dokter-Pasien", lines=6, visible=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
- input_choice.change(fn=toggle_inputs, inputs=input_choice,
59
- outputs=[audio_upload, text_input])
 
 
 
 
60
 
61
- process_button.click(
62
- fn=handle_audio,
63
- inputs=audio_upload,
64
- outputs=[transcript_output, soap_output, tags_output],
65
- show_progress="minimal"
66
  )
67
 
 
68
  process_button.click(
69
- fn=handle_text,
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