# Run the script and open the link in the browser. import os import gradio as gr import streamlit as st import torch from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline # scratch with latbert tokenizer CHECKPOINT_PATH= 'scratch_2-nodes_tokenizer_latbert-original_packing_fcocchi/model.safetensors' CHECKPOINT_PATH= 'itserr/latin_llm_alpha' print(f"Loading model from: {CHECKPOINT_PATH}") tokenizer = AutoTokenizer.from_pretrained(CHECKPOINT_PATH, token=os.environ['HF_TOKEN']) model = AutoModelForCausalLM.from_pretrained(CHECKPOINT_PATH, token=os.environ['HF_TOKEN']) description=""" This is a Latin Language Model (LLM) based on GPT-2 and it was trained on a large corpus of Latin texts and can generate text in Latin. Please enter a prompt in Latin to generate text. """ title= "(L3) - Latin Large Language Model" article= "hello world ..." examples= ['Accidere ex una scintilla', 'Audacter calumniare,', 'Consolatium misero comites'] logo_image= 'ITSERR_row_logo.png' def generate_text(prompt): if torch.cuda.is_available(): device = torch.device("cuda") else: device = torch.device("cpu") print("No GPU available") print("***** Generate *****") text_generator = pipeline("text-generation", model=model, tokenizer=tokenizer, device=device) generated_text = text_generator(prompt, max_length=50, do_sample=True, temperature=1.0, repetition_penalty=2.0, truncation=True) return generated_text[0]['generated_text'] custom_css = """ #logo { display: block; margin-left: auto; margin-right: auto; width: 512px; height: 256px; } """ with gr.Blocks(css=custom_css) as demo: gr.Markdown(f"