Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import spaces
|
2 |
import torch
|
3 |
import gradio as gr
|
4 |
-
from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
|
5 |
from threading import Thread
|
6 |
from typing import Iterator
|
7 |
import os
|
@@ -89,53 +89,26 @@ def generate_soap(
|
|
89 |
outputs.append(text)
|
90 |
yield "".join(outputs)
|
91 |
|
92 |
-
# Gradio
|
93 |
demo = gr.Blocks(theme=gr.themes.Ocean())
|
94 |
|
95 |
-
# Interface for microphone or file transcription
|
96 |
-
mf_transcribe = gr.Interface(
|
97 |
-
fn=transcribe,
|
98 |
-
inputs=[
|
99 |
-
gr.Audio(sources="microphone", type="filepath"),
|
100 |
-
gr.Radio(["transcribe", "translate"], label="Task", value="transcribe")
|
101 |
-
],
|
102 |
-
outputs="text",
|
103 |
-
title="Audio Transcribe",
|
104 |
-
description="Transcribe long-form microphone or audio inputs."
|
105 |
-
)
|
106 |
-
|
107 |
-
file_transcribe = gr.Interface(
|
108 |
-
fn=transcribe,
|
109 |
-
inputs=[
|
110 |
-
gr.Audio(sources="upload", type="filepath", label="Audio file"),
|
111 |
-
gr.Radio(["transcribe", "translate"], label="Task", value="transcribe")
|
112 |
-
],
|
113 |
-
outputs="text",
|
114 |
-
title="Audio Transcribe"
|
115 |
-
)
|
116 |
-
|
117 |
-
# SOAP Note generation interface with additional parameters
|
118 |
-
soap_note = gr.Interface(
|
119 |
-
fn=generate_soap,
|
120 |
-
inputs=[
|
121 |
-
gr.Textbox(label="Transcribed Text", lines=10),
|
122 |
-
gr.Textbox(label="System Prompt", lines=2, value="You are a world class clinical assistant."),
|
123 |
-
gr.Slider(label="Max new tokens", minimum=1, maximum=2048, value=1024, step=1),
|
124 |
-
gr.Slider(label="Temperature", minimum=0.1, maximum=4.0, value=0.6, step=0.1),
|
125 |
-
gr.Slider(label="Top-p", minimum=0.05, maximum=1.0, value=0.9, step=0.05),
|
126 |
-
gr.Slider(label="Top-k", minimum=1, maximum=1000, value=50, step=1),
|
127 |
-
gr.Slider(label="Repetition penalty", minimum=1.0, maximum=2.0, value=1.2, step=0.05)
|
128 |
-
],
|
129 |
-
outputs="text",
|
130 |
-
title="Generate Clinical SOAP Note",
|
131 |
-
description="Convert transcribed conversation to a clinical SOAP note with structured sections."
|
132 |
-
)
|
133 |
-
|
134 |
-
# Tabbed interface
|
135 |
with demo:
|
136 |
-
gr.
|
137 |
-
|
138 |
-
|
139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
|
141 |
demo.queue().launch(ssr_mode=False)
|
|
|
1 |
import spaces
|
2 |
import torch
|
3 |
import gradio as gr
|
4 |
+
from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
|
5 |
from threading import Thread
|
6 |
from typing import Iterator
|
7 |
import os
|
|
|
89 |
outputs.append(text)
|
90 |
yield "".join(outputs)
|
91 |
|
92 |
+
# Gradio Interface combining transcription and SOAP note generation
|
93 |
demo = gr.Blocks(theme=gr.themes.Ocean())
|
94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
with demo:
|
96 |
+
with gr.Tab("Clinical SOAP Note from Audio"):
|
97 |
+
audio_transcribe_and_soap = gr.Interface(
|
98 |
+
fn=lambda inputs, task: generate_soap(transcribe(inputs, task)),
|
99 |
+
inputs=[
|
100 |
+
gr.Audio(sources=["microphone", "upload"], type="filepath", label="Audio Input"),
|
101 |
+
gr.Radio(["transcribe", "translate"], label="Task", value="transcribe"),
|
102 |
+
gr.Textbox(label="System Prompt", lines=2, value="You are a world class clinical assistant."),
|
103 |
+
gr.Slider(label="Max new tokens", minimum=1, maximum=2048, value=1024, step=1),
|
104 |
+
gr.Slider(label="Temperature", minimum=0.1, maximum=4.0, value=0.6, step=0.1),
|
105 |
+
gr.Slider(label="Top-p", minimum=0.05, maximum=1.0, value=0.9, step=0.05),
|
106 |
+
gr.Slider(label="Top-k", minimum=1, maximum=1000, value=50, step=1),
|
107 |
+
gr.Slider(label="Repetition penalty", minimum=1.0, maximum=2.0, value=1.2, step=0.05)
|
108 |
+
],
|
109 |
+
outputs="text",
|
110 |
+
title="Generate Clinical SOAP Note from Audio",
|
111 |
+
description="Transcribe audio input and convert it into a structured clinical SOAP note."
|
112 |
+
)
|
113 |
|
114 |
demo.queue().launch(ssr_mode=False)
|