Update app.py
Browse files
app.py
CHANGED
|
@@ -57,49 +57,6 @@ def similarity_search(query, search_type, num_results, progress=gr.Progress()):
|
|
| 57 |
|
| 58 |
return [row['frame'] for row in results]
|
| 59 |
|
| 60 |
-
# Process video and create index
|
| 61 |
-
def process_video(video_file, progress=gr.Progress()):
|
| 62 |
-
|
| 63 |
-
progress(0, desc="Initializing...")
|
| 64 |
-
|
| 65 |
-
# Pixeltable setup
|
| 66 |
-
pxt.drop_dir('video_search', force=True)
|
| 67 |
-
pxt.create_dir('video_search')
|
| 68 |
-
|
| 69 |
-
video_table = pxt.create_table('video_search.videos', {'video': pxt.VideoType()})
|
| 70 |
-
|
| 71 |
-
frames_view = pxt.create_view(
|
| 72 |
-
'video_search.frames',
|
| 73 |
-
video_table,
|
| 74 |
-
iterator=FrameIterator.create(video=video_table.video, fps=1)
|
| 75 |
-
)
|
| 76 |
-
|
| 77 |
-
progress(0.2, desc="Inserting video...")
|
| 78 |
-
video_table.insert([{'video': video_file.name}])
|
| 79 |
-
|
| 80 |
-
progress(0.4, desc="Creating embedding index...")
|
| 81 |
-
frames_view.add_embedding_index('frame', string_embed=str_embed, image_embed=embed_image)
|
| 82 |
-
|
| 83 |
-
progress(1.0, desc="Processing complete")
|
| 84 |
-
return "Video processed and indexed successfully!"
|
| 85 |
-
|
| 86 |
-
# Perform similarity search
|
| 87 |
-
def similarity_search(query, search_type, num_results, progress=gr.Progress()):
|
| 88 |
-
|
| 89 |
-
frames_view = pxt.get_table('video_search.frames')
|
| 90 |
-
|
| 91 |
-
progress(0.5, desc="Performing search...")
|
| 92 |
-
if search_type == "Text":
|
| 93 |
-
sim = frames_view.frame.similarity(query)
|
| 94 |
-
else: # Image search
|
| 95 |
-
sim = frames_view.frame.similarity(query)
|
| 96 |
-
|
| 97 |
-
results = frames_view.order_by(sim, asc=False).limit(num_results).select(frames_view.frame, sim=sim).collect()
|
| 98 |
-
|
| 99 |
-
progress(1.0, desc="Search complete")
|
| 100 |
-
|
| 101 |
-
return [row['frame'] for row in results]
|
| 102 |
-
|
| 103 |
# Gradio interface
|
| 104 |
with gr.Blocks(theme=gr.themes.Base()) as demo:
|
| 105 |
gr.Markdown(
|
|
|
|
| 57 |
|
| 58 |
return [row['frame'] for row in results]
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
# Gradio interface
|
| 61 |
with gr.Blocks(theme=gr.themes.Base()) as demo:
|
| 62 |
gr.Markdown(
|