File size: 2,068 Bytes
178c5c2
4ca3c57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178c5c2
678fb1e
e8b6316
678fb1e
e8b6316
4ca3c57
 
 
 
 
178c5c2
4ca3c57
678fb1e
4ca3c57
 
5bc7c1a
fe4bf72
478d286
 
 
 
 
 
 
 
e8b6316
 
 
 
 
 
 
478d286
4ca3c57
6f6de56
478d286
5bc7c1a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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()