Spaces:
Running
Running
Create lyrics_module.py
Browse files- lyrics_module.py +22 -0
lyrics_module.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
# Load Mistral instruct model (quantized preferred for CPU use)
|
5 |
+
generator = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.2")
|
6 |
+
|
7 |
+
def generate_lyrics(prompt):
|
8 |
+
system_prompt = (
|
9 |
+
f"You are a songwriter. Write creative lyrics for a song based on this prompt:\n"
|
10 |
+
f"\"{prompt}\"\n\n"
|
11 |
+
f"Include structure: Verse 1, Chorus, Verse 2, etc.\n"
|
12 |
+
)
|
13 |
+
result = generator(system_prompt, max_new_tokens=256, do_sample=True, temperature=0.8)[0]["generated_text"]
|
14 |
+
return result.strip()
|
15 |
+
|
16 |
+
gr.Interface(
|
17 |
+
fn=generate_lyrics,
|
18 |
+
inputs=gr.Textbox(label="Describe your song idea (mood, genre, theme)"),
|
19 |
+
outputs=gr.Textbox(label="Generated Lyrics"),
|
20 |
+
title="LarynxLab - Text-to-Lyrics",
|
21 |
+
description="Generate song lyrics from a prompt using open-source AI."
|
22 |
+
).launch()
|