Spaces:
Runtime error
Runtime error
Commit
·
76ceb1a
1
Parent(s):
93951fe
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from transformers import BioGptTokenizer, BioGptForCausalLM, set_seed
|
3 |
+
|
4 |
+
tokenizer = BioGptTokenizer.from_pretrained("microsoft/biogpt")
|
5 |
+
model = BioGptForCausalLM.from_pretrained("microsoft/biogpt")
|
6 |
+
|
7 |
+
sentence = "COVID-19 is"
|
8 |
+
|
9 |
+
|
10 |
+
set_seed(42)
|
11 |
+
|
12 |
+
def get_beam_output(sentence):
|
13 |
+
inputs = tokenizer(sentence, return_tensors="pt")
|
14 |
+
with torch.no_grad():
|
15 |
+
beam_output = model.generate(**inputs,
|
16 |
+
min_length=100,
|
17 |
+
max_length=1024,
|
18 |
+
num_beams=5,
|
19 |
+
early_stopping=True
|
20 |
+
)
|
21 |
+
tokenizer.decode(beam_output[0], skip_special_tokens=True)
|
22 |
+
|
23 |
+
|
24 |
+
demo = gr.Interface(fn=get_beam_output, inputs="text", outputs="text")
|
25 |
+
demo.launch()
|