Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -26,22 +26,31 @@ st.sidebar.image("logo-wordlift.png")
|
|
| 26 |
language_options = {"English", "German"}
|
| 27 |
selected_language = st.sidebar.selectbox("Select the Language", list(language_options))
|
| 28 |
|
| 29 |
-
#
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
@st.cache_resource # ๐ Add the caching decorator
|
| 38 |
-
def load_model(model_name, entity_set):
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
# Use the cached model
|
| 44 |
-
|
| 45 |
|
| 46 |
# Addi citation
|
| 47 |
citation = """
|
|
@@ -75,17 +84,13 @@ with st.form(key='my_form'):
|
|
| 75 |
text_input = st.text_area(label='Enter a sentence')
|
| 76 |
submit_button = st.form_submit_button(label='Analyze')
|
| 77 |
|
|
|
|
| 78 |
if text_input:
|
| 79 |
if selected_language == "German":
|
| 80 |
-
doc_de =
|
| 81 |
-
entities = [(ent.text, ent.label_
|
| 82 |
-
# You will have to adjust the rest of the code since the format is different
|
| 83 |
-
# For the demo, we'll simply print them for now
|
| 84 |
-
for entity in entities:
|
| 85 |
-
st.write(entity)
|
| 86 |
|
| 87 |
else:
|
| 88 |
-
entities = refined_model.process_text(text_input)
|
| 89 |
|
| 90 |
entities = refined_model.process_text(text_input)
|
| 91 |
|
|
|
|
| 26 |
language_options = {"English", "German"}
|
| 27 |
selected_language = st.sidebar.selectbox("Select the Language", list(language_options))
|
| 28 |
|
| 29 |
+
# Based on selected language, display model and entity set options
|
| 30 |
+
if selected_language != "German":
|
| 31 |
+
# Only show these options for languages other than German
|
| 32 |
+
model_options = {"aida_model", "wikipedia_model_with_numbers"}
|
| 33 |
+
selected_model_name = st.sidebar.selectbox("Select the Model", list(model_options))
|
| 34 |
+
# Select entity_set
|
| 35 |
+
entity_set_options = {"wikidata", "wikipedia"}
|
| 36 |
+
selected_entity_set = st.sidebar.selectbox("Select the Entity Set", list(entity_set_options))
|
| 37 |
+
else:
|
| 38 |
+
selected_model_name = None
|
| 39 |
+
selected_entity_set = None
|
| 40 |
|
| 41 |
@st.cache_resource # ๐ Add the caching decorator
|
| 42 |
+
def load_model(selected_language, model_name=None, entity_set=None):
|
| 43 |
+
if selected_language == "German":
|
| 44 |
+
# Load the German-specific model
|
| 45 |
+
nlp_model_de = spacy.load("de_core_news_sm")
|
| 46 |
+
return nlp_model_de
|
| 47 |
+
else:
|
| 48 |
+
# Load the pretrained model for other languages
|
| 49 |
+
refined_model = Refined.from_pretrained(model_name=model_name, entity_set=entity_set)
|
| 50 |
+
return refined_model
|
| 51 |
|
| 52 |
# Use the cached model
|
| 53 |
+
model = load_model(selected_language, selected_model_name, selected_entity_set)
|
| 54 |
|
| 55 |
# Addi citation
|
| 56 |
citation = """
|
|
|
|
| 84 |
text_input = st.text_area(label='Enter a sentence')
|
| 85 |
submit_button = st.form_submit_button(label='Analyze')
|
| 86 |
|
| 87 |
+
# When processing the text, check the language and adjust processing accordingly
|
| 88 |
if text_input:
|
| 89 |
if selected_language == "German":
|
| 90 |
+
doc_de = model(text_input)
|
| 91 |
+
entities = [(ent.text, ent.label_) for ent in doc_de.ents] # Adjust this based on your needs
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
else:
|
|
|
|
| 94 |
|
| 95 |
entities = refined_model.process_text(text_input)
|
| 96 |
|