| import gradio as gr | |
| # import torch | |
| # from peft import PeftModel, PeftConfig | |
| # from transformers import AutoModelForCausalLM, AutoTokenizer | |
| # peft_model_id = "hackathon-somos-nlp-2023/bertin-gpt-j-6b-ner-es" | |
| # config = PeftConfig.from_pretrained(peft_model_id) | |
| # model = AutoModelForCausalLM.from_pretrained( | |
| # "DavidFM43/bertin-gpt-j-6b-half-sharded", | |
| # return_dict=True, | |
| # load_in_8bit=True, | |
| # device_map="auto", | |
| # ) | |
| # tokenizer = AutoTokenizer.from_pretrained(peft_model_id) | |
| # # load the Lora model | |
| # model = PeftModel.from_pretrained(model, peft_model_id) | |
| # model.eval() | |
| def gen_entities(text): | |
| """Does Named Entity Recognition in the given text.""" | |
| # text = f"<SP> text: {text}\n\n entities:" | |
| # batch = tokenizer(text, return_tensors="pt") | |
| # batch["input_ids"] = batch["input_ids"].to("cuda") | |
| # with torch.cuda.amp.autocast(): | |
| # output_tokens = model.generate(**batch, max_new_tokens=256, eos_token_id=50258) | |
| # response = tokenizer.batch_decode(output_tokens.detach().cpu().numpy(), skip_special_tokens=False)[0] | |
| # return response[response.find("entities") : response.find("<EP>")] | |
| return "" | |
| iface = gr.Interface( | |
| fn=gen_entities, | |
| inputs="text", | |
| outputs="text", | |
| title="Podcast Named Entity Recognition", | |
| description="Introduce un texto corto para que el modelo identifique las identidades presentes en el mismo.", | |
| theme="gradio/monochrome", | |
| 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.", | |
| "Victoria del Reino Unido (Alxandrina Victoria; Londres, 24 de mayo " | |
| "de 1819-isla de Wight, 22 de enero de 1901) fue la reina del Reino Unido.", | |
| "El viaje de Chihiro es una película de animación japonesa estrenada " | |
| " el 20 de julio de 2001. Fue dirigida por Hayao Miyazaki y producida en el Studio Ghibli", | |
| ], | |
| article=open("article.txt").read(), | |
| cache_examples=False | |
| ) | |
| iface.launch() | |