Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from inference import UrgencyModel | |
| from asr import Transcriber | |
| urg = UrgencyModel() | |
| asr = Transcriber() | |
| def transcribe_then_score(audio_file, thr=0.5): | |
| urg.threshold = float(thr) | |
| if audio_file is None: | |
| return "", 0.0, "Non-Urgent", "No audio provided." | |
| text = asr.transcribe_file(audio_file) | |
| res = urg.predict(text) | |
| return text, res["urgency_score"], res["urgent_label"], res["rationale"] | |
| def score_text(text, thr=0.5): | |
| urg.threshold = float(thr) | |
| res = urg.predict(text or "") | |
| return res["urgency_score"], res["urgent_label"], res["rationale"] | |
| with gr.Blocks(title="911 Urgency Prototype") as demo: | |
| gr.Markdown("# 911 Urgency Prototype\nDecision support (not dispatch).") | |
| thr = gr.Slider(0, 1, value=0.5, step=0.01, label="Decision threshold") | |
| with gr.Tab("Voice β Urgency"): | |
| gr.Markdown("Record or upload a short clip (WAV/MP3).") | |
| audio_in = gr.Audio(sources=["microphone","upload"], type="filepath") | |
| btn_v = gr.Button("Transcribe & Score") | |
| text_out = gr.Textbox(label="Transcript", lines=8) | |
| score_out = gr.Number(label="Urgency Score (0β1)") | |
| label_out = gr.Textbox(label="Urgent / Non-Urgent") | |
| rationale_out = gr.Textbox(label="Rationale") | |
| btn_v.click(transcribe_then_score, inputs=[audio_in, thr], | |
| outputs=[text_out, score_out, label_out, rationale_out]) | |
| with gr.Tab("Text β Urgency"): | |
| txt_in = gr.Textbox(label="Paste transcript", lines=8, placeholder="Paste a transcriptβ¦") | |
| btn_t = gr.Button("Score Text") | |
| score_out2 = gr.Number(label="Urgency Score (0β1)") | |
| label_out2 = gr.Textbox(label="Urgent / Non-Urgent") | |
| rationale_out2 = gr.Textbox(label="Rationale") | |
| btn_t.click(score_text, inputs=[txt_in, thr], outputs=[score_out2, label_out2, rationale_out2]) | |
| gr.Markdown("**Notes:** Prototype for QA/training. No PII stored; processing is in-memory.") | |
| if __name__ == "__main__": | |
| demo.launch() # Spaces handles networking | |