yeliudev commited on
Commit
655f4ae
·
1 Parent(s): 5d3c3d0

Use lineplot instead of plot

Browse files
Files changed (2) hide show
  1. app.py +12 -16
  2. requirements.txt +1 -1
app.py CHANGED
@@ -7,8 +7,8 @@ import decord
7
  import nncore
8
  import torch
9
  import gradio as gr
10
- import matplotlib.pyplot as plt
11
  import numpy as np
 
12
  import torchvision.transforms.functional as F
13
  from decord import VideoReader
14
  from nncore.engine import load_checkpoint
@@ -59,7 +59,7 @@ def init_model(config, checkpoint):
59
  return model, cfg
60
 
61
 
62
- def main(video, query, model, cfg, fig, ax):
63
  if len(query) == 0:
64
  raise gr.Error('Text query can not be empty.')
65
 
@@ -81,33 +81,29 @@ def main(video, query, model, cfg, fig, ax):
81
 
82
  hd = pred['_out']['saliency'].cpu()
83
  hd = ((hd - hd.min()) / (hd.max() - hd.min())).tolist()
 
84
 
85
- ax.cla()
86
- ax.plot(range(0, len(hd) * 2, 2), hd)
87
-
88
- ax.set_xlabel('Time (s)', fontsize=15)
89
- ax.set_ylabel('Saliency Score', fontsize=15)
90
-
91
- ax.tick_params(labelsize=14)
92
-
93
- return mr, fig
94
 
95
 
96
  model, cfg = init_model(CONFIG, WEIGHT)
97
 
98
- plt.tight_layout(rect=(0.02, 0.05, 0.95, 0.885))
99
- fig, ax = plt.subplots(figsize=(10, 5.5))
100
-
101
  demo = gr.Interface(
102
- fn=partial(main, model=model, cfg=cfg, fig=fig, ax=ax),
103
  inputs=[gr.Video(label='Video'),
104
  gr.Textbox(label='Text Query')],
105
  outputs=[
106
  gr.Dataframe(
107
  headers=['Start Time', 'End Time', 'Score'], label='Moment Retrieval'),
108
- gr.Plot(label='Highlight Detection')
 
 
 
 
 
109
  ],
110
  allow_flagging='never',
111
  title=TITLE,
112
  description=DESCRIPTION)
 
113
  demo.launch()
 
7
  import nncore
8
  import torch
9
  import gradio as gr
 
10
  import numpy as np
11
+ import pandas as pd
12
  import torchvision.transforms.functional as F
13
  from decord import VideoReader
14
  from nncore.engine import load_checkpoint
 
59
  return model, cfg
60
 
61
 
62
+ def main(video, query, model, cfg):
63
  if len(query) == 0:
64
  raise gr.Error('Text query can not be empty.')
65
 
 
81
 
82
  hd = pred['_out']['saliency'].cpu()
83
  hd = ((hd - hd.min()) / (hd.max() - hd.min())).tolist()
84
+ hd = pd.DataFrame(dict(x=range(0, len(hd) * 2, 2), y=hd))
85
 
86
+ return mr, hd
 
 
 
 
 
 
 
 
87
 
88
 
89
  model, cfg = init_model(CONFIG, WEIGHT)
90
 
 
 
 
91
  demo = gr.Interface(
92
+ fn=partial(main, model=model, cfg=cfg),
93
  inputs=[gr.Video(label='Video'),
94
  gr.Textbox(label='Text Query')],
95
  outputs=[
96
  gr.Dataframe(
97
  headers=['Start Time', 'End Time', 'Score'], label='Moment Retrieval'),
98
+ gr.LinePlot(
99
+ x='x',
100
+ y='y',
101
+ x_title='Time (seconds)',
102
+ y_title='Saliency Score',
103
+ label='Highlight Detection')
104
  ],
105
  allow_flagging='never',
106
  title=TITLE,
107
  description=DESCRIPTION)
108
+
109
  demo.launch()
requirements.txt CHANGED
@@ -1,6 +1,6 @@
1
  git+https://github.com/openai/CLIP.git@a1d0717
2
  decord==0.6.0
3
- matplotlib==3.9.0
4
  nncore==0.4.4
 
5
  torch==2.2.1
6
  torchvision==0.17.1
 
1
  git+https://github.com/openai/CLIP.git@a1d0717
2
  decord==0.6.0
 
3
  nncore==0.4.4
4
+ pandas==2.2.2
5
  torch==2.2.1
6
  torchvision==0.17.1