Spaces:
Runtime error
Runtime error
import streamlit as st | |
import time | |
from datetime import datetime | |
from transformers import AutoModelForCausalLM, AutoTokenizer | |
import torch | |
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) |