alibidaran's picture
Update app.py
8a82af7
raw
history blame
1.12 kB
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
import gradio as gr
device = 'cuda' if torch.cuda.is_available() else 'cpu'
tokenizer = AutoTokenizer.from_pretrained("alibidaran/medical_transcription_generator")
model = AutoModelForCausalLM.from_pretrained("alibidaran/medical_transcription_generator").to(device)
def generate_text(Text,Max_length,Temperature):
torch.manual_seed(32)
tokenizer.pad_token_id=tokenizer.eos_token_id
with torch.no_grad():
input_ids = tokenizer(Text, return_tensors="pt")["input_ids"].to('cpu')
attn_mask=tokenizer(Text, return_tensors="pt")["attention_mask"].to('cpu')
output=model.generate(input_ids=input_ids,attention_mask=attn_mask,max_new_tokens=Max_length,do_sample=True, temperature=Temperature, top_p=0.90,top_k=10)
return tokenizer.decode(output[0])
demo=gr.Interface(
generate_text,
['text',
gr.Slider(50,2000,value=100,step=10),
gr.Slider(0,2,value=0.7,step=0.1)],
'text',
theme=gr.themes.Base(primary_hue='blue',secondary_hue='cyan'),
description="Medical Trasncript Generator"
)
demo.launch()