Spaces:
Sleeping
Sleeping
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])) |