File size: 985 Bytes
396b713
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import torch 
from transformers import AutoTokenizer, AutoModelForCausalLM
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')
    output=model.generate(input_ids,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()