Spaces:
Runtime error
Runtime error
import transformers | |
import streamlit as st | |
from transformers import AutoTokenizer, AutoModelForCausalLM | |
tokenizer = AutoTokenizer.from_pretrained("VietAI/gpt-neo-1.3B-vietnamese-news") | |
def load_model(model_name): | |
model = AutoModelForCausalLM.from_pretrained(model_name) | |
return model | |
model = load_model("VietAI/gpt-neo-1.3B-vietnamese-news") | |
def infer(input_ids, max_length): | |
output_sequences = model.generate( | |
input_ids=input_ids, | |
max_length=max_length, | |
do_sample=True, | |
temperature=0.9, | |
top_k=20, | |
#top_p=top_p, | |
#num_return_sequences=1 | |
) | |
return output_sequences | |
default_value = "Tiềm năng của trí tuệ nhân tạo" | |
st.title("Vietnamese Text Generation With Transformers") | |
st.write("This app generates Vietnamese text based on a given prompt. To change the parameters of the generated text, adjust the slider on the left and click Generate Text again.") | |
st.write("It might be a bit slow after you change the generated text length. Be patient!") | |
sent = st.text_area("Text", default_value, height = 275) | |
max_length = st.sidebar.slider("Max Length", min_value = 10, max_value=500) | |
# We don't really need these params. It's a lot slower. | |
# temperature = st.sidebar.slider("Temperature", value = 1.0, min_value = 0.0, max_value=1.0, step=0.05) | |
# top_k = st.sidebar.slider("Top-k", min_value = 0, max_value=5, value = 0) | |
# top_p = st.sidebar.slider("Top-p", min_value = 0.0, max_value=1.0, step = 0.05, value = 0.9) | |
if st.button("Generate Text"): | |
with st.spinner("Working Hard..."): | |
encoded_prompt = tokenizer.encode(sent, add_special_tokens=False, return_tensors="pt") | |
if encoded_prompt.size()[-1] == 0: | |
input_ids = None | |
else: | |
input_ids = encoded_prompt | |
gen_tokens = infer(encoded_prompt, max_length) | |
gen_text = tokenizer.batch_decode(gen_tokens)[0] | |
st.write(gen_text) | |
st.success("Done!") | |
st.write("For feedback/requests, write to [email protected].") |