Imsachinsingh00 commited on
Commit
b3d97d5
·
1 Parent(s): 586b493

initial commit

Browse files
Files changed (2) hide show
  1. app.py +33 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from transformers import BertTokenizer, EncoderDecoderModel, pipeline
4
+
5
+ # Load model and tokenizer
6
+ model = EncoderDecoderModel.from_pretrained("imsachinsingh00/bert2bert-mts-summary")
7
+ tokenizer = BertTokenizer.from_pretrained("imsachinsingh00/bert2bert-mts-summary")
8
+
9
+ # Move to CUDA if available
10
+ device = "cuda" if torch.cuda.is_available() else "cpu"
11
+ model.to(device)
12
+
13
+ # Summarization function
14
+ def summarize_dialogue(dialogue):
15
+ inputs = tokenizer(dialogue, return_tensors="pt", padding=True, truncation=True, max_length=512).to(device)
16
+ summary_ids = model.generate(inputs.input_ids, max_length=64, num_beams=4, early_stopping=True)
17
+ summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
18
+ return summary
19
+
20
+ # Gradio interface
21
+ demo = gr.Interface(
22
+ fn=summarize_dialogue,
23
+ inputs=[
24
+ gr.Textbox(lines=10, label="Doctor-Patient Dialogue"),
25
+ gr.Audio(source="microphone", type="filepath", optional=True)
26
+ ],
27
+ outputs="text",
28
+ title="Medical Dialogue Summarizer",
29
+ description="Enter or speak a conversation. The model will summarize it."
30
+ )
31
+
32
+ if __name__ == "__main__":
33
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ transformers
2
+ datasets
3
+ evaluate
4
+ rouge_score
5
+ torch