Prgckwb commited on
Commit
ca79346
1 Parent(s): fc973c2

Add progress bar and catch error

Browse files
Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -12,13 +12,16 @@ os.environ['TOKENIZERS_PARALLELISM'] = "false"
12
  def inference(
13
  text="",
14
  model_id="openai/clip-vit-large-patch14",
15
- ) -> (list[str, str], pd.DataFrame):
 
16
  if text == "":
17
- return [], pd.DataFrame()
18
 
 
19
  tokenizer = AutoTokenizer.from_pretrained(model_id)
20
 
21
  # Use tokenizer to tokenize the text
 
22
  text_inputs = tokenizer(text, return_tensors='pt')
23
 
24
  input_ids = text_inputs['input_ids'].tolist()[0] # Convert tensor to list
@@ -88,4 +91,4 @@ if __name__ == '__main__':
88
  allow_flagging="never",
89
 
90
  )
91
- iface.launch()
 
12
  def inference(
13
  text="",
14
  model_id="openai/clip-vit-large-patch14",
15
+ progress=gr.Progress()
16
+ ) -> (list[str, str], list[str, str], pd.DataFrame):
17
  if text == "":
18
+ return [], [], pd.DataFrame()
19
 
20
+ progress(0, desc='Loading tokenizer...')
21
  tokenizer = AutoTokenizer.from_pretrained(model_id)
22
 
23
  # Use tokenizer to tokenize the text
24
+ progress(0.5, desc='Tokenizing text...')
25
  text_inputs = tokenizer(text, return_tensors='pt')
26
 
27
  input_ids = text_inputs['input_ids'].tolist()[0] # Convert tensor to list
 
91
  allow_flagging="never",
92
 
93
  )
94
+ iface.queue().launch()