Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -35,7 +35,7 @@ footer {
|
|
35 |
}
|
36 |
'''
|
37 |
|
38 |
-
global_instruction = "You will analyze video,
|
39 |
|
40 |
input_prefixes = {
|
41 |
"Image": "Analyze the '█' image.",
|
@@ -52,14 +52,12 @@ filetypes = {
|
|
52 |
}
|
53 |
|
54 |
# Functions
|
55 |
-
|
56 |
-
step = max(len(seq) // n, 1)
|
57 |
-
return seq[::step][:n]
|
58 |
|
59 |
def build_video(path):
|
60 |
vr = VideoReader(path, ctx = cpu(0))
|
61 |
-
|
62 |
-
batch = vr.get_batch(
|
63 |
frames = [Image.fromarray(frame.astype("uint8")) for frame in batch]
|
64 |
|
65 |
audio = build_audio(path)
|
@@ -83,10 +81,10 @@ def build_image(path):
|
|
83 |
return image
|
84 |
|
85 |
def build_gif(path):
|
86 |
-
|
87 |
-
|
88 |
-
frames =
|
89 |
-
return frames
|
90 |
|
91 |
def build_audio(path):
|
92 |
audio, _ = librosa.load(path, sr=AUDIO_SR, mono=True)
|
@@ -142,7 +140,7 @@ with gr.Blocks(css=css) as main:
|
|
142 |
with gr.Column():
|
143 |
input = gr.File(label="Input", file_types=["image", "video", "audio"], type="filepath")
|
144 |
instruction = gr.Textbox(lines=1, value=DEFAULT_INPUT, label="Instruction")
|
145 |
-
sampling = gr.Checkbox(value=
|
146 |
temperature = gr.Slider(minimum=0, maximum=2, step=0.01, value=1, label="Temperature")
|
147 |
top_p = gr.Slider(minimum=0, maximum=1, step=0.01, value=0.95, label="Top P")
|
148 |
top_k = gr.Slider(minimum=0, maximum=1000, step=1, value=50, label="Top K")
|
|
|
35 |
}
|
36 |
'''
|
37 |
|
38 |
+
global_instruction = "You will analyze image, GIF, video, and audio input, then use as much keywords to describe the given content and take as much guesses of what it could be."
|
39 |
|
40 |
input_prefixes = {
|
41 |
"Image": "Analyze the '█' image.",
|
|
|
52 |
}
|
53 |
|
54 |
# Functions
|
55 |
+
uniform_sample=lambda seq, n: seq[::max(len(seq) // n,1)][:n]
|
|
|
|
|
56 |
|
57 |
def build_video(path):
|
58 |
vr = VideoReader(path, ctx = cpu(0))
|
59 |
+
i = uniform_sample(range(len(vr)), MAX_FRAMES)
|
60 |
+
batch = vr.get_batch(i).asnumpy()
|
61 |
frames = [Image.fromarray(frame.astype("uint8")) for frame in batch]
|
62 |
|
63 |
audio = build_audio(path)
|
|
|
81 |
return image
|
82 |
|
83 |
def build_gif(path):
|
84 |
+
vr = VideoReader(path, ctx=cpu(0))
|
85 |
+
i = uniform_sample(range(len(vr)), MAX_FRAMES)
|
86 |
+
frames = vr.get_batch(i).asnumpy()
|
87 |
+
return [Image.fromarray(f.astype("uint8")) for f in frames]
|
88 |
|
89 |
def build_audio(path):
|
90 |
audio, _ = librosa.load(path, sr=AUDIO_SR, mono=True)
|
|
|
140 |
with gr.Column():
|
141 |
input = gr.File(label="Input", file_types=["image", "video", "audio"], type="filepath")
|
142 |
instruction = gr.Textbox(lines=1, value=DEFAULT_INPUT, label="Instruction")
|
143 |
+
sampling = gr.Checkbox(value=False, label="Sampling")
|
144 |
temperature = gr.Slider(minimum=0, maximum=2, step=0.01, value=1, label="Temperature")
|
145 |
top_p = gr.Slider(minimum=0, maximum=1, step=0.01, value=0.95, label="Top P")
|
146 |
top_k = gr.Slider(minimum=0, maximum=1000, step=1, value=50, label="Top K")
|