TYH71 commited on
Commit
0ad27ae
·
1 Parent(s): b6bdd8f

refactor: clip interface

Browse files
Files changed (1) hide show
  1. src/interface/clip.py +25 -10
src/interface/clip.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  # libraries
2
  from typing import List, Dict
3
  import gradio as gr
@@ -10,19 +12,32 @@ from src.model.clip import CLIP_Model
10
  MODEL = CLIP_Model()
11
 
12
  def clean_text(text: str) -> List[str]:
13
- """function to clean gradio input text, remove the trailing and leading spaces"""
 
 
 
 
 
 
 
14
  return list(map(lambda x: x.strip(), text.split(",")))
15
 
16
  def clip_demo_fn(image: Image.Image, text: str) -> Dict[str, float]:
17
- try:
18
- logger.info("demo function invoked")
19
- text = clean_text(text)
20
- logger.debug("clean text: %s", text)
21
- return MODEL(image, text)
22
- except Exception as error_msg:
23
- logger.error("Error caught: %s", error_msg)
24
- finally:
25
- logger.info("demo function completed")
 
 
 
 
 
 
26
 
27
  demo_interface = gr.Interface(
28
  fn=clip_demo_fn,
 
1
+ """CLIP interface module"""
2
+
3
  # libraries
4
  from typing import List, Dict
5
  import gradio as gr
 
12
  MODEL = CLIP_Model()
13
 
14
  def clean_text(text: str) -> List[str]:
15
+ """function to clean gradio input text
16
+
17
+ Args:
18
+ text (str): string of comma separated text
19
+
20
+ Returns:
21
+ List[str]: list of cleaned text
22
+ """
23
  return list(map(lambda x: x.strip(), text.split(",")))
24
 
25
  def clip_demo_fn(image: Image.Image, text: str) -> Dict[str, float]:
26
+ """demo function for gradio interface
27
+
28
+ Args:
29
+ image (Image.Image): expects PIL image_
30
+ text (str): string of comma separated text
31
+
32
+ Returns:
33
+ Dict[str, float]: dictionary of text classes and its associated probability
34
+ """
35
+ logger.info("demo function invoked")
36
+ text = clean_text(text)
37
+ logger.debug("clean text: %s", text)
38
+ yield MODEL(image, text)
39
+ logger.info("demo function completed")
40
+ return
41
 
42
  demo_interface = gr.Interface(
43
  fn=clip_demo_fn,