Spaces:
Sleeping
Sleeping
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() | |