baouws commited on
Commit
a822e58
Β·
verified Β·
1 Parent(s): 07c157f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +226 -0
app.py ADDED
@@ -0,0 +1,226 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Matrix Music Hacker - Hugging Face Spaces Deployment Guide
2
+
3
+ ## Step 1: Create Required Files
4
+
5
+ You'll need to create these files in your repository:
6
+
7
+ ### 1. `app.py` (Main application file)
8
+ ```python
9
+ import gradio as gr
10
+ import os
11
+
12
+ # Read the HTML content
13
+ def load_html():
14
+ with open("index.html", "r", encoding="utf-8") as f:
15
+ return f.read()
16
+
17
+ # Create the Gradio interface
18
+ def create_interface():
19
+ html_content = load_html()
20
+
21
+ with gr.Blocks(
22
+ title="Matrix Music Hacker",
23
+ theme=gr.themes.Base(
24
+ primary_hue="green",
25
+ secondary_hue="cyan",
26
+ neutral_hue="slate"
27
+ ).set(
28
+ body_background_fill="#000000",
29
+ block_background_fill="#001100",
30
+ border_color_primary="#00ff00"
31
+ )
32
+ ) as interface:
33
+
34
+ gr.HTML(html_content)
35
+
36
+ return interface
37
+
38
+ if __name__ == "__main__":
39
+ interface = create_interface()
40
+ interface.launch(
41
+ server_name="0.0.0.0",
42
+ server_port=7860,
43
+ share=False
44
+ )
45
+ ```
46
+
47
+ ### 2. `requirements.txt`
48
+ ```
49
+ gradio>=4.0.0
50
+ ```
51
+
52
+ ### 3. `README.md`
53
+ ```markdown
54
+ ---
55
+ title: Matrix Music Hacker
56
+ emoji: 🎡
57
+ colorFrom: green
58
+ colorTo: cyan
59
+ sdk: gradio
60
+ sdk_version: 4.44.0
61
+ app_file: app.py
62
+ pinned: false
63
+ license: mit
64
+ ---
65
+
66
+ # Matrix Music Hacker v2.1
67
+
68
+ A cyberpunk-themed voice-controlled music synthesizer using Strudel.cc for beat generation and audio synthesis.
69
+
70
+ ## Features
71
+
72
+ - 🎀 **Voice Recognition**: Speak commands to generate music
73
+ - πŸ’» **Code Matrix**: Edit Strudel code directly
74
+ - 🌊 **Real-time Visualization**: Matrix-style audio visualizations
75
+ - 🎡 **Multiple Genres**: Deep house, cyberpunk, ambient, breakbeat, and more
76
+ - πŸ”Š **Live Audio Synthesis**: Powered by Strudel.cc
77
+
78
+ ## Voice Commands
79
+
80
+ Try saying:
81
+ - "play deep house drums"
82
+ - "create underground bass"
83
+ - "make cyberpunk synth wave"
84
+ - "play matrix ambient sounds"
85
+ - "start rave breakbeat"
86
+
87
+ ## Keyboard Shortcuts
88
+
89
+ - `Ctrl + Enter`: Execute code
90
+ - `Escape`: Stop playback
91
+ - `Ctrl + R`: Start voice recognition
92
+
93
+ ## Technology Stack
94
+
95
+ - **Frontend**: HTML5, CSS3, JavaScript
96
+ - **Audio Engine**: Strudel.cc
97
+ - **Speech Recognition**: Web Speech API
98
+ - **Visualization**: Canvas 2D API
99
+ - **Deployment**: Hugging Face Spaces + Gradio
100
+
101
+ ## Usage
102
+
103
+ 1. Click "INITIATE VOICE HACK" to start voice recognition
104
+ 2. Speak a music command (see examples above)
105
+ 3. Watch as your voice is converted to Strudel code
106
+ 4. The system will automatically execute the generated music
107
+ 5. Enjoy the matrix-style visualizations!
108
+
109
+ ## Note
110
+
111
+ This application requires:
112
+ - A modern web browser with Web Speech API support
113
+ - Microphone permissions for voice input
114
+ - Audio permissions for sound output
115
+
116
+ Built with ❀️ for the cyberpunk music community.
117
+ ```
118
+
119
+ ### 4. `.gitattributes` (Optional)
120
+ ```
121
+ *.html linguist-language=HTML
122
+ *.js linguist-language=JavaScript
123
+ *.css linguist-language=CSS
124
+ *.py linguist-language=Python
125
+ ```
126
+
127
+ ## Step 2: Rename Your HTML File
128
+
129
+ Rename your `paste.txt` file to `index.html` since that's what the Python code expects.
130
+
131
+ ## Step 3: Deploy to Hugging Face Spaces
132
+
133
+ ### Option A: Using Hugging Face Hub (Recommended)
134
+
135
+ 1. **Install the Hugging Face Hub**:
136
+ ```bash
137
+ pip install huggingface_hub
138
+ ```
139
+
140
+ 2. **Login to Hugging Face**:
141
+ ```bash
142
+ huggingface-cli login
143
+ ```
144
+
145
+ 3. **Create the Space**:
146
+ ```bash
147
+ # Create a new directory for your space
148
+ mkdir matrix-music-hacker
149
+ cd matrix-music-hacker
150
+
151
+ # Copy all your files here
152
+ cp /path/to/your/paste.txt ./index.html
153
+ # Create the other files (app.py, requirements.txt, README.md)
154
+
155
+ # Initialize git repo
156
+ git init
157
+ git add .
158
+ git commit -m "Initial commit: Matrix Music Hacker v2.1"
159
+
160
+ # Push to Hugging Face Spaces
161
+ git remote add origin https://huggingface.co/spaces/YOUR_USERNAME/matrix-music-hacker
162
+ git push -u origin main
163
+ ```
164
+
165
+ ### Option B: Using the Web Interface
166
+
167
+ 1. Go to [Hugging Face Spaces](https://huggingface.co/spaces)
168
+ 2. Click "Create new Space"
169
+ 3. Choose:
170
+ - **Name**: `matrix-music-hacker`
171
+ - **SDK**: `Gradio`
172
+ - **Hardware**: `CPU basic` (free tier)
173
+ - **Visibility**: `Public`
174
+ 4. Upload all your files through the web interface
175
+
176
+ ## Step 4: Configuration Notes
177
+
178
+ ### Important Considerations:
179
+
180
+ 1. **Audio Context**: The Web Audio API might have some limitations in the Gradio iframe environment. You may need to add user interaction requirements.
181
+
182
+ 2. **Speech Recognition**: The Web Speech API requires HTTPS, which Hugging Face Spaces provides.
183
+
184
+ 3. **External Dependencies**: The Strudel.js library is loaded from CDN, which should work fine.
185
+
186
+ 4. **File Structure**:
187
+ ```
188
+ your-space/
189
+ β”œβ”€β”€ app.py
190
+ β”œβ”€β”€ requirements.txt
191
+ β”œβ”€β”€ README.md
192
+ β”œβ”€β”€ index.html
193
+ └── .gitattributes (optional)
194
+ ```
195
+
196
+ ## Step 5: Testing and Troubleshooting
197
+
198
+ After deployment:
199
+
200
+ 1. **Check the logs** in the Hugging Face Spaces interface
201
+ 2. **Test voice recognition** - ensure microphone permissions work
202
+ 3. **Verify audio output** - check if sounds play correctly
203
+ 4. **Test all buttons** and interactive elements
204
+
205
+ ### Common Issues:
206
+
207
+ - **Audio not playing**: May need user interaction before audio context starts
208
+ - **Voice recognition not working**: Check browser compatibility and HTTPS
209
+ - **Visualization not showing**: Canvas might need resizing in iframe
210
+
211
+ ## Step 6: Optimization (Optional)
212
+
213
+ For better performance, consider:
214
+
215
+ 1. **Minify the HTML/CSS/JS**
216
+ 2. **Add error handling** for audio context initialization
217
+ 3. **Add loading states** for better UX
218
+ 4. **Implement fallbacks** for unsupported browsers
219
+
220
+ ## Final Notes
221
+
222
+ - The application will be available at `https://huggingface.co/spaces/YOUR_USERNAME/matrix-music-hacker`
223
+ - Hugging Face Spaces provides free hosting for public repositories
224
+ - The space will automatically rebuild when you push changes to the repository
225
+
226
+ Your Matrix Music Hacker is ready to hack the cybernetic soundscape! 🎡πŸ”₯