alibidaran
commited on
Commit
•
396b713
1
Parent(s):
2530a27
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
+
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
4 |
+
tokenizer = AutoTokenizer.from_pretrained("alibidaran/medical_transcription_generator")
|
5 |
+
|
6 |
+
model = AutoModelForCausalLM.from_pretrained("alibidaran/medical_transcription_generator").to(device)
|
7 |
+
def generate_text(Text,Max_length,Temperature):
|
8 |
+
torch.manual_seed(32)
|
9 |
+
tokenizer.pad_token_id=tokenizer.eos_token_id
|
10 |
+
with torch.no_grad():
|
11 |
+
input_ids = tokenizer(Text, return_tensors="pt")["input_ids"].to('cpu')
|
12 |
+
output=model.generate(input_ids,max_new_tokens=Max_length,do_sample=True, temperature=Temperature, top_p=0.90,top_k=10)
|
13 |
+
return tokenizer.decode(output[0])
|
14 |
+
demo=gr.Interface(
|
15 |
+
generate_text,
|
16 |
+
['text',
|
17 |
+
gr.Slider(50,2000,value=100,step=10),
|
18 |
+
gr.Slider(0,2,value=0.7,step=0.1)],
|
19 |
+
'text',
|
20 |
+
theme=gr.themes.Base(primary_hue='blue',secondary_hue='cyan'),
|
21 |
+
description="Medical Trasncript Generator"
|
22 |
+
)
|
23 |
+
demo.launch()
|