asahi417 commited on
Commit
3bd9346
1 Parent(s): 377ebdf

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +2 -2
  2. app.py +7 -28
  3. requirements.txt +1 -0
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
  title: CLIP Interrogator
3
  emoji: 🕵️‍♂️
4
- colorFrom: green
5
- colorTo: purple
6
  sdk: gradio
7
  sdk_version: 4.8.0
8
  app_file: app.py
 
1
  ---
2
  title: CLIP Interrogator
3
  emoji: 🕵️‍♂️
4
+ colorFrom: blue
5
+ colorTo: red
6
  sdk: gradio
7
  sdk_version: 4.8.0
8
  app_file: app.py
app.py CHANGED
@@ -1,16 +1,8 @@
1
  import spaces
2
- import torch
3
  import gradio as gr
4
- from clip_interrogator import Config, Interrogator
5
 
6
-
7
- config = Config()
8
- config.device = 'cuda' if torch.cuda.is_available() else 'cpu'
9
- config.blip_offload = False if torch.cuda.is_available() else True
10
- config.chunk_size = 2048
11
- config.flavor_intermediate_count = 512
12
- config.blip_num_beams = 64
13
- ci = Interrogator(config)
14
  css = """
15
  #col-container {
16
  margin: 0 auto;
@@ -20,31 +12,18 @@ css = """
20
 
21
 
22
  @spaces.GPU
23
- def infer(image, mode, best_max_flavors):
24
  image = image.convert('RGB')
25
- if mode == 'best':
26
- prompt_result = ci.interrogate(image, max_flavors=int(best_max_flavors))
27
- elif mode == 'classic':
28
- prompt_result = ci.interrogate_classic(image)
29
- else:
30
- prompt_result = ci.interrogate_fast(image)
31
- return prompt_result
32
 
33
 
34
  with gr.Blocks(css=css) as demo:
35
  with gr.Column(elem_id="col-container"):
36
  gr.Markdown("# CLIP Interrogator")
37
- input_image = gr.Image(type='pil', elem_id="input-img")
38
  with gr.Row():
39
- mode_input = gr.Radio(['best', 'classic', 'fast'], label='Select mode', value='best')
40
  flavor_input = gr.Slider(minimum=2, maximum=48, step=2, value=32, label='best mode max flavors')
41
  run_button = gr.Button("Submit")
42
  output_text = gr.Textbox(label="Description Output")
43
- run_button.click(
44
- fn=infer,
45
- inputs=[input_image, mode_input, flavor_input],
46
- outputs=[output_text],
47
- concurrency_limit=10
48
- )
49
-
50
- demo.queue().launch()
 
1
  import spaces
 
2
  import gradio as gr
3
+ from panna import CLIPInterrogator
4
 
5
+ model = CLIPInterrogator()
 
 
 
 
 
 
 
6
  css = """
7
  #col-container {
8
  margin: 0 auto;
 
12
 
13
 
14
  @spaces.GPU
15
+ def infer(image, best_max_flavors):
16
  image = image.convert('RGB')
17
+ return model.image2text([image], best_max_flavors=best_max_flavors)[0]
 
 
 
 
 
 
18
 
19
 
20
  with gr.Blocks(css=css) as demo:
21
  with gr.Column(elem_id="col-container"):
22
  gr.Markdown("# CLIP Interrogator")
23
+ input_image = gr.Image(type='pil')
24
  with gr.Row():
 
25
  flavor_input = gr.Slider(minimum=2, maximum=48, step=2, value=32, label='best mode max flavors')
26
  run_button = gr.Button("Submit")
27
  output_text = gr.Textbox(label="Description Output")
28
+ run_button.click(fn=infer, inputs=[input_image, flavor_input], outputs=[output_text], concurrency_limit=10)
29
+ demo.launch()
 
 
 
 
 
 
requirements.txt CHANGED
@@ -3,3 +3,4 @@ torch
3
  torchvision
4
  spaces
5
  clip-interrogator
 
 
3
  torchvision
4
  spaces
5
  clip-interrogator
6
+ panna