Ajouter le script Gradio et les dépendances
Browse files
app.py
CHANGED
@@ -1,29 +1,29 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import laion_clap
|
3 |
-
from qdrant_client import QdrantClient
|
4 |
import os
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
|
10 |
-
#
|
11 |
-
client = QdrantClient(
|
12 |
print("[INFO] Client created...")
|
13 |
|
14 |
-
#
|
15 |
print("[INFO] Loading the model...")
|
16 |
-
model_name = "laion/
|
17 |
-
model =
|
18 |
-
|
19 |
|
20 |
-
# Interface
|
21 |
max_results = 10
|
22 |
|
|
|
23 |
def sound_search(query):
|
24 |
-
|
|
|
|
|
25 |
hits = client.search(
|
26 |
-
collection_name="
|
27 |
query_vector=text_embed,
|
28 |
limit=max_results,
|
29 |
)
|
@@ -34,12 +34,13 @@ def sound_search(query):
|
|
34 |
for hit in hits
|
35 |
]
|
36 |
|
|
|
37 |
with gr.Blocks() as demo:
|
38 |
gr.Markdown(
|
39 |
"""# Sound search database """
|
40 |
)
|
41 |
inp = gr.Textbox(placeholder="What sound are you looking for ?")
|
42 |
-
out = [gr.Audio(label=f"{x}") for x in range(max_results)] #
|
43 |
inp.change(sound_search, inp, out)
|
44 |
|
45 |
demo.launch()
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
|
3 |
+
import gradio as gr
|
4 |
+
from qdrant_client import QdrantClient
|
5 |
+
from transformers import ClapModel, ClapProcessor
|
6 |
|
7 |
+
# Loading the Qdrant DB in local ###################################################################
|
8 |
+
client = QdrantClient("https://ebe79742-e3ac-4d09-a2c6-63946024cc7a.us-east4-0.gcp.cloud.qdrant.io", api_key="_NnGLuSMH4Qwv-ancoFh88YvzuR7WbyidAorVOVQ_eMCbPhxTb2TSw")
|
9 |
print("[INFO] Client created...")
|
10 |
|
11 |
+
# loading the model
|
12 |
print("[INFO] Loading the model...")
|
13 |
+
model_name = "laion/larger_clap_general"
|
14 |
+
model = ClapModel.from_pretrained(model_name)
|
15 |
+
processor = ClapProcessor.from_pretrained(model_name)
|
16 |
|
17 |
+
# Gradio Interface #################################################################################
|
18 |
max_results = 10
|
19 |
|
20 |
+
|
21 |
def sound_search(query):
|
22 |
+
text_inputs = processor(text=query, return_tensors="pt")
|
23 |
+
text_embed = model.get_text_features(**text_inputs)[0]
|
24 |
+
|
25 |
hits = client.search(
|
26 |
+
collection_name="demo_spaces_db",
|
27 |
query_vector=text_embed,
|
28 |
limit=max_results,
|
29 |
)
|
|
|
34 |
for hit in hits
|
35 |
]
|
36 |
|
37 |
+
|
38 |
with gr.Blocks() as demo:
|
39 |
gr.Markdown(
|
40 |
"""# Sound search database """
|
41 |
)
|
42 |
inp = gr.Textbox(placeholder="What sound are you looking for ?")
|
43 |
+
out = [gr.Audio(label=f"{x}") for x in range(max_results)] # Necessary to have different objs
|
44 |
inp.change(sound_search, inp, out)
|
45 |
|
46 |
demo.launch()
|