HarshRathi09 commited on
Commit
6a389ee
β€’
1 Parent(s): bc3c070

Delete Music_Generator.py

Browse files
Files changed (1) hide show
  1. Music_Generator.py +0 -108
Music_Generator.py DELETED
@@ -1,108 +0,0 @@
1
- import streamlit as st
2
- from musicgen import init_musicgen, generate_music
3
- import numpy as np
4
- from scipy.io.wavfile import write
5
-
6
- # Custom CSS to improve the appearance
7
- st.markdown("""
8
- <style>
9
- .stApp {
10
- background-image:linear-gradient(to bottom, #000000 ,#000814 ,#10002b, #240046);
11
- }
12
- .main-title {
13
- font-size: 3rem !important;
14
- color: #f1faee;
15
- text-align: center;
16
- padding: 1rem 0;
17
- }
18
- .subtitle {
19
- font-size: 1.2rem;
20
- color: #f1faee;
21
- text-align: center;
22
- margin-bottom: 2rem;
23
- }
24
- .stTextInput > div > div > input {
25
- font-size: 1.2rem;
26
- }
27
- .generate-button {
28
- font-size: 1.2rem;
29
- border-radius: 10px;
30
- padding: 0.5rem 1rem;
31
- }
32
- .info-section {
33
- background-color: #ffffff;
34
- padding: 1rem;
35
- border-radius: 10px;
36
- margin-top: 2rem;
37
- }
38
- </style>
39
- """, unsafe_allow_html=True)
40
-
41
- # Initialize the MusicGen model and tokenizer
42
- @st.cache_resource
43
- def load_model():
44
- return init_musicgen('facebook/musicgen-small')
45
-
46
- tokenizer, model = load_model()
47
-
48
- # Streamlit interface
49
- st.markdown("<h1 class='main-title'>🎡 AI Music Generator</h1>", unsafe_allow_html=True)
50
- st.markdown("<p class='subtitle'>Describe the type of music you want, and the AI will generate it for you.</p>", unsafe_allow_html=True)
51
-
52
- # Main interaction area
53
- text_input = st.text_input("πŸ–ŠοΈ Describe the music you want to create",
54
- placeholder="E.g., A happy pop song with guitar and drums")
55
-
56
- if st.button("🎼 Generate Music"):
57
- if text_input.strip():
58
- with st.spinner("🎧 Generating your music..."):
59
- try:
60
- audio_array = generate_music(text_input, tokenizer, model)
61
-
62
- # Convert to int16 and save as WAV file
63
- audio_int16 = (audio_array * 32767).astype(np.int16)
64
- write("generated_music.wav", 44100, audio_int16)
65
-
66
- st.success("πŸŽ‰ Your music has been generated successfully!")
67
-
68
- # Play the generated audio
69
- st.audio("generated_music.wav")
70
-
71
- # Provide download button
72
- with open("generated_music.wav", "rb") as file:
73
- st.download_button(
74
- label="πŸ“₯ Download Music",
75
- data=file,
76
- file_name="ai_generated_music.wav",
77
- mime="audio/wav"
78
- )
79
- except Exception as e:
80
- st.error(f"πŸ˜• Oops! An error occurred: {str(e)}")
81
- else:
82
- st.warning("πŸ€” Please enter a description for your music.")
83
-
84
- # Information sections
85
- st.markdown("---")
86
-
87
- col1, col2 = st.columns(2)
88
-
89
- with col1:
90
- st.markdown("### 🌟 How it works")
91
- st.markdown("""
92
- 1. πŸ“ Describe the music you want
93
- 2. πŸ–±οΈ Click 'Generate Music'
94
- 3. 🎧 Listen to your AI-created tune
95
- 4. πŸ“₯ Download and share!
96
- """)
97
-
98
- with col2:
99
- st.markdown("### 🎨 Tips for great results")
100
- st.markdown("""
101
- - Be specific about instruments
102
- - Mention genre or mood
103
- - Describe tempo or rhythm
104
- - Reference famous artists or songs
105
- """)
106
-
107
- # Footer
108
- st.markdown("---")