Spaces:
Sleeping
Sleeping
| from transformers import pipeline | |
| import gradio as gr | |
| USERNAME = "admin" | |
| PASSWORD = "admin" | |
| def login(user, pwd): | |
| return user == USERNAME and pwd == PASSWORD | |
| # --- PIPELINE --- | |
| ner_pipeline = pipeline(model="projecte-aina/roberta-base-ca-v2-cased-ner") | |
| def ner(text): | |
| output = ner_pipeline(text) | |
| return {"text": text, "entities": output} | |
| def neteja(): | |
| return gr.update(value=""), gr.update(value=None) | |
| # --- APP --- | |
| with gr.Blocks(theme=gr.themes.Glass()) as demo: | |
| # ---------- LOGIN ---------- | |
| with gr.Group(visible=True) as login_group: | |
| gr.Markdown("## Inici de sessió") | |
| user = gr.Textbox(label="Usuari") | |
| pwd = gr.Textbox(label="Contrasenya", type="password") | |
| b3 = gr.Button("Entrar") | |
| # ---------- APLICACIÓ PRINCIPAL ---------- | |
| with gr.Group(visible=False) as app_group: | |
| gr.Markdown( | |
| """ | |
| # Reconeixement d'entitats nomenades en català | |
| Escriu o copia un text i troba les seves entitats | |
| """) | |
| with gr.Row(): | |
| with gr.Column(): | |
| inp = gr.Textbox(label="text", placeholder="Escriu aquí...") | |
| with gr.Row(): | |
| b1 = gr.Button(value="Neteja") | |
| b2 = gr.Button("Troba entitats", variant="primary") | |
| out = gr.HighlightedText(label="sortida") | |
| # Accions de la app | |
| b1.click(neteja, outputs=[inp, out]) | |
| b2.click(ner, inputs=inp, outputs=out) | |
| # ---------- LÒGICA DEL LOGIN ---------- | |
| def auth_button(u, p): | |
| if login(u, p): | |
| return gr.update(visible=False), gr.update(visible=True) | |
| else: | |
| return gr.update(), gr.update() | |
| b3.click(auth_button, inputs=[user, pwd], outputs=[login_group, app_group]) | |
| demo.launch() |