Larynxlab / lyrics_module.py
Lambeckkk's picture
Create lyrics_module.py
cd5e097 verified
raw
history blame contribute delete
872 Bytes
from transformers import pipeline
import gradio as gr
# Load Mistral instruct model (quantized preferred for CPU use)
generator = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.2")
def generate_lyrics(prompt):
system_prompt = (
f"You are a songwriter. Write creative lyrics for a song based on this prompt:\n"
f"\"{prompt}\"\n\n"
f"Include structure: Verse 1, Chorus, Verse 2, etc.\n"
)
result = generator(system_prompt, max_new_tokens=256, do_sample=True, temperature=0.8)[0]["generated_text"]
return result.strip()
gr.Interface(
fn=generate_lyrics,
inputs=gr.Textbox(label="Describe your song idea (mood, genre, theme)"),
outputs=gr.Textbox(label="Generated Lyrics"),
title="LarynxLab - Text-to-Lyrics",
description="Generate song lyrics from a prompt using open-source AI."
).launch()