Spaces:
Paused
Paused
Commit
·
9891731
1
Parent(s):
c724c5d
Use model
Browse files- app.py +60 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
|
4 |
+
# Load model directly from your Hugging Face repository
|
5 |
+
def load_model():
|
6 |
+
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained("omi-health/sum-small", trust_remote_code=False)
|
8 |
+
model = AutoModelForCausalLM.from_pretrained("omi-health/sum-small", trust_remote_code=False)
|
9 |
+
|
10 |
+
return model, tokenizer
|
11 |
+
return model, tokenizer
|
12 |
+
|
13 |
+
# Function to generate SOAP notes
|
14 |
+
def generate_soap_note(doctor_patient_conversation):
|
15 |
+
if not doctor_patient_conversation.strip():
|
16 |
+
return "Please enter a doctor-patient conversation."
|
17 |
+
|
18 |
+
# Tokenize and generate
|
19 |
+
inputs = tokenizer(doctor_patient_conversation, return_tensors="pt")
|
20 |
+
|
21 |
+
generate_ids = model.generate(inputs.input_ids, max_length=200, num_beams=5, no_repeat_ngram_size=2, early_stopping=True)
|
22 |
+
|
23 |
+
|
24 |
+
# Decode and extract the response part
|
25 |
+
return tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
26 |
+
|
27 |
+
# Load model and tokenizer (this will run once when the app starts)
|
28 |
+
model, tokenizer = load_model()
|
29 |
+
|
30 |
+
# Sample conversation for the example
|
31 |
+
sample_conversation = """
|
32 |
+
Doctor: Good morning, how are you feeling today?
|
33 |
+
Patient: Not so great, doctor. I've had this persistent cough for about two weeks now.
|
34 |
+
Doctor: I'm sorry to hear that. Can you tell me more about the cough? Is it dry or are you coughing up anything?
|
35 |
+
Patient: It started as a dry cough, but for the past few days I've been coughing up some yellowish phlegm.
|
36 |
+
Doctor: Do you have any other symptoms like fever, chills, or shortness of breath?
|
37 |
+
Patient: I had a fever of 100.5°F two days ago. I've been feeling more tired than usual, and sometimes it's a bit hard to catch my breath after coughing a lot.
|
38 |
+
"""
|
39 |
+
|
40 |
+
# Create Gradio interface
|
41 |
+
demo = gr.Interface(
|
42 |
+
fn=generate_soap_note,
|
43 |
+
inputs=gr.Textbox(
|
44 |
+
lines=15,
|
45 |
+
placeholder="Enter doctor-patient conversation here...",
|
46 |
+
label="Doctor-Patient Conversation",
|
47 |
+
value=sample_conversation
|
48 |
+
),
|
49 |
+
outputs=gr.Textbox(
|
50 |
+
label="Generated SOAP Note",
|
51 |
+
lines=15
|
52 |
+
),
|
53 |
+
title="Medical SOAP Note Generator",
|
54 |
+
description="Enter a doctor-patient conversation to generate a structured SOAP note using OMI Health's task-specific model.",
|
55 |
+
examples=[[sample_conversation]],
|
56 |
+
allow_flagging="never"
|
57 |
+
)
|
58 |
+
|
59 |
+
# Launch the app
|
60 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
--extra-index-url https://download.pytorch.org/whl/cu113
|
2 |
+
torch
|
3 |
+
transformers>=4.36.0
|
4 |
+
gradio>=3.50.0
|