Spaces:
Runtime error
Runtime error
import streamlit as st | |
import time | |
from transformers import pipeline | |
import torch | |
#from transformers import AutoModelForCausalLM, AutoTokenizer | |
#@st.cache(allow_output_mutation=True) | |
#def define_model(): | |
# model = AutoModelForCausalLM.from_pretrained("facebook/opt-1.3b", torch_dtype=torch.float16).cuda() | |
# tokenizer = AutoTokenizer.from_pretrained("facebook/opt-1.3b", use_fast=False) | |
# return model, tokenizer | |
generator = pipeline('text-generation', model="facebook/opt-1.3b", skip_special_tokens=True) | |
#@st.cache(allow_output_mutation=True) | |
#def opt_model(prompt, model, tokenizer, num_sequences = 1, max_length = 50): | |
# 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 | |
#model, tokenizer = define_model() | |
prompt= st.text_area('Your prompt here', | |
'''Hello, I'm am conscious and''') | |
answer = generator(prompt, max_length=60,no_repeat_ngram_size=2, early_stopping=True, num_beams=5) | |
#answer = opt_model(prompt, model, tokenizer,) | |
#lst = ['ciao come stai sjfsbd dfhsdf fuahfuf feuhfu wefwu '] | |
#answer = define_model(prompt) | |
lst = answer[0]['generated_text'] | |
t = st.empty() | |
for i in range(len(lst)): | |
t.markdown(" %s..." % lst[0:i]) | |
time.sleep(0.04) |