Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,6 @@ from PIL import Image
|
|
5 |
import scipy.io.wavfile
|
6 |
|
7 |
# Load the MusicGen model
|
8 |
-
musicgen = pipeline("text-to-audio", model="facebook/musicgen-small")
|
9 |
|
10 |
# Load the StreetCLIP model
|
11 |
model = CLIPModel.from_pretrained("geolocal/StreetCLIP")
|
@@ -13,7 +12,7 @@ processor = CLIPProcessor.from_pretrained("geolocal/StreetCLIP")
|
|
13 |
|
14 |
labels = ['Albania', 'Andorra', 'Argentina', 'Australia', 'Austria', 'Bangladesh', 'Belgium', 'Bermuda', 'Bhutan', 'Bolivia', 'Botswana', 'Brazil', 'Bulgaria', 'Cambodia', 'Canada', 'Chile', 'China', 'Colombia', 'Croatia', 'Czech Republic', 'Denmark', 'Dominican Republic', 'Egypt', 'Ecuador', 'Estonia', 'Finland', 'France', 'Germany', 'Ghana', 'Greece', 'Greenland', 'Guam', 'Guatemala', 'Hungary', 'Iceland', 'India', 'Indonesia', 'Ireland', 'Israel', 'Italy', 'Japan', 'Jordan', 'Kenya', 'Kyrgyzstan', 'Laos', 'Latvia', 'Lesotho', 'Lithuania', 'Luxembourg', 'Macedonia', 'Madagascar', 'Malaysia', 'Malta', 'Mexico', 'Monaco', 'Mongolia', 'Montenegro', 'Netherlands', 'New Zealand', 'Nigeria', 'Norway', 'Pakistan', 'Palestine', 'Peru', 'Philippines', 'Poland', 'Portugal', 'Puerto Rico', 'Romania', 'Russia', 'Rwanda','Saudi Arabia', 'Senegal', 'Serbia', 'Singapore', 'Slovakia', 'Slovenia', 'South Africa', 'South Korea', 'Spain', 'Sri Lanka', 'Swaziland', 'Sweden', 'Switzerland', 'Syria','Taiwan', 'Thailand', 'Tunisia', 'Turkey', 'Uganda', 'Ukraine', 'United Arab Emirates', 'United Kingdom', 'United States', 'Uruguay']
|
15 |
|
16 |
-
def process_image(image
|
17 |
# Ensure the image is in the correct format
|
18 |
if isinstance(image, str):
|
19 |
image = Image.open(image)
|
@@ -33,18 +32,15 @@ def process_image(image, audio_path="musicgen_out.wav"):
|
|
33 |
country = labels[country_index]
|
34 |
print(country)
|
35 |
# Generate music based on the country
|
36 |
-
music_description = f"Traditional music from {country}"
|
37 |
-
music = musicgen(music_description, forward_params={"do_sample": True})
|
38 |
|
39 |
# Save the generated music to the specified path
|
40 |
-
scipy.io.wavfile.write(audio_path, rate=music["sampling_rate"], data=music["audio"])
|
41 |
|
42 |
# Return the country and the path to the generated music
|
43 |
-
return country
|
44 |
|
45 |
# Define the Gradio interface
|
46 |
inputs = gr.Image(type="pil", label="Upload a photo (تحميل صورة)")
|
47 |
-
outputs = [gr.Textbox(label="Country (البلد)")
|
48 |
|
49 |
iface = gr.Interface(
|
50 |
fn=process_image,
|
|
|
5 |
import scipy.io.wavfile
|
6 |
|
7 |
# Load the MusicGen model
|
|
|
8 |
|
9 |
# Load the StreetCLIP model
|
10 |
model = CLIPModel.from_pretrained("geolocal/StreetCLIP")
|
|
|
12 |
|
13 |
labels = ['Albania', 'Andorra', 'Argentina', 'Australia', 'Austria', 'Bangladesh', 'Belgium', 'Bermuda', 'Bhutan', 'Bolivia', 'Botswana', 'Brazil', 'Bulgaria', 'Cambodia', 'Canada', 'Chile', 'China', 'Colombia', 'Croatia', 'Czech Republic', 'Denmark', 'Dominican Republic', 'Egypt', 'Ecuador', 'Estonia', 'Finland', 'France', 'Germany', 'Ghana', 'Greece', 'Greenland', 'Guam', 'Guatemala', 'Hungary', 'Iceland', 'India', 'Indonesia', 'Ireland', 'Israel', 'Italy', 'Japan', 'Jordan', 'Kenya', 'Kyrgyzstan', 'Laos', 'Latvia', 'Lesotho', 'Lithuania', 'Luxembourg', 'Macedonia', 'Madagascar', 'Malaysia', 'Malta', 'Mexico', 'Monaco', 'Mongolia', 'Montenegro', 'Netherlands', 'New Zealand', 'Nigeria', 'Norway', 'Pakistan', 'Palestine', 'Peru', 'Philippines', 'Poland', 'Portugal', 'Puerto Rico', 'Romania', 'Russia', 'Rwanda','Saudi Arabia', 'Senegal', 'Serbia', 'Singapore', 'Slovakia', 'Slovenia', 'South Africa', 'South Korea', 'Spain', 'Sri Lanka', 'Swaziland', 'Sweden', 'Switzerland', 'Syria','Taiwan', 'Thailand', 'Tunisia', 'Turkey', 'Uganda', 'Ukraine', 'United Arab Emirates', 'United Kingdom', 'United States', 'Uruguay']
|
14 |
|
15 |
+
def process_image(image):
|
16 |
# Ensure the image is in the correct format
|
17 |
if isinstance(image, str):
|
18 |
image = Image.open(image)
|
|
|
32 |
country = labels[country_index]
|
33 |
print(country)
|
34 |
# Generate music based on the country
|
|
|
|
|
35 |
|
36 |
# Save the generated music to the specified path
|
|
|
37 |
|
38 |
# Return the country and the path to the generated music
|
39 |
+
return country
|
40 |
|
41 |
# Define the Gradio interface
|
42 |
inputs = gr.Image(type="pil", label="Upload a photo (تحميل صورة)")
|
43 |
+
outputs = [gr.Textbox(label="Country (البلد)")]
|
44 |
|
45 |
iface = gr.Interface(
|
46 |
fn=process_image,
|