cstr commited on
Commit
7dc7c8e
·
verified ·
1 Parent(s): c193dfd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -13
app.py CHANGED
@@ -28,6 +28,8 @@ MODEL_INFO: Dict[str, Tuple[str, str, str]] = {
28
  "grc-perseus-sm": ("Ancient Greek (Perseus SM)", "grc_perseus_sm", "grecy"),
29
  }
30
 
 
 
31
  UI_TEXT = {
32
  "de": {
33
  "title": "# 🔍 Mehrsprachiger Morpho-Syntaktischer Analysator",
@@ -41,11 +43,12 @@ UI_TEXT = {
41
  "tab_graphic": "Grafische Darstellung",
42
  "tab_table": "Tabelle",
43
  "tab_json": "JSON",
44
- "tab_ner": "Entitäten", # <-- ADDED
45
  "html_label": "Abhängigkeitsparsing",
46
  "table_label": "Morphologische Analyse",
 
47
  "json_label": "JSON-Ausgabe",
48
- "ner_label": "Benannte Entitäten", # <-- ADDED
49
  "error_message": "Fehler: "
50
  },
51
  "en": {
@@ -60,11 +63,12 @@ UI_TEXT = {
60
  "tab_graphic": "Graphic View",
61
  "tab_table": "Table",
62
  "tab_json": "JSON",
63
- "tab_ner": "Entities", # <-- ADDED
64
  "html_label": "Dependency Parsing",
65
  "table_label": "Morphological Analysis",
 
66
  "json_label": "JSON Output",
67
- "ner_label": "Named Entities", # <-- ADDED
68
  "error_message": "Error: "
69
  },
70
  "es": {
@@ -79,14 +83,16 @@ UI_TEXT = {
79
  "tab_graphic": "Vista Gráfica",
80
  "tab_table": "Tabla",
81
  "tab_json": "JSON",
82
- "tab_ner": "Entidades", # <-- ADDED
83
  "html_label": "Análisis de Dependencias",
84
  "table_label": "Análisis Morfológico",
 
85
  "json_label": "Salida JSON",
86
- "ner_label": "Entidades Nombradas", # <-- ADDED
87
  "error_message": "Error: "
88
  }
89
  }
 
90
 
91
  MODELS: Dict[str, Optional[spacy.Language]] = {}
92
 
@@ -124,9 +130,9 @@ def install_grecy_model_from_github(model_name: str) -> bool:
124
 
125
  if model_name == "grc_proiel_trf":
126
  wheel_filename = "grc_proiel_trf-3.7.5-py3-none-any.whl"
127
- # --- UPDATED: Added grc_ner_trf to this list ---
128
  elif model_name in ["grc_perseus_trf", "grc_proiel_lg", "grc_perseus_lg",
129
  "grc_proiel_sm", "grc_perseus_sm", "grc_ner_trf"]:
 
130
  wheel_filename = f"{model_name}-0.0.0-py3-none-any.whl"
131
  else:
132
  print(f"✗ Unknown grecy model: {model_name}")
@@ -329,11 +335,11 @@ def update_ui(ui_lang: str):
329
  gr.Tab(label=ui_config["tab_graphic"]),
330
  gr.Tab(label=ui_config["tab_table"]),
331
  gr.Tab(label=ui_config["tab_json"]),
332
- gr.Tab(label=ui_config["tab_ner"]), # <-- ADDED
333
  gr.HTML(label=ui_config["html_label"]),
334
  gr.DataFrame(label=ui_config["table_label"], headers=ui_config["table_headers"], interactive=False),
335
  gr.JSON(label=ui_config["json_label"]),
336
- gr.HTML(label=ui_config["ner_label"]) # <-- ADDED
337
  ]
338
 
339
  def create_interface():
@@ -358,22 +364,19 @@ def create_interface():
358
  with gr.Tabs():
359
  with gr.Tab(config["tab_graphic"]) as tab_graphic:
360
  html_dep_out = gr.HTML(label=config["html_label"])
361
- # --- ADDED NEW TAB ---
362
  with gr.Tab(config["tab_ner"]) as tab_ner:
363
  html_ner_out = gr.HTML(label=config["ner_label"])
364
- # --- END ADDITION ---
365
  with gr.Tab(config["tab_table"]) as tab_table:
 
366
  df_out = gr.DataFrame(label=config["table_label"], headers=config["table_headers"], interactive=False)
367
  with gr.Tab(config["tab_json"]) as tab_json:
368
  json_out = gr.JSON(label=config["json_label"])
369
 
370
- # --- UPDATED OUTPUTS ---
371
  analyze_button.click(fn=get_analysis,
372
  inputs=[ui_lang_radio, model_lang_radio, text_input],
373
  outputs=[df_out, json_out, html_dep_out, html_ner_out, analyze_button],
374
  api_name="get_morphology")
375
 
376
- # --- UPDATED OUTPUTS ---
377
  ui_lang_radio.change(fn=update_ui,
378
  inputs=ui_lang_radio,
379
  outputs=[markdown_title, markdown_subtitle, ui_lang_radio, model_lang_radio,
 
28
  "grc-perseus-sm": ("Ancient Greek (Perseus SM)", "grc_perseus_sm", "grecy"),
29
  }
30
 
31
+ # --- *** THE FIX IS HERE *** ---
32
+ # Added the 'table_headers' key to each language
33
  UI_TEXT = {
34
  "de": {
35
  "title": "# 🔍 Mehrsprachiger Morpho-Syntaktischer Analysator",
 
43
  "tab_graphic": "Grafische Darstellung",
44
  "tab_table": "Tabelle",
45
  "tab_json": "JSON",
46
+ "tab_ner": "Entitäten",
47
  "html_label": "Abhängigkeitsparsing",
48
  "table_label": "Morphologische Analyse",
49
+ "table_headers": ["Wort", "Lemma", "POS", "Tag", "Morphologie", "Abhängigkeit"], # <-- WAS MISSING
50
  "json_label": "JSON-Ausgabe",
51
+ "ner_label": "Benannte Entitäten",
52
  "error_message": "Fehler: "
53
  },
54
  "en": {
 
63
  "tab_graphic": "Graphic View",
64
  "tab_table": "Table",
65
  "tab_json": "JSON",
66
+ "tab_ner": "Entities",
67
  "html_label": "Dependency Parsing",
68
  "table_label": "Morphological Analysis",
69
+ "table_headers": ["Word", "Lemma", "POS", "Tag", "Morphology", "Dependency"], # <-- WAS MISSING
70
  "json_label": "JSON Output",
71
+ "ner_label": "Named Entities",
72
  "error_message": "Error: "
73
  },
74
  "es": {
 
83
  "tab_graphic": "Vista Gráfica",
84
  "tab_table": "Tabla",
85
  "tab_json": "JSON",
86
+ "tab_ner": "Entidades",
87
  "html_label": "Análisis de Dependencias",
88
  "table_label": "Análisis Morfológico",
89
+ "table_headers": ["Palabra", "Lema", "POS", "Etiqueta", "Morfología", "Dependencia"], # <-- WAS MISSING
90
  "json_label": "Salida JSON",
91
+ "ner_label": "Entidades Nombradas",
92
  "error_message": "Error: "
93
  }
94
  }
95
+ # --- *** END FIX *** ---
96
 
97
  MODELS: Dict[str, Optional[spacy.Language]] = {}
98
 
 
130
 
131
  if model_name == "grc_proiel_trf":
132
  wheel_filename = "grc_proiel_trf-3.7.5-py3-none-any.whl"
 
133
  elif model_name in ["grc_perseus_trf", "grc_proiel_lg", "grc_perseus_lg",
134
  "grc_proiel_sm", "grc_perseus_sm", "grc_ner_trf"]:
135
+ # Note: Wheel name uses underscore (grc_ner_trf), not hyphen
136
  wheel_filename = f"{model_name}-0.0.0-py3-none-any.whl"
137
  else:
138
  print(f"✗ Unknown grecy model: {model_name}")
 
335
  gr.Tab(label=ui_config["tab_graphic"]),
336
  gr.Tab(label=ui_config["tab_table"]),
337
  gr.Tab(label=ui_config["tab_json"]),
338
+ gr.Tab(label=ui_config["tab_ner"]),
339
  gr.HTML(label=ui_config["html_label"]),
340
  gr.DataFrame(label=ui_config["table_label"], headers=ui_config["table_headers"], interactive=False),
341
  gr.JSON(label=ui_config["json_label"]),
342
+ gr.HTML(label=ui_config["ner_label"])
343
  ]
344
 
345
  def create_interface():
 
364
  with gr.Tabs():
365
  with gr.Tab(config["tab_graphic"]) as tab_graphic:
366
  html_dep_out = gr.HTML(label=config["html_label"])
 
367
  with gr.Tab(config["tab_ner"]) as tab_ner:
368
  html_ner_out = gr.HTML(label=config["ner_label"])
 
369
  with gr.Tab(config["tab_table"]) as tab_table:
370
+ # This is the line that was crashing
371
  df_out = gr.DataFrame(label=config["table_label"], headers=config["table_headers"], interactive=False)
372
  with gr.Tab(config["tab_json"]) as tab_json:
373
  json_out = gr.JSON(label=config["json_label"])
374
 
 
375
  analyze_button.click(fn=get_analysis,
376
  inputs=[ui_lang_radio, model_lang_radio, text_input],
377
  outputs=[df_out, json_out, html_dep_out, html_ner_out, analyze_button],
378
  api_name="get_morphology")
379
 
 
380
  ui_lang_radio.change(fn=update_ui,
381
  inputs=ui_lang_radio,
382
  outputs=[markdown_title, markdown_subtitle, ui_lang_radio, model_lang_radio,