Download app.py from seberthe/BaraMusik: direct link, hf CLI and curl.
- Browser
- Download file 1.54 kB
-
https://huggingface.co/spaces/seberthe/BaraMusik/resolve/main/app.py
- Command line
-
hf download hf://spaces/seberthe/BaraMusik/app.py
-
curl -L -o app.py https://huggingface.co/spaces/seberthe/BaraMusik/resolve/main/app.py
1.54 kB
| import os | |
| import requests | |
| import gradio as gr | |
| from utils import ask_llm, translate_to_english, translate_to_bambara | |
| API_URL = "https://api-inference.huggingface.co/models/facebook/musicgen-small" | |
| headers = {"Authorization": f"Bearer {os.getenv('HF_API_KEY')}"} | |
| def query(style, instrus, chanson): | |
| payload = { 'inputs': f"{style} music style with instruments {instrus} for a song about {translate_to_english(chanson)}" } | |
| response = requests.post(API_URL, headers=headers, json=payload) | |
| couplet = ask_llm(f"Ecris un couplet court pouvant être chanté en 30 seconds pour une chanson à propos de : '{chanson}'") | |
| track = response.content | |
| return track, translate_to_bambara(couplet) | |
| demo = gr.Interface( | |
| title="BaraMusiki", | |
| description="Explorez l'infini des possibilités musicales avec BaraMusiki.", | |
| article="Créez des mélodies uniques en choisissant le style, les instruments, et la description de votre chanson.", | |
| fn=query, | |
| inputs=[ | |
| gr.Radio(["Afrobeat", "Afro trap", "Mande", "Tuareg", "Wassoulou", "Hiphop", "Rap"], label="Styles", info="Choisissez le style"), | |
| gr.CheckboxGroup(["Balafon", "Kora", "Ngoni", "Djembe", "Drum", "Piano", "Flute", "Saxophone"], label="Instrus", info="Choisissez les instrus"), | |
| gr.Text(label="Decription Chanson", interactive=True) | |
| ], | |
| outputs=[ | |
| gr.Audio(label="Track", type="numpy"), | |
| gr.Text(label="Couplet", interactive=False), | |
| ], | |
| allow_flagging='never' | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |