import gradio as gr from peft import PeftModel, PeftConfig from transformers import AutoModelForCausalLM, AutoTokenizer import torch if torch.cuda.is_available(): device = torch.device("cuda") print("GPU is available!") else: device = torch.device("cpu") print("GPU is not available, using CPU.") # Load the model and config when the script starts peft_model_id = "phearion/bigbrain-v0.0.1" config = PeftConfig.from_pretrained(peft_model_id) model = AutoModelForCausalLM.from_pretrained(config.base_model_name_or_path) tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path) # Load the Lora model model = PeftModel.from_pretrained(model, peft_model_id) def greet(text): batch = tokenizer("“aide moi avec les equa diff ” ->: ", return_tensors='pt') with torch.cuda.amp.autocast(): output_tokens = model.generate(**batch, max_new_tokens=15) return tokenizer.decode(output_tokens[0], skip_special_tokens=True) iface = gr.Interface(fn=greet, inputs="text", outputs="text") iface.launch()