Spaces:
Sleeping
Sleeping
first commit
Browse files
.env
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
GROQ_API_KEY=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
|
| 2 |
+
API_TRANSCRIBE=https://soap-ai-928613594324.asia-southeast2.run.app/full_process
|
| 3 |
+
API_TEXT=https://soap-ai-928613594324.asia-southeast2.run.app/soap_tags
|
app.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
import requests
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
|
| 6 |
+
load_dotenv()
|
| 7 |
+
API_TRANSCRIBE = os.getenv("API_TRANSCRIBE")
|
| 8 |
+
API_TEXT = os.getenv("API_TEXT")
|
| 9 |
+
|
| 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)
|
| 17 |
+
result = response.json()
|
| 18 |
+
return result.get("transcription", "-"), result.get("soap_content", "-"), result.get("tags_content", "-")
|
| 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")
|
| 51 |
+
|
| 52 |
+
# Output
|
| 53 |
+
transcript_output = gr.Textbox(label="π Hasil Transkripsi", lines=3)
|
| 54 |
+
soap_output = gr.Textbox(label="π Ringkasan SOAP", lines=6)
|
| 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()
|