Spaces:
Sleeping
Sleeping
File size: 856 Bytes
1f0c25c 3466a8f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import streamlit as st
from transformers import pipeline
from transformers import AutoModelWithLMHead, AutoTokenizer
import torch
tokenizer = AutoTokenizer.from_pretrained("flan-alpaca-base")
model = AutoModelWithLMHead.from_pretrained("flan-alpaca-base")
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
print("Is cuda available:", torch.cuda.is_available())
model = model.to(device)
text = st.text_area("Enter your text:")
if text:
# model = pipeline(model="flan-alpaca-xl")
#model(prompt, max_length=128, do_sample=True)
input_text = "question: %s " % (text)
features = tokenizer([input_text], return_tensors='pt')
out = model.generate(input_ids=features['input_ids'].to(device), attention_mask=features['attention_mask'].to(device))
if tokenizer.decode(out[0]):
st.write(tokenizer.decode(out[0])) |