llm-ie 0.2.1__py3-none-any.whl → 0.2.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
llm_ie/data_types.py CHANGED
@@ -1,4 +1,4 @@
1
- from typing import List, Dict, Iterable, Callable
1
+ from typing import List, Dict, Tuple, Iterable, Callable
2
2
  import importlib.util
3
3
  import json
4
4
 
@@ -283,15 +283,12 @@ class LLMInformationExtractionDocument:
283
283
  json_file.flush()
284
284
 
285
285
 
286
- def serve_viz(self, host: str = '0.0.0.0', port: int = 3000, theme:str = "light",
287
- color_attr_key:str=None, color_map_func:Callable=None):
286
+ def _viz_preprocess(self) -> Tuple:
288
287
  """
289
- This method serves a visualization of the document.
288
+ This method preprocesses the entities and relations for visualization.
290
289
  """
291
290
  if importlib.util.find_spec("ie_viz") is None:
292
291
  raise ImportError("ie_viz not found. Please install ie_viz (```pip install ie-viz```).")
293
-
294
- from ie_viz import serve
295
292
 
296
293
  if self.has_frame():
297
294
  entities = [{"entity_id": frame.frame_id, "start": frame.start, "end": frame.end, "attr": frame.attr} for frame in self.frames]
@@ -306,6 +303,31 @@ class LLMInformationExtractionDocument:
306
303
  else:
307
304
  relations = None
308
305
 
306
+ return entities, relations
307
+
308
+
309
+ def viz_serve(self, host: str = '0.0.0.0', port: int = 5000, theme:str = "light",
310
+ color_attr_key:str=None, color_map_func:Callable=None):
311
+ """
312
+ This method serves a visualization App of the document.
313
+
314
+ Parameters:
315
+ -----------
316
+ host : str, Optional
317
+ The host address to run the server on.
318
+ port : int, Optional
319
+ The port number to run the server on.
320
+ theme : str, Optional
321
+ The theme of the visualization. Must be either "light" or "dark".
322
+ color_attr_key : str, Optional
323
+ The attribute key to be used for coloring the entities.
324
+ color_map_func : Callable, Optional
325
+ The function to be used for mapping the entity attributes to colors. When provided, the color_attr_key and
326
+ theme will be overwritten. The function must take an entity dictionary as input and return a color string (hex).
327
+ """
328
+ entities, relations = self._viz_preprocess()
329
+ from ie_viz import serve
330
+
309
331
  serve(text=self.text,
310
332
  entities=entities,
311
333
  relations=relations,
@@ -314,4 +336,28 @@ class LLMInformationExtractionDocument:
314
336
  theme=theme,
315
337
  color_attr_key=color_attr_key,
316
338
  color_map_func=color_map_func)
317
-
339
+
340
+
341
+ def viz_render(self, theme:str = "light", color_attr_key:str=None, color_map_func:Callable=None) -> str:
342
+ """
343
+ This method renders visualization html of the document.
344
+
345
+ Parameters:
346
+ -----------
347
+ theme : str, Optional
348
+ The theme of the visualization. Must be either "light" or "dark".
349
+ color_attr_key : str, Optional
350
+ The attribute key to be used for coloring the entities.
351
+ color_map_func : Callable, Optional
352
+ The function to be used for mapping the entity attributes to colors. When provided, the color_attr_key and
353
+ theme will be overwritten. The function must take an entity dictionary as input and return a color string (hex).
354
+ """
355
+ entities, relations = self._viz_preprocess()
356
+ from ie_viz import render
357
+
358
+ return render(text=self.text,
359
+ entities=entities,
360
+ relations=relations,
361
+ theme=theme,
362
+ color_attr_key=color_attr_key,
363
+ color_map_func=color_map_func)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: llm-ie
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: An LLM-powered tool that transforms everyday language into robust information extraction pipelines.
5
5
  License: MIT
6
6
  Author: Enshuo (David) Hsu
@@ -6,10 +6,10 @@ llm_ie/asset/prompt_guide/BinaryRelationExtractor_prompt_guide.txt,sha256=z9Xg0f
6
6
  llm_ie/asset/prompt_guide/MultiClassRelationExtractor_prompt_guide.txt,sha256=D5DphUHw8SUERUVdcIjUynuTmYJa6-PwBlF7FzxNsvQ,2276
7
7
  llm_ie/asset/prompt_guide/ReviewFrameExtractor_prompt_guide.txt,sha256=XbnU8byLGGUA3A3lT0bb2Hw-ggzhcqD3ZuKzduod2ww,1944
8
8
  llm_ie/asset/prompt_guide/SentenceFrameExtractor_prompt_guide.txt,sha256=8nj9OLPJMtr9Soi5JU3Xk-HC7pKNoI54xA_A4u7I5j4,2620
9
- llm_ie/data_types.py,sha256=zAUx-n1ePTTg1aFrml0lTZPreJx241YTeWFCprRoYbU,12245
9
+ llm_ie/data_types.py,sha256=hPz3WOeAzfn2QKmb0CxHmRdQWZQ4G9zq8U-RJBVFdYk,14329
10
10
  llm_ie/engines.py,sha256=m9ytGUX61jEy9SmVHbb90mrfGMAwC6dV-v7Jke1U7Ho,9296
11
11
  llm_ie/extractors.py,sha256=EVuHqW1lW0RpGmnRNmX4ih6ppfvy2gYOAOgc8Pngfkw,44103
12
12
  llm_ie/prompt_editor.py,sha256=dbu7A3O7O7Iw2v-xCgrTFH1-wTLAGf4SHDqdeS-He2Q,1869
13
- llm_ie-0.2.1.dist-info/METADATA,sha256=JOjW83QHlj-rgp09upos2-XvhvvnROBeOoX4U33AZKU,40052
14
- llm_ie-0.2.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
15
- llm_ie-0.2.1.dist-info/RECORD,,
13
+ llm_ie-0.2.2.dist-info/METADATA,sha256=V7gi1wZN_FlaW2ZfdsGKtEGi2s-AjIvssrkjjd7ubWU,40052
14
+ llm_ie-0.2.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
15
+ llm_ie-0.2.2.dist-info/RECORD,,
File without changes