Spaces:
Runtime error
Runtime error
File size: 990 Bytes
7d5081f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import streamlit as st
import time
from datetime import datetime
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
@st.cache(allow_output_mutation=True)
def opt_model(prompt, num_sequences = 1, max_length = 50):
model = AutoModelForCausalLM.from_pretrained("facebook/opt-30b", torch_dtype=torch.float16).cuda()
tokenizer = AutoTokenizer.from_pretrained("facebook/opt-30b", use_fast=False)
input_ids = tokenizer(prompt, return_tensors="pt").input_ids.cuda()
generated_ids = model.generate(input_ids, num_return_sequences=num_sequences, max_length=max_length)
answer = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
return answer
prompt= st.text_area('Your prompt here',
'''Hello, I'm am conscious and''')
answer = opt_model(prompt)
#lst = ['ciao come stai sjfsbd dfhsdf fuahfuf feuhfu wefwu ']
lst = ' '.join(answer)
t = st.empty()
for i in range(len(lst)):
t.markdown("### %s..." % lst[0:i])
time.sleep(0.04) |