File size: 2,444 Bytes
49e7846
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import gradio as gr
import os
import requests
from dotenv import load_dotenv

load_dotenv()
API_TRANSCRIBE = os.getenv("API_TRANSCRIBE")
API_TEXT = os.getenv("API_TEXT")

# ==== Function for backend calls ====
def handle_audio(audio_file):
    if audio_file is None:
        return "-", "-", "-"
    with open(audio_file, "rb") as f:
        files = {"audio": f}
        response = requests.post(API_TRANSCRIBE, files=files)
        result = response.json()
    return result.get("transcription", "-"), result.get("soap_content", "-"), result.get("tags_content", "-")

def handle_text(dialogue):
    if not dialogue.strip():
        return "-", "-", "-"
    response = requests.post(API_TEXT, json={"dialogue": dialogue})
    result = response.json()
    return dialogue, result.get("soap_content", "-"), result.get("tags_content", "-")

# ==== Function to toggle inputs ====
def toggle_inputs(choice):
    return (
        gr.update(visible=(choice == "Upload Audio")),
        gr.update(visible=(choice == "Rekam Audio")),
        gr.update(visible=(choice == "Input Teks")),
    )

# ==== UI ====
with gr.Blocks(title="SOAP AI Dropdown Input") as app:
    gr.Markdown("## 🩺 SOAP AI β€” Pilih Jenis Input")

    input_choice = gr.Dropdown(
        choices=["Upload Audio", "Input Teks"],
        value="Upload Audio",
        label="Pilih Metode Input"
    )

    # Input fields (hidden by default except selected)
    audio_upload = gr.Audio("microphone",label="πŸ”Š Upload File Audio", type="filepath", visible=True)
    text_input = gr.Textbox(label="πŸ“ Masukkan Percakapan Dokter-Pasien", lines=6, visible=False)

    # Tombol proses
    process_button = gr.Button("πŸš€ Proses ke SOAP")

    # Output
    transcript_output = gr.Textbox(label="πŸ“ Hasil Transkripsi", lines=3)
    soap_output = gr.Textbox(label="πŸ“‹ Ringkasan SOAP", lines=6)
    tags_output = gr.Textbox(label="🏷️ Medical Tags", lines=6)

    # === Events ===
    input_choice.change(fn=toggle_inputs, inputs=input_choice,
                        outputs=[audio_upload, text_input])

    process_button.click(
        fn=handle_audio,
        inputs=audio_upload,
        outputs=[transcript_output, soap_output, tags_output],
        show_progress="minimal"
    )

    process_button.click(
        fn=handle_text,
        inputs=text_input,
        outputs=[transcript_output, soap_output, tags_output],
        show_progress="minimal"
    )

app.launch()