PodcastNER / app.py
sergiopperez's picture
Update app.py
9e24f6f
raw
history blame
1.34 kB
import gradio as gr
import torch
from transformers import pipeline, GPTJForCausalLM, AutoModelForCausalLM
from peft import LoraConfig, get_peft_model, PeftModel, PeftConfig
config = PeftConfig.from_pretrained("hackathon-somos-nlp-2023/bertin-gpt-j-6b-ner-es")
model = AutoModelForCausalLM.from_pretrained("hackathon-somos-nlp-2023/bertin-gpt-j-6b-ner-es", return_dict=True, load_in_8bit=True, device_map='auto')
# # load fp 16 model
# model = GPTJForCausalLM.from_pretrained("models/hackathon-somos-nlp-2023/bertin-gpt-j-6b-ner-es")
# config = AutoConfig.from_pretrained("hackathon-somos-nlp-2023/bertin-gpt-j-6b-ner-es", name_or_path="adapter_model.bin")
# load tokenizer
tokenizer = AutoTokenizer.from_pretrained("hackathon-somos-nlp-2023/bertin-gpt-j-6b-ner-es")
# Load the Lora model
model = PeftModel.from_pretrained(model, "hackathon-somos-nlp-2023/bertin-gpt-j-6b-ner-es")
# create pipeline
pipe = pipeline("text-generation", model=model, config=config, tokenizer=tokenizer, device=0,)
def predict(text):
return pipe(f"text: {text}, entities:")["generated_text"]
iface = gr.Interface(
fn=predict,
inputs='text',
outputs='text',
examples=[["Yo hoy voy a hablar de mujeres en el mundo del arte, porque me ha leΓ­do un libro fantΓ‘stico que se llama Historia del arte sin hombres, de Katie Hesel."]]
)
iface.launch()