Spaces:
Sleeping
Sleeping
added app and req
Browse files- app.py +50 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import spacy
|
2 |
+
import gradio as gr
|
3 |
+
from spacy import displacy
|
4 |
+
|
5 |
+
# Load your trained spaCy model
|
6 |
+
nlp = spacy.load("sr_Spacy_Serbian_Model_SrpKor4Tagging_BERTICOVO")
|
7 |
+
|
8 |
+
# Define a function to display the tags and lemmas
|
9 |
+
def display_tags_and_lemmas(text):
|
10 |
+
doc = nlp(text)
|
11 |
+
html = displacy.render(doc, style="ent", page=True, minify=True)
|
12 |
+
|
13 |
+
# We'll also create a custom HTML to display lemmas nicely
|
14 |
+
lemma_html = "<div class='lemma-display'><table class='table table-hover'>"
|
15 |
+
lemma_html += "<thead><tr><th>Token</th><th>Lemma</th><th>POS Tag</th></tr></thead><tbody>"
|
16 |
+
|
17 |
+
for token in doc:
|
18 |
+
lemma_html += f"<tr><td>{token.text}</td><td>{token.lemma_}</td><td>{token.pos_}</td></tr>"
|
19 |
+
|
20 |
+
lemma_html += "</tbody></table></div>"
|
21 |
+
|
22 |
+
# Return both the displaCy HTML and our custom lemma table
|
23 |
+
return html, lemma_html
|
24 |
+
|
25 |
+
# Define Gradio interface
|
26 |
+
iface = gr.Interface(
|
27 |
+
fn=display_tags_and_lemmas,
|
28 |
+
inputs=gr.inputs.Textbox(lines=5, placeholder="Unesite rečenicu ovde..."),
|
29 |
+
outputs=[
|
30 |
+
gr.outputs.HTML(label="Leme i POS oznake")
|
31 |
+
],
|
32 |
+
title="spaCy Tagger i Lemmatizer",
|
33 |
+
description="Unesite rečenicu da biste videli njene imenovane entitete, POS oznake i leme.",
|
34 |
+
examples=["Lep dan, danas."]
|
35 |
+
)
|
36 |
+
|
37 |
+
|
38 |
+
# Include CSS styling for nicer outputs
|
39 |
+
css = """
|
40 |
+
<style>
|
41 |
+
.lemma-display { margin: auto; width: 50%; }
|
42 |
+
.table { font-family: Arial, Helvetica, sans-serif; border-collapse: collapse; width: 100%; }
|
43 |
+
.table td, .table th { border: 1px solid #ddd; padding: 8px; }
|
44 |
+
.table tr:nth-child(even){ background-color: #f2f2f2; }
|
45 |
+
.table tr:hover { background-color: #ddd; }
|
46 |
+
.table th { padding-top: 12px; padding-bottom: 12px; text-align: left; background-color: #04AA6D; color: white; }
|
47 |
+
</style>
|
48 |
+
"""
|
49 |
+
|
50 |
+
iface.launch(inline=False, enable_queue=True, share=True, css=css)
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
spacy==3.0.0 # Replace with the version you used for training and packaging your model
|
2 |
+
gradio==2.0.0 # Replace with your used version
|
3 |
+
https://huggingface.co/Tanor/sr_Spacy_Serbian_Model_SrpKor4Tagging_BERTICOVO/resolve/main/sr_Spacy_Serbian_Model_SrpKor4Tagging_BERTICOVO-any-py3-none-any.whl
|