Spaces:
Runtime error
Runtime error
fixes
Browse files- app.py +1 -1
- downloader.py +64 -88
app.py
CHANGED
@@ -3,7 +3,7 @@ import lancedb.embeddings.imagebind
|
|
3 |
from lancedb.embeddings import get_registry
|
4 |
from lancedb.pydantic import LanceModel, Vector
|
5 |
import gradio as gr
|
6 |
-
from downloader import dowload_and_save_audio, dowload_and_save_image, base_path
|
7 |
|
8 |
model = get_registry().get("imagebind").create()
|
9 |
|
|
|
3 |
from lancedb.embeddings import get_registry
|
4 |
from lancedb.pydantic import LanceModel, Vector
|
5 |
import gradio as gr
|
6 |
+
from .downloader import dowload_and_save_audio, dowload_and_save_image, base_path
|
7 |
|
8 |
model = get_registry().get("imagebind").create()
|
9 |
|
downloader.py
CHANGED
@@ -1,90 +1,66 @@
|
|
1 |
-
import
|
2 |
-
import
|
3 |
-
from
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
vector: Vector(model.ndims()) = model.VectorField()
|
16 |
-
|
17 |
-
|
18 |
-
text_list = ["A bird", "A dragon", "A car"]
|
19 |
-
image_paths = dowload_and_save_image()
|
20 |
-
audio_paths = dowload_and_save_audio()
|
21 |
-
|
22 |
-
# Load data
|
23 |
-
inputs = [
|
24 |
-
{"text": a, "audio_path": b, "image_uri": c}
|
25 |
-
for a, b, c in zip(text_list, audio_paths, image_paths)
|
26 |
]
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
.
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
)
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
process_audio,
|
79 |
-
gr.Audio(type="filepath", value=audio_paths[0]),
|
80 |
-
[gr.Image(label="Output Image"), gr.Text(label="Output Text")],
|
81 |
-
examples=audio_paths,
|
82 |
-
allow_flagging="never",
|
83 |
-
)
|
84 |
-
demo = gr.TabbedInterface(
|
85 |
-
[im_to_at, txt_to_ia, a_to_it],
|
86 |
-
["Image to Text/Audio", "Text to Image/Audio", "Audio to Image/Text"],
|
87 |
-
)
|
88 |
-
|
89 |
-
if __name__ == "__main__":
|
90 |
-
demo.launch(share=True, allowed_paths=[f"{base_path}/test_inputs/"])
|
|
|
1 |
+
import requests
|
2 |
+
import os
|
3 |
+
from pathlib import Path
|
4 |
+
|
5 |
+
# URL of the raw audio file on GitHub
|
6 |
+
audio_file_urls = [
|
7 |
+
"https://github.com/raghavdixit99/assets/raw/main/bird_audio.wav",
|
8 |
+
"https://github.com/raghavdixit99/assets/raw/main/dragon-growl-37570.wav",
|
9 |
+
"https://github.com/raghavdixit99/assets/raw/main/car_audio.wav",
|
10 |
+
]
|
11 |
+
image_urls = [
|
12 |
+
"https://github.com/raghavdixit99/assets/assets/34462078/abf47cc4-d979-4aaa-83be-53a2115bf318",
|
13 |
+
"https://github.com/raghavdixit99/assets/assets/34462078/93be928e-522b-4e37-889d-d4efd54b2112",
|
14 |
+
"https://github.com/raghavdixit99/assets/assets/34462078/025deaff-632a-4829-a86c-3de6e326402f",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
]
|
16 |
|
17 |
+
base_path = os.path.dirname(os.path.abspath(__file__))
|
18 |
+
|
19 |
+
|
20 |
+
# Local path where you want to save the .wav file
|
21 |
+
def dowload_and_save_audio():
|
22 |
+
audio_pths = []
|
23 |
+
for url in audio_file_urls:
|
24 |
+
filename = url.split("/")[-1]
|
25 |
+
local_file_path = Path(f"{base_path}/test_inputs/{filename}")
|
26 |
+
local_file_path.parent.mkdir(parents=True, exist_ok=True)
|
27 |
+
# Perform the GET request
|
28 |
+
response = requests.get(url)
|
29 |
+
|
30 |
+
# Check if the request was successful
|
31 |
+
if response.status_code == 200:
|
32 |
+
# Write the content of the response to a local file
|
33 |
+
with open(local_file_path, "wb") as audio_file:
|
34 |
+
audio_file.write(response.content)
|
35 |
+
audio_pths.append(str(local_file_path))
|
36 |
+
print(
|
37 |
+
f"Audio file downloaded successfully and saved as '{local_file_path}'."
|
38 |
+
)
|
39 |
+
else:
|
40 |
+
print(f"Failed to download file. Status code: {response.status_code}")
|
41 |
+
return audio_pths
|
42 |
+
|
43 |
+
|
44 |
+
def dowload_and_save_image():
|
45 |
+
image_paths = []
|
46 |
+
for url in image_urls:
|
47 |
+
filename = url.split("/")[-1]
|
48 |
+
local_file_path = Path(f"{base_path}/test_inputs/{filename}.jpeg")
|
49 |
+
|
50 |
+
local_file_path.parent.mkdir(parents=True, exist_ok=True)
|
51 |
+
# Perform the GET request
|
52 |
+
response = requests.get(url)
|
53 |
+
|
54 |
+
# Check if the request was successful
|
55 |
+
if response.status_code == 200:
|
56 |
+
# Write the content of the response to a local file
|
57 |
+
with open(local_file_path, "wb") as image_file:
|
58 |
+
image_file.write(response.content)
|
59 |
+
image_paths.append(str(local_file_path))
|
60 |
+
print(
|
61 |
+
f"Image file downloaded successfully and saved as '{local_file_path}'."
|
62 |
+
)
|
63 |
+
else:
|
64 |
+
print(f"Failed to download file. Status code: {response.status_code}")
|
65 |
+
|
66 |
+
return image_paths
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|