PRANJAL KAR
commited on
Commit
·
c893884
1
Parent(s):
611a504
FEAT: Added Tracing for user selections
Browse files- app.py +11 -2
- requirements.txt +2 -0
- utils.py +4 -0
app.py
CHANGED
|
@@ -16,6 +16,7 @@ from utils import (
|
|
| 16 |
)
|
| 17 |
|
| 18 |
from dotenv import load_dotenv
|
|
|
|
| 19 |
|
| 20 |
load_dotenv()
|
| 21 |
|
|
@@ -153,6 +154,7 @@ def generate_section_variants_handler(
|
|
| 153 |
return f"Error generating variants: {str(e)}", None, None, None, None, None, None
|
| 154 |
|
| 155 |
|
|
|
|
| 156 |
def select_variant(section_type, variant_num, append):
|
| 157 |
"""Select a variant for a specific section, with an option to append."""
|
| 158 |
global ALL_VARIANTS, SELECTED_VARIANTS
|
|
@@ -166,17 +168,23 @@ def select_variant(section_type, variant_num, append):
|
|
| 166 |
return f"Variant {variant_num} not found for {section_type}", "None"
|
| 167 |
|
| 168 |
# Store the selection
|
| 169 |
-
|
|
|
|
| 170 |
|
| 171 |
# Create a display string for the selected variant
|
| 172 |
-
variant_info = ALL_VARIANTS[section_type][variant_key]
|
| 173 |
display_text = f"Selected: Variant {variant_num}"
|
| 174 |
if "description" in variant_info:
|
| 175 |
display_text += f" - {variant_info['description']}"
|
| 176 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
return f"Selected variant {variant_num} for {section_type}", display_text
|
| 178 |
|
| 179 |
except Exception as e:
|
|
|
|
| 180 |
return f"Error selecting variant: {str(e)}", "None"
|
| 181 |
|
| 182 |
|
|
@@ -447,6 +455,7 @@ with gr.Blocks(title="Interactive Music Track Generator") as demo:
|
|
| 447 |
|
| 448 |
edm_arrangement_tab()
|
| 449 |
|
|
|
|
| 450 |
with gr.Tab("2. Generate Section Variants"):
|
| 451 |
gr.Markdown("### Generate and Select Variants for Each Section")
|
| 452 |
gr.Markdown("Generate variants for each section and select which one to use in the final track")
|
|
|
|
| 16 |
)
|
| 17 |
|
| 18 |
from dotenv import load_dotenv
|
| 19 |
+
from langsmith import traceable
|
| 20 |
|
| 21 |
load_dotenv()
|
| 22 |
|
|
|
|
| 154 |
return f"Error generating variants: {str(e)}", None, None, None, None, None, None
|
| 155 |
|
| 156 |
|
| 157 |
+
@traceable(run_type="chain", name="groq_call")
|
| 158 |
def select_variant(section_type, variant_num, append):
|
| 159 |
"""Select a variant for a specific section, with an option to append."""
|
| 160 |
global ALL_VARIANTS, SELECTED_VARIANTS
|
|
|
|
| 168 |
return f"Variant {variant_num} not found for {section_type}", "None"
|
| 169 |
|
| 170 |
# Store the selection
|
| 171 |
+
variant_info = ALL_VARIANTS[section_type][variant_key]
|
| 172 |
+
SELECTED_VARIANTS[section_type] = variant_info["config"]
|
| 173 |
|
| 174 |
# Create a display string for the selected variant
|
|
|
|
| 175 |
display_text = f"Selected: Variant {variant_num}"
|
| 176 |
if "description" in variant_info:
|
| 177 |
display_text += f" - {variant_info['description']}"
|
| 178 |
|
| 179 |
+
# Log selection details for tracing
|
| 180 |
+
logger.info(f"Selected variant for {section_type}: {variant_key}")
|
| 181 |
+
logger.info(f"Variant description: {variant_info.get('description', 'No description')}")
|
| 182 |
+
logger.info(f"Stems used: {variant_info.get('config', {}).get('stems', [])}")
|
| 183 |
+
|
| 184 |
return f"Selected variant {variant_num} for {section_type}", display_text
|
| 185 |
|
| 186 |
except Exception as e:
|
| 187 |
+
logger.error(f"Error selecting variant: {str(e)}")
|
| 188 |
return f"Error selecting variant: {str(e)}", "None"
|
| 189 |
|
| 190 |
|
|
|
|
| 455 |
|
| 456 |
edm_arrangement_tab()
|
| 457 |
|
| 458 |
+
|
| 459 |
with gr.Tab("2. Generate Section Variants"):
|
| 460 |
gr.Markdown("### Generate and Select Variants for Each Section")
|
| 461 |
gr.Markdown("Generate variants for each section and select which one to use in the final track")
|
requirements.txt
CHANGED
|
@@ -8,3 +8,5 @@ python-dotenv
|
|
| 8 |
plotly-express
|
| 9 |
pandas
|
| 10 |
pydub
|
|
|
|
|
|
|
|
|
| 8 |
plotly-express
|
| 9 |
pandas
|
| 10 |
pydub
|
| 11 |
+
langsmith
|
| 12 |
+
langchain
|
utils.py
CHANGED
|
@@ -8,6 +8,8 @@ from pydub.effects import low_pass_filter, high_pass_filter
|
|
| 8 |
from tqdm import tqdm
|
| 9 |
from groq import Groq
|
| 10 |
import logging
|
|
|
|
|
|
|
| 11 |
|
| 12 |
from dotenv import load_dotenv
|
| 13 |
import random
|
|
@@ -20,6 +22,8 @@ logger.setLevel(logging.INFO)
|
|
| 20 |
logger.addHandler(logging.StreamHandler())
|
| 21 |
logger.addHandler(logging.FileHandler("log.txt"))
|
| 22 |
|
|
|
|
|
|
|
| 23 |
def make_groq_call(stems, song_name, p, section_type=None, bpm=120, bars=16):
|
| 24 |
"""
|
| 25 |
Make a call to the Groq API to get music production instructions.
|
|
|
|
| 8 |
from tqdm import tqdm
|
| 9 |
from groq import Groq
|
| 10 |
import logging
|
| 11 |
+
from langsmith import traceable
|
| 12 |
+
from langchain.callbacks import LangChainTracer
|
| 13 |
|
| 14 |
from dotenv import load_dotenv
|
| 15 |
import random
|
|
|
|
| 22 |
logger.addHandler(logging.StreamHandler())
|
| 23 |
logger.addHandler(logging.FileHandler("log.txt"))
|
| 24 |
|
| 25 |
+
|
| 26 |
+
@traceable(run_type="llm", name="groq_call")
|
| 27 |
def make_groq_call(stems, song_name, p, section_type=None, bpm=120, bars=16):
|
| 28 |
"""
|
| 29 |
Make a call to the Groq API to get music production instructions.
|