Spaces:
Sleeping
Sleeping
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) | |