Spaces:
Sleeping
Sleeping
File size: 1,606 Bytes
620e2d6 8c37033 620e2d6 7dfc6cc 620e2d6 cddbd4e 620e2d6 041809e 620e2d6 8c37033 041809e 8c37033 620e2d6 8c37033 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
import gradio as gr
import torch
from transformers import pipeline, AutoTokenizer, AutoModelForSeq2SeqLM
# Load model and tokenizer explicitly
model_name = "sazzadul/bangla-med-sum"
tokenizer = AutoTokenizer.from_pretrained(model_name, src_lang="bn_IN")
model = AutoModelForSeq2SeqLM.from_pretrained(
model_name,
device_map="auto"
# low_cpu_mem_usage=True
)
summarizer = pipeline(
"summarization",
model=model,
tokenizer=tokenizer
)
def summarize_text(text):
try:
if not text.strip():
return "আপনার রোগ অথবা সমস্যা সম্পর্কে বিস্তারিত বলুন : "
summary = summarizer(
text,
max_length=256,
min_length=30,
truncation=True,
# Directly pass forced_bos_token_id here
forced_bos_token_id=tokenizer.lang_code_to_id["bn_IN"]
)[0]['summary_text']
return summary
except Exception as e:
return f"Error during summarization: {str(e)}"
iface = gr.Interface(
fn=summarize_text,
inputs=gr.Textbox(lines=5, label="রোগীর সমস্যার বিবরণ (বাংলায়)"),
outputs=gr.Textbox(lines=5, label="সারাংশ"),
title="Bangla Medical Problem Summary Generation",
description="Provide a detailed description of the patient or treatment-related question or problem and get a concise and clear summary",
allow_flagging="never"
)
if __name__ == "__main__":
iface.launch(server_name="0.0.0.0", server_port=7860)
|