import gradio as gr from transformers import pipeline from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("facebook/galactica-125m") model = AutoModelForCausalLM.from_pretrained("facebook/galactica-125m") text2text_generator = pipeline("text-generation", model=model, tokenizer=tokenizer, num_workers=2) def predict(text, max_length=64, temperature=0.7, do_sample=True): text = text.strip() out_text = text2text_generator(text, max_length=max_length, temperature=temperature, do_sample=do_sample, eos_token_id = tokenizer.eos_token_id, bos_token_id = tokenizer.bos_token_id, pad_token_id = tokenizer.pad_token_id, )[0]['generated_text'] out_text = "
" + out_text + "
" out_text = out_text.replace(text, text + "") out_text = out_text + "" out_text = out_text.replace("\n", "