Kvikontent commited on
Commit
8a769c6
·
1 Parent(s): 4f6e5f8

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import gradio as gr
3
+ import os
4
+
5
+ API_URL = "https://api-inference.huggingface.co/models/facebook/musicgen-medium"
6
+ API_KEY = os.getenv("HUGGINGFACE_API_KEY")
7
+
8
+ def query(payload, api_key):
9
+ headers = {"Authorization": "Bearer " + api_key}
10
+ response = requests.post(API_URL, headers=headers, json=payload)
11
+ return response.content
12
+
13
+ def generate_music(prompt):
14
+ audio_bytes = query({
15
+ "inputs": prompt,
16
+ })
17
+ return audio_bytes, None # Return audio bytes and no error
18
+
19
+ title = "MusicGen"
20
+ description = "Generate music based on the provided prompt using Facebook's music generation model."
21
+
22
+ iface = gr.Interface(
23
+ fn=generate_music,
24
+ inputs=gr.Textbox(lines=3, label="Enter music prompt"),
25
+ outputs=gr.Audio(type="bytes", label="Generated Music"),
26
+ title=title,
27
+ description=description
28
+ )
29
+
30
+ iface.launch()