Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +35 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
ner_pipeline = pipeline(model="projecte-aina/roberta-base-ca-v2-cased-ner")
|
| 5 |
+
|
| 6 |
+
exemples = ["El Joan no ha anat mai a Manresa"]
|
| 7 |
+
|
| 8 |
+
def ner(text):
|
| 9 |
+
output = ner_pipeline(text)
|
| 10 |
+
return {"text": text, "entities": output}
|
| 11 |
+
|
| 12 |
+
def neteja():
|
| 13 |
+
return [gr.Textbox(value=None), gr.HighlightedText(value=None)]
|
| 14 |
+
|
| 15 |
+
with gr.Blocks(theme=gr.themes.Glass()) as demo:
|
| 16 |
+
gr.Markdown(
|
| 17 |
+
"""
|
| 18 |
+
# Reconeixament d'entitats nomenades en català
|
| 19 |
+
Escriu o copia un text i troba les seves entitats
|
| 20 |
+
""")
|
| 21 |
+
with gr.Row():
|
| 22 |
+
with gr.Column():
|
| 23 |
+
inp = gr.Textbox(label="text", placeholder="Escriu aquí...")
|
| 24 |
+
with gr.Row():
|
| 25 |
+
b1 = gr.Button(value="Neteja")
|
| 26 |
+
b2 = gr.Button("Troba entitats", variant="primary")
|
| 27 |
+
out = gr.HighlightedText(label="sortida")
|
| 28 |
+
|
| 29 |
+
examples = gr.Examples(examples=exemples, inputs=inp, label="Exemple:")
|
| 30 |
+
logout_button = gr.Button("Logout", link="/logout")
|
| 31 |
+
|
| 32 |
+
b1.click(neteja, outputs=[inp, out])
|
| 33 |
+
b2.click(ner, inputs=inp, outputs=out)
|
| 34 |
+
|
| 35 |
+
demo.launch(show_api=False, auth=("admin", "admin"))
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
transformers
|
| 3 |
+
torch
|