Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,30 +8,23 @@ import tempfile
|
|
| 8 |
import time
|
| 9 |
from rhythma import RhythmaModulationEngine, RhythmaSymphAICore
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
# Initialize the SymphAI Core
|
| 12 |
-
symphai_core = RhythmaSymphAICore()
|
| 13 |
|
| 14 |
def analyze_input(input_text=None, audio_input=None):
|
| 15 |
"""Analyze user input for emotional state and rhythm patterns"""
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
transcription = "Audio transcription would go here"
|
| 19 |
-
input_text = transcription
|
| 20 |
-
|
| 21 |
-
if not input_text or not input_text.strip():
|
| 22 |
-
return {
|
| 23 |
-
"error": "Please enter a description of your emotional state or provide an audio input."
|
| 24 |
-
}
|
| 25 |
-
|
| 26 |
-
# Analyze the input using SymphAI Core
|
| 27 |
-
analysis = symphai_core.analyze_input(input_text)
|
| 28 |
-
|
| 29 |
-
return {
|
| 30 |
-
"input_text": input_text,
|
| 31 |
-
"emotional_state": analysis["emotional_state"],
|
| 32 |
-
"rhythm_pattern": analysis["rhythm_pattern"],
|
| 33 |
-
"transcription": input_text if audio_input else None
|
| 34 |
-
}
|
| 35 |
|
| 36 |
def generate_modulated_experience(analysis_result, base_freq=None, modulation_type="sine", rhythm_pattern=None, duration=5):
|
| 37 |
"""Generate a complete modulated experience based on analysis and parameters"""
|
|
@@ -93,7 +86,9 @@ def rhythma_experience(
|
|
| 93 |
)
|
| 94 |
|
| 95 |
# Return all outputs
|
| 96 |
-
|
|
|
|
|
|
|
| 97 |
|
| 98 |
# Create the Gradio interface
|
| 99 |
def create_interface():
|
|
@@ -101,6 +96,9 @@ def create_interface():
|
|
| 101 |
gr.Markdown("# Rhythma: The Living Modulation Engine")
|
| 102 |
gr.Markdown("### Dynamic rhythm-based sound modulation for wellbeing")
|
| 103 |
|
|
|
|
|
|
|
|
|
|
| 104 |
with gr.Row():
|
| 105 |
with gr.Column(scale=1):
|
| 106 |
# Input section
|
|
@@ -110,12 +108,12 @@ def create_interface():
|
|
| 110 |
)
|
| 111 |
audio_input = gr.Audio(
|
| 112 |
type="filepath",
|
| 113 |
-
label="Or speak about your feelings"
|
| 114 |
)
|
| 115 |
|
| 116 |
with gr.Accordion("Advanced Settings", open=False):
|
| 117 |
override_freq = gr.Slider(
|
| 118 |
-
minimum=
|
| 119 |
label="Override Frequency (Hz, leave at 0 for automatic)"
|
| 120 |
)
|
| 121 |
override_modulation = gr.Dropdown(
|
|
@@ -144,6 +142,7 @@ def create_interface():
|
|
| 144 |
waveform_simple = gr.Image(label="Basic Waveform")
|
| 145 |
waveform_plot = gr.Plot(label="Detailed Waveform Analysis")
|
| 146 |
symbolic_output = gr.Textbox(label="Symbolic Interpretation")
|
|
|
|
| 147 |
|
| 148 |
# Button action
|
| 149 |
generate_button.click(
|
|
@@ -155,7 +154,8 @@ def create_interface():
|
|
| 155 |
],
|
| 156 |
outputs=[
|
| 157 |
analysis_output, audio_output,
|
| 158 |
-
waveform_plot, waveform_simple, symbolic_output
|
|
|
|
| 159 |
]
|
| 160 |
)
|
| 161 |
|
|
@@ -187,6 +187,10 @@ def create_interface():
|
|
| 187 |
Rhythma uses principles of Floquet modulation and rhythm analysis to generate audio that
|
| 188 |
resonates with your current state or intention.
|
| 189 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
© 2025 Rhythma Technologies
|
| 191 |
""")
|
| 192 |
|
|
|
|
| 8 |
import time
|
| 9 |
from rhythma import RhythmaModulationEngine, RhythmaSymphAICore
|
| 10 |
|
| 11 |
+
# Check if Groq API key is available
|
| 12 |
+
has_groq_key = os.environ.get("GROQ_API_KEY") is not None
|
| 13 |
+
use_groq = has_groq_key
|
| 14 |
+
|
| 15 |
+
# If Groq API key is not set, show a message
|
| 16 |
+
if not has_groq_key:
|
| 17 |
+
print("⚠️ GROQ_API_KEY not found in environment variables.")
|
| 18 |
+
print("To enable Groq LLM and audio transcription features, set the GROQ_API_KEY environment variable.")
|
| 19 |
+
print("Running with limited functionality.")
|
| 20 |
+
|
| 21 |
# Initialize the SymphAI Core
|
| 22 |
+
symphai_core = RhythmaSymphAICore(use_groq=use_groq)
|
| 23 |
|
| 24 |
def analyze_input(input_text=None, audio_input=None):
|
| 25 |
"""Analyze user input for emotional state and rhythm patterns"""
|
| 26 |
+
# Pass to SymphAI Core for analysis
|
| 27 |
+
return symphai_core.analyze_input(input_text, audio_input)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
def generate_modulated_experience(analysis_result, base_freq=None, modulation_type="sine", rhythm_pattern=None, duration=5):
|
| 30 |
"""Generate a complete modulated experience based on analysis and parameters"""
|
|
|
|
| 86 |
)
|
| 87 |
|
| 88 |
# Return all outputs
|
| 89 |
+
transcription = analysis.get("transcription", "") if isinstance(analysis, dict) else ""
|
| 90 |
+
|
| 91 |
+
return analysis_text, audio_file, fig, waveform_image, symbolic, transcription
|
| 92 |
|
| 93 |
# Create the Gradio interface
|
| 94 |
def create_interface():
|
|
|
|
| 96 |
gr.Markdown("# Rhythma: The Living Modulation Engine")
|
| 97 |
gr.Markdown("### Dynamic rhythm-based sound modulation for wellbeing")
|
| 98 |
|
| 99 |
+
if not use_groq:
|
| 100 |
+
gr.Markdown("⚠️ **Running with limited functionality:** GROQ_API_KEY not found. Advanced emotion detection and audio transcription disabled.")
|
| 101 |
+
|
| 102 |
with gr.Row():
|
| 103 |
with gr.Column(scale=1):
|
| 104 |
# Input section
|
|
|
|
| 108 |
)
|
| 109 |
audio_input = gr.Audio(
|
| 110 |
type="filepath",
|
| 111 |
+
label="Or speak about your feelings" if use_groq else "Audio input (requires Groq API for transcription)"
|
| 112 |
)
|
| 113 |
|
| 114 |
with gr.Accordion("Advanced Settings", open=False):
|
| 115 |
override_freq = gr.Slider(
|
| 116 |
+
minimum=0, maximum=1000, value=0,
|
| 117 |
label="Override Frequency (Hz, leave at 0 for automatic)"
|
| 118 |
)
|
| 119 |
override_modulation = gr.Dropdown(
|
|
|
|
| 142 |
waveform_simple = gr.Image(label="Basic Waveform")
|
| 143 |
waveform_plot = gr.Plot(label="Detailed Waveform Analysis")
|
| 144 |
symbolic_output = gr.Textbox(label="Symbolic Interpretation")
|
| 145 |
+
transcription_output = gr.Textbox(label="Transcribed Audio (if provided)", visible=use_groq)
|
| 146 |
|
| 147 |
# Button action
|
| 148 |
generate_button.click(
|
|
|
|
| 154 |
],
|
| 155 |
outputs=[
|
| 156 |
analysis_output, audio_output,
|
| 157 |
+
waveform_plot, waveform_simple, symbolic_output,
|
| 158 |
+
transcription_output
|
| 159 |
]
|
| 160 |
)
|
| 161 |
|
|
|
|
| 187 |
Rhythma uses principles of Floquet modulation and rhythm analysis to generate audio that
|
| 188 |
resonates with your current state or intention.
|
| 189 |
|
| 190 |
+
### Advanced Features (require Groq API):
|
| 191 |
+
- Enhanced emotion detection with large language models
|
| 192 |
+
- Audio transcription for voice input
|
| 193 |
+
|
| 194 |
© 2025 Rhythma Technologies
|
| 195 |
""")
|
| 196 |
|