Ajouter le script Gradio et les dépendances*
Browse files
app.py
CHANGED
|
@@ -2,22 +2,26 @@ import os
|
|
| 2 |
import gradio as gr
|
| 3 |
from qdrant_client import QdrantClient
|
| 4 |
from transformers import ClapModel, ClapProcessor
|
| 5 |
-
import huggingface_hub
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
model_name = "laion/clap-large-v2"
|
| 17 |
model = ClapModel.from_pretrained(model_name)
|
| 18 |
processor = ClapProcessor.from_pretrained(model_name)
|
| 19 |
|
| 20 |
-
#
|
| 21 |
max_results = 10
|
| 22 |
|
| 23 |
def sound_search(query):
|
|
@@ -26,7 +30,7 @@ def sound_search(query):
|
|
| 26 |
|
| 27 |
hits = client.search(
|
| 28 |
collection_name="demo_spaces_db",
|
| 29 |
-
query_vector=text_embed.tolist(), #
|
| 30 |
limit=max_results,
|
| 31 |
)
|
| 32 |
return [
|
|
@@ -38,10 +42,10 @@ def sound_search(query):
|
|
| 38 |
|
| 39 |
with gr.Blocks() as demo:
|
| 40 |
gr.Markdown(
|
| 41 |
-
"""#
|
| 42 |
)
|
| 43 |
-
inp = gr.Textbox(placeholder="
|
| 44 |
-
out = [gr.Audio(label=f"{x}") for x in range(max_results)] #
|
| 45 |
inp.change(fn=sound_search, inputs=inp, outputs=out)
|
| 46 |
|
| 47 |
demo.launch()
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from qdrant_client import QdrantClient
|
| 4 |
from transformers import ClapModel, ClapProcessor
|
|
|
|
| 5 |
|
| 6 |
+
# Utiliser les secrets définis comme variables d'environnement
|
| 7 |
+
qdrant_url = os.getenv("QDRANT_URL")
|
| 8 |
+
qdrant_key = os.getenv("QDRANT_KEY")
|
| 9 |
|
| 10 |
+
if not qdrant_url or not qdrant_key:
|
| 11 |
+
raise ValueError("QDRANT_URL and QDRANT_KEY must be set as environment variables.")
|
| 12 |
|
| 13 |
+
client = QdrantClient(qdrant_url, qdrant_key)
|
| 14 |
+
|
| 15 |
+
# Chargement de la base de données Qdrant en local
|
| 16 |
+
print("[INFO] Client créé...")
|
| 17 |
+
|
| 18 |
+
# Chargement du modèle
|
| 19 |
+
print("[INFO] Chargement du modèle...")
|
| 20 |
model_name = "laion/clap-large-v2"
|
| 21 |
model = ClapModel.from_pretrained(model_name)
|
| 22 |
processor = ClapProcessor.from_pretrained(model_name)
|
| 23 |
|
| 24 |
+
# Interface Gradio
|
| 25 |
max_results = 10
|
| 26 |
|
| 27 |
def sound_search(query):
|
|
|
|
| 30 |
|
| 31 |
hits = client.search(
|
| 32 |
collection_name="demo_spaces_db",
|
| 33 |
+
query_vector=text_embed.tolist(), # Convertir le tenseur en liste
|
| 34 |
limit=max_results,
|
| 35 |
)
|
| 36 |
return [
|
|
|
|
| 42 |
|
| 43 |
with gr.Blocks() as demo:
|
| 44 |
gr.Markdown(
|
| 45 |
+
"""# Base de données de recherche de sons """
|
| 46 |
)
|
| 47 |
+
inp = gr.Textbox(placeholder="Quel son recherchez-vous ?")
|
| 48 |
+
out = [gr.Audio(label=f"{x}") for x in range(max_results)] # Nécessaire d'avoir des objets différents
|
| 49 |
inp.change(fn=sound_search, inputs=inp, outputs=out)
|
| 50 |
|
| 51 |
demo.launch()
|