Commit
·
647a796
0
Parent(s):
Initial commit
Browse files- .gitattributes +35 -0
- README.md +45 -0
- app.py +52 -0
- requirements.txt +3 -0
.gitattributes
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Clinical Report Generator
|
| 2 |
+
|
| 3 |
+
This Hugging Face Space provides a clinical report generation service using a fine-tuned T5 model. The model has been trained on a dataset of clinical documents to generate professional, structured clinical reports from input notes.
|
| 4 |
+
|
| 5 |
+
## Features
|
| 6 |
+
|
| 7 |
+
- Generates professional clinical reports from input notes
|
| 8 |
+
- Maintains medical terminology and context
|
| 9 |
+
- Removes unwanted elements like URLs
|
| 10 |
+
- Provides a user-friendly interface
|
| 11 |
+
|
| 12 |
+
## How to Use
|
| 13 |
+
|
| 14 |
+
1. Enter your clinical notes in the input text box
|
| 15 |
+
2. Click "Submit" to generate the report
|
| 16 |
+
3. The generated report will appear in the output text box
|
| 17 |
+
|
| 18 |
+
## Model Details
|
| 19 |
+
|
| 20 |
+
- Base Model: T5-small
|
| 21 |
+
- Fine-tuned on: Clinical documents and structured templates
|
| 22 |
+
- Input Length: Up to 512 tokens
|
| 23 |
+
- Output Length: Up to 256 tokens
|
| 24 |
+
- Special Features:
|
| 25 |
+
- Beam search with 4 beams
|
| 26 |
+
- No repeat ngram size of 3
|
| 27 |
+
- Length penalty of 2.0
|
| 28 |
+
- Early stopping enabled
|
| 29 |
+
- URL filtering
|
| 30 |
+
|
| 31 |
+
## Examples
|
| 32 |
+
|
| 33 |
+
The interface includes example inputs to demonstrate the model's capabilities. These examples cover common clinical scenarios such as:
|
| 34 |
+
- Initial patient presentations
|
| 35 |
+
- Follow-up visits
|
| 36 |
+
- Treatment responses
|
| 37 |
+
|
| 38 |
+
## Notes
|
| 39 |
+
|
| 40 |
+
- The model is designed for generating clinical reports only
|
| 41 |
+
- Input should be clear and contain relevant clinical information
|
| 42 |
+
- Generated reports should be reviewed by healthcare professionals
|
| 43 |
+
|
| 44 |
+
## SDK Version
|
| 45 |
+
sdk_version: 4.12.0
|
app.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import T5Tokenizer, T5ForConditionalGeneration
|
| 3 |
+
|
| 4 |
+
# Load the base T5 model and tokenizer
|
| 5 |
+
model = T5ForConditionalGeneration.from_pretrained('t5-small')
|
| 6 |
+
tokenizer = T5Tokenizer.from_pretrained('t5-small')
|
| 7 |
+
|
| 8 |
+
def generate_clinical_report(input_text):
|
| 9 |
+
"""
|
| 10 |
+
Generate a clinical report from the input text using the fine-tuned T5 model.
|
| 11 |
+
"""
|
| 12 |
+
# Prepare input text
|
| 13 |
+
input_ids = tokenizer.encode("summarize: " + input_text, return_tensors="pt", max_length=512, truncation=True)
|
| 14 |
+
|
| 15 |
+
# Generate report
|
| 16 |
+
outputs = model.generate(
|
| 17 |
+
input_ids,
|
| 18 |
+
max_length=256,
|
| 19 |
+
num_beams=4,
|
| 20 |
+
no_repeat_ngram_size=3,
|
| 21 |
+
length_penalty=2.0,
|
| 22 |
+
early_stopping=True,
|
| 23 |
+
bad_words_ids=[[tokenizer.encode(word, add_special_tokens=False)[0]]
|
| 24 |
+
for word in ['http', 'www', '.com', '.org']]
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
# Decode and return the generated report
|
| 28 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 29 |
+
|
| 30 |
+
# Create Gradio interface
|
| 31 |
+
demo = gr.Interface(
|
| 32 |
+
fn=generate_clinical_report,
|
| 33 |
+
inputs=gr.Textbox(
|
| 34 |
+
lines=8,
|
| 35 |
+
placeholder="Enter clinical notes here...",
|
| 36 |
+
label="Clinical Notes"
|
| 37 |
+
),
|
| 38 |
+
outputs=gr.Textbox(
|
| 39 |
+
lines=8,
|
| 40 |
+
label="Generated Clinical Report"
|
| 41 |
+
),
|
| 42 |
+
title="Clinical Report Generator",
|
| 43 |
+
description="Generate professional clinical reports from clinical notes using a fine-tuned T5 model.",
|
| 44 |
+
examples=[
|
| 45 |
+
["Patient presented with severe abdominal pain in the lower right quadrant. Temperature 38.5°C, BP 130/85."],
|
| 46 |
+
["Follow-up visit for diabetes management. Blood sugar levels have been stable with current medication regimen."]
|
| 47 |
+
]
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
# Launch the app
|
| 51 |
+
if __name__ == "__main__":
|
| 52 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers==4.36.2
|
| 2 |
+
torch>=2.0.0
|
| 3 |
+
gradio==4.12.0
|